Nous allons nous occuper de gérer les collisions entre le joueur et les objets en C-sharp.
using UnityEngine; using System.Collections; public class PlayerController : MonoBehaviour { public int speed = 10; private int count; // Use this for initialization void Start () { count = 0; } // Update is called once per frame void FixedUpdate () { float mouveHorizontal = Input.GetAxis("Horizontal"); float mouveVertical = Input.GetAxis("Vertical"); Vector3 mouvment = new Vector3(mouveHorizontal, 0, mouveVertical); rigidbody.AddForce(mouvment * speed * Time.deltaTime); } void OnTriggerEnter(Collider other) { if(other.gameObject.tag == "cube") { other.gameObject.SetActive(false); count = count + 1; } else if(other.gameObject.tag == "mechant") { Application.LoadLevel(0); } } }