- Home /
Question by
Grober · Oct 06, 2018 at 06:35 PM ·
scripting problemcollisionontriggerenterdestroy object
Destroy by Contact (OnTriggerEntry) - destroying more then i want.
Hello, I'm trying to create my first simple game. I'm trying to create rocks that is destroyed in steps, i have create 2 models that fits each other and each one got own collision. That's how my stuff looks like:
prefab
rock1
debuglog
rock1-1
And here is my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class destroybyContact : MonoBehaviour {
public GameObject explosionVIS;
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Boundary")
{
// Debug.Log("1. Boundary START, GameObject:" + gameObject.name + "Other:" + other.name + "KONIEC");
return;
}
if (gameObject.tag == "Skala")
{
if (other.tag == "Skala")
{
//Debug.Log("2. col skala-skala START GameObject" + gameObject.name + "Other: "+ other.name + "Koniec");
return;
}
}
//else
//{
//Debug.Log("Start last else");
if (other.tag == "Player")
{
Debug.Log("3. GameOject: " + gameObject.name + " Other: " + other.name);
Instantiate(explosionVIS, other.transform.position, other.transform.rotation);
}
Debug.Log("4. gameObject: " + gameObject.name + " Other: " + other.name);
Destroy(other.gameObject);
Destroy(gameObject);
Instantiate(explosionVIS, transform.position, transform.rotation);
//}
}
}
for some reason games always detects collision first with smaller one (top) and then with bottom one even if bolt does not hit it.
3.png
(488.8 kB)
Comment