using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BoxCollider : MonoBehaviour {
private float degrees = 180f;
public float rotateSpeed = 10f;
private GameObject character;
private bool entered = false;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (entered == true)
{
character.transform.rotation = Quaternion.Slerp(character.transform.rotation, Quaternion.Euler(degrees, 0, degrees), rotateSpeed * Time.deltaTime);
}
}
void OnTriggerEnter(Collider c)
{
character = c.gameObject;
entered = true;
}
}
角色第一次碰撞牆(空對象與箱對撞機)時,它會將輸入更改爲true並旋轉角色。如何在字符碰撞盒子時以邏輯方式使用bool變量?
但與後旋轉其他牆碰撞,達到了其他牆壁我用斷點而且越來越向部分:
void OnTriggerEnter(Collider c)
{
character = c.gameObject;
entered = true;
}
但是當它得到的更新功能:
if (entered == true)
我在這條線上使用了一個斷點並輸入了錯誤。 不知道爲什麼。
第一次碰撞牆是真的,但第二次碰撞牆是錯誤的。
我使用這個布爾的原因是隻有當碰撞牆(盒)時才旋轉角色。
我在地形周圍有4個空的gameobjects,每個人都有一個box collider istrigger設置爲on,並且這個腳本也附加到每個gameobject上。
我不明白爲什麼第一次輸入是真的第二次是錯誤的。
確定您正在查看/調試正確的實體? (如果沒有誤導,多次使用的對象中的斷點會引起混淆。) – RuDevel