为什么变量的新值不影响 void update in unity?
Why isn't the new values for the variable not taking affect in void update in unity?
我试图让一个物体在撞到另一个物体时改变方向,但由于某种原因,当它撞到一个物体时,原来的物体静止不动。
using UnityEngine;
using System.Collections;
public class playerController : MonoBehaviour {
public float c =0;
public float a =0;
public float d =1;
private Rigidbody rb;
void Start ()
{
rb = GetComponent<Rigidbody>();
}
void OnTriggerEnter(Collider other) {
a = 0;
c = -1;
d = 0;
}
void fixedUpdate ()
{
transform.Translate (c*1f, a*1f, d*1f);
}
}
只需尝试 "FixedUpdate" 而不是 "fixedUpdate"。
我试图让一个物体在撞到另一个物体时改变方向,但由于某种原因,当它撞到一个物体时,原来的物体静止不动。
using UnityEngine;
using System.Collections;
public class playerController : MonoBehaviour {
public float c =0;
public float a =0;
public float d =1;
private Rigidbody rb;
void Start ()
{
rb = GetComponent<Rigidbody>();
}
void OnTriggerEnter(Collider other) {
a = 0;
c = -1;
d = 0;
}
void fixedUpdate ()
{
transform.Translate (c*1f, a*1f, d*1f);
}
}
只需尝试 "FixedUpdate" 而不是 "fixedUpdate"。