[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Unity Collision Problem

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 16
Thread images: 2

File: Untitled.png (988KB, 1913x633px) Image search: [Google]
Untitled.png
988KB, 1913x633px
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
>>
File: 1463610130993.jpg (22KB, 306x306px) Image search: [Google]
1463610130993.jpg
22KB, 306x306px
>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 autist

using 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 better
using 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.
Thread posts: 16
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.