using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Collisione : MonoBehaviour
{
public GameManager gameManager;
public GameObject NemiciRossi;
// Start is called before the first frame update
void Start()
{
}
private void OnCollisionEnter(Collision other)
{ //distruggo nemico blu con player
if (other.gameObject.tag == "PuntiBlu")
{
Destroy(other.gameObject);
//assegno la posizione al nemico rosso
float asseX = Random.Range(-15f, 15f);
float asseZ = Random.Range(-15f, 15f);
//instanzio nemico rosso
Instantiate(NemiciRossi);
NemiciRossi.transform.position = new Vector3(asseX, 1, asseZ);
gameManager.NemiciRimasti();
}
//distruggo il player con nemico rosso
if (other.gameObject.tag == "NemiciRossi")
{
Destroy(gameObject);
//nemicirimasti di gamemanager si incrementa di uno
gameManager.NemiciRimasti();
SceneManager.LoadScene("Fine");
}
}
}
I have no idea why, but it worked for me after adding a Rigidbody to the Player.
If you want to stop the Player from falling over if you have a Rigidbody attached, you can use the Constrains, located in the Rigidbody component and freeze the x and z rotation.