I have a problem with collision detection between 2 objects.
I'm creating a GoogleVr zombie shooting game. When a zombie enter the red area, the game should be game over.
I've created following script on the red area object.using UnityEngine;.
using System.Collections;
public class YouLoseIfEnemyHitsThis : MonoBehaviour
{
void OnTriggerEnter(Collider col)
{
if(col.gameObject.name == "zombie")
{
Debug.Log("Game is over. I am showing the VR Canvas");
}
if (col.gameObject.name == "Zombie")
{
Debug.Log("Game is over. I am showing the VR Canvas");
}
if (col.gameObject.name == "enemy")
{
Debug.Log("Game is over. I am showing the VR Canvas");
if (col.gameObject.name == "Enemy")
{
Debug.Log("Game is over. I am showing the VR Canvas");
}
}
}
private void OnCollisionEnter(Collision collision)
{
print(collision.collider.name);
if (collision.collider.name == "zombie")
{
print("APESHIT!");
}
if (collision.collider.name == "Zombie")
{
print("APESHIT!");
}
}
}
Can someone help me out? i've tried everything.
it print nor log anything. i cant seems to trigger it
go to the unity forums.
>>58911922
Okay thanks anon
>>58911865
ever heard of OR statements?
Like "if A == 1 || A == 2 || A == 3 || ..."
>>58911865
what the fuck is this retarded code? It's even retardier than the code of that anime schoolgirl game
>Using gameobject name and not tags
>Using both OnTriggerEnter and OnCollisionEnter
>Using print and Debug.Log interchangably
>Random whitespace
>private void and [nothing] void
>That class name
>Using System.Collections even though you use it
Holy shit anon. Post on Unity Answers before you ask /g/ or atleast go to AGDG on /vg/
(Not to mention you made a new thread instead of asking /sqt/)
Jesus shit dude. Atleast try thinking by yourself
>>58912055
or isn't a statement, it's a logical connective
You check for name "enemy" first and then "Enemy". C# is case sensitive.
>>58911865
Make your own engine
last time I help you you autistusing UnityEngine;
using System.Collections;
public class YouLoseIfEnemyHitsThis : MonoBehaviour
{
void OnTriggerEnter(Collider col)
{
if(col.gameObject.name.ToLower() == "zombie")
{
Debug.Log("Game is over. I am showing the VR Canvas");
}
if (col.gameObject.name.ToLower() == "enemy")
{
Debug.Log("Game is over. I am showing the VR Canvas");
}
}
private void OnCollisionEnter(Collision collision)
{
print(collision.collider.name);
if (collision.collider.name.ToLower() == "zombie")
{
print("APESHIT!");
}
}
}
>>58916236
even betterusing UnityEngine;
using System.Collections;
public class YouLoseIfEnemyHitsThis : MonoBehaviour
{
void OnTriggerEnter(Collider col)
{
String name = col.gameObject.name.ToLower();
if((name == "zombie") || (name == "enemy"))
{
Debug.Log("Game is over. I am showing the VR Canvas");
}
}
private void OnCollisionEnter(Collision collision)
{
print(collision.collider.name);
if (collision.collider.name.ToLower() == "zombie")
{
print("APESHIT!");
}
}
}
>>58911865
You don't need to use OnCollisionEnter when your red area is a Trigger collider. The OnTriggerEnter events should be good enough
Show us the gameobject/rigidbody setup of the zombie. That's probably where your issue is.
this isn't fucking stack overflow fucking mongoloid
>>58911865
>I'm creating a GoogleVr zombie shooting game
I hope you die in your sleep.
>>58918497
There is nothing wrong with VR games.