I was trying to make an object move to a random X position. But when I run the code the object just stays in the same position.
public class RandomSpawn : MonoBehaviour
{
Rigidbody2D body;
float Y = 3.71f;
public bool findNewPos = false;
float Xmax = 3.71f;
float Xmin = -6.0f;
float X = 0f;
Vector2 Pos;
// Start is called before the first frame update
void Start()
{
body = GetComponent();
findNewPos = true;
}
void Update()
{
if(Y == -3.47f)
{
findNewPos = true;
}
if(findNewPos == true)
{
X = Random.Range (Xmin, Xmax);
Pos = new Vector2 (X, Y);
}
}
↧