Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
manlykeweaver465

Adding a fixed distance between 2 sprite objects (C#, UNITY)

nvm i fixed it 

Recommended Posts

Posted · Original PosterOP

hey guys I'm creating an infinite 'Flappy bird' like game, when both objects are instantiated it gets given a random range, to add some RNG into the game but i want to add a consistent fixed distance between the 2 platforms and I'm not sure how to do it, I've tried lots of different things like using vector2.distance and changing the position of the object to a specific distance but i cant seem to get it to work, here's my code.

public class Spawner : MonoBehaviour {
	public GameObject Platform1;
	public GameObject Platform2;

	public float CoolDown = 3f;
	public float CoolDownTimer;

	// Use this for initialization
	void Start () {
		
	}

	// Update is called once per frame
	void Update () {
		if (CoolDownTimer > 0) {
			CoolDownTimer -= Time.deltaTime;
		}
		if (CoolDownTimer < 0) {
			CoolDownTimer = 0;
		}

		if (CoolDownTimer == 0) {
			Vector2 RandRange = new Vector2 (10f, Random.Range(2f, 6f));
			Instantiate (Platform1, RandRange, transform.rotation);

			Vector2 RandRange2 = new Vector2 (10f, Random.Range(-2f, -6f));
			Instantiate (Platform2, RandRange2, transform.rotation);

			CoolDownTimer = CoolDown;
		}

	}
}

 

any help will be appreciated, thanks :).

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×