Quantcast
Channel: Questions in topic: "random spawn"
Viewing all articles
Browse latest Browse all 125

Random X position 2D

$
0
0
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); } }

Viewing all articles
Browse latest Browse all 125

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>