0
\$\begingroup\$

Hello i have one problem with my 2d game a made 2d endles racing game and i add cars spawner with prefab and on this scripts i add and coin whith box collider 2d and make trigger and when i play the game when i take the coin my car is rotation on z where is my problem here my code. Start Game After Play Game

using UnityEngine;
using System.Collections;

public class carSpawner : MonoBehaviour {

	public GameObject[] cars;
	int carNo;
	public float maxPos = 1.7f;
	public float delayTimer;
	float timer;

	// Use this for initialization
	void Start () {

		timer = delayTimer;

	}
	
	// Update is called once per frame
	void Update () {

		timer -= Time.deltaTime;
		if (timer <= 0) {

			Vector3 carPos = new Vector3 (Random.Range (-1.7f, 1.7f), transform.position.y, transform.position.z);
			carNo = Random.Range (0, 10);
			Instantiate (cars[carNo], carPos, transform.rotation);
			timer = delayTimer;

		}
			
	
	}
}

void OnCollisionEnter2D(Collision2D col) {
        if (col.gameObject.tag == "coin")
        {
            col.gameObject.SetActive(false);
        }
    }

\$\endgroup\$
0
\$\begingroup\$

I can't really understand your problem, that being said, the Z rotation looks really minimum, it probably has something to do with the car controller script. If you don't want to rotate on the Z axis at all, just mark this inside your car's rigidbody.

enter image description here

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .