MY SCRIPT:
using System.Collections.Generic;
using UnityEngine;
public class DEAD : MonoBehaviour {
public GameObject CAR;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter (Collision col)
{
if (col.gameObject.name == "WALL")
{
CAR.SetActive (true);
}
}
}
I would like to know how to make it possible to set active CAR GameObject if player collides at 20mph speed instead of colliding with specific objects, Thank you!
Hi,
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DEAD : MonoBehaviour
{
public GameObject CAR;
public Rigidbody rb;
public float speed;
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
speed = rb.velocity.magnitude;
}
void OnCollisionEnter(Collision col)
{
if (speed >= 20 && col.gameObject.name == "WALL")
{
CAR.SetActive(true);
}
}
}
I guess you are interested in the impact force when you collide with an obstacle. This information is provided through the impulse property or the relativeVelocity of the Collision object.