Detect Collision in unity easy tutorial

preview_player
Показать описание
Steps:
1. Add rigidbody(non kinematic) and collider with isTriggered=false on one gameObject
2. Add collider with isTriggered=false and tagToDetect on other.
3. Add following script on that object having rigid body
4. You can change the tag string in inspector of script
5. Play the game

Code :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CollisionDetection : MonoBehaviour
{
public string tagToDetect = "Finish";

// Start is called before the first frame update
void Start()
{

}

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

}

private void OnCollisionEnter(Collision collision)
{
{
print("gotHit");
}
}
}
Рекомендации по теме