I have a wall in my project and a player. Player has a Rigidbody and a Sphere Collider which is a trigger. My wall has a box collider (trigger) and a script with:
void OnTriggerEnter (Collider col){
if (col.gameObject.name == "Ballmodel"){
switch (PackmanMoving.movementDirection)
{
case 1:
PackMan.transform.Translate(0, 0, -0.05f);
PackmanMoving.movementDirection = 0;
break;
case 2:
PackMan.transform.Translate(-0.05f, 0, 0);
PackmanMoving.movementDirection = 0;
break;
case 3:
PackMan.transform.Translate(0, 0, 0.05f);
PackmanMoving.movementDirection = 0;
break;
case 4:
PackMan.transform.Translate(0.05f, 0, 0);
PackmanMoving.movementDirection = 0;
break;
}
}
}
Pressing Uparrow key sets movementDirection to an integer and a player starts moving in speed of deltatime. When a player hits a wall that has a OnTriggerEnter script attached, it stops and gets back little from the wall. I have around 100 walls in my project which are inside of a gameObject named Walls. If I put my OnTriggerEnter script on Walls, it doesn’t work. However if I put that script on one wall and move into it, the player stops.
How do I make player stop to all walls that are under gameobject Walls? Full scripts:
WallCollision: using UnityEngine;using System.Collections;public class WallCollision : Mo - Pastebin.com
PackmanMoving: using UnityEngine;using System.Collections;public class PackmanMoving : Mo - Pastebin.com