- Home /
Multiple OnControllerColliderHit If statements for collision
So I'm trying to have a room where my character controller jumps onto platforms around the room to get around and once it has touched the platforms it disappears after 1.5 seconds I've been trying different methods for months and nothing has seemed to work
public BoxCollider boxCollider1;
public MeshRenderer meshRenderer1;
public BoxCollider boxCollider2;
public MeshRenderer meshRenderer2;
void OnControllerColliderHit(ControllerColliderHit other)
{
if (other.gameObject.name == "Platform1")
{
boxCollider1.enabled = false;
meshRenderer1.enabled = false;
} else if (other.gameObject.name == "Platform2")
{
boxCollider2.enabled = false;
meshRenderer2.enabled = false;
}
}
I also have 16 different platforms but I'm testing 2 at the moment. If anyone knows an easy fix or better method please let me know thanks!
Answer by jawad111ahmad · Apr 03 at 10:20 AM
public GameObject first;
public GameObject second;
private void OnCollisionEnter(Collision other)
{
if (other.gameObject.name == "Platform1")
{
first.SetActive(False)
} else if (other.gameObject.name == "Platform2")
{
second.SetActive(False)
}
}
i hope that the upper code will work and if you want that the specific gameobject in secene disable after specific time then look at the following link: StartCoroutine
I tried the code and it gave me this error error CS0103: The name 'False' does not exist in the current context
public GameObject first;
public GameObject second;
private void OnControllerColliderHit(ControllerColliderHit hit)
{
if (hit.gameObject.name == "Platform1")
{
first.SetActive(False);
}
else if (hit.gameObject.name == "Platform2")
{
second.SetActive(False);
}
}
also on the first code it worked perfectly on the first object but wouldn’t on the second
Your answer
![](https://koobas.hobune.stream/wayback/20220613054954im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Character Controller Grenade problems 1 Answer
Collision Detection in Capsule Collider 0 Answers
CharacterController collision detection with pendulum like object 0 Answers
Character Controller wont collide (not a trigger issue) 2 Answers
bullet collision with Terrain and Character Collider doesn't work in very fast speed 2 Answers