Hi everyone,
I’m doing the Challenge: Moving sound and in the example game, there’s an object that starts moving when the player gets close to it.
So my question is: How do I check when the player is close enough to trigger the action that I want?
public class RiseAndRun : MonoBehaviour
{
public Vector3 positionChange;
public Vector3 positionChangeHorizontal;
readonly double distance = 0.5;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//if (condition)
//{
if (this.transform.position.y < 1.5)
{
transform.position += (positionChange * Time.deltaTime);
}
if (this.transform.position.y >= 1.5)
{
transform.position += (positionChangeHorizontal * (Time.deltaTime * 10));
}
//}
}
}