- Home /
Cube under the First Person Controler
I like to make a script which checks if a cube is under the First Person Controler. How should I try to do this in C# , i`ve tryed it with OnTriggerStay but then the cube must be the trigger so what should i do?
You could try using OnTriggerEnter/OnTriggerExit, other than that I can't really help you because I don't know what you are trying to accomplish. Please be specific.
Edit- Are you trying to see if the character is grounded?
Answer by Digital-Phantom · Mar 25, 2015 at 07:08 PM
Add an empty game object to the cube, give this empty object its own collider. Raise the collider slightly so its above the cube and have that as the trigger.
This uses a lot of extra memory so will decrease performance, but still a good idea, thumbs up to you!
Answer by JigneshKoradiya · Mar 25, 2015 at 07:11 PM
you have to put box collider on leg of your character of FPcontroller and you have to put collider on that box when they collide you will get event,put this script on your FPC player and give your box to name Box
using UnityEngine; using System.Collections;
public class FPCScript: MonoBehaviour {
void OnCollisionEnter(UnityEngine.Collision hit)
{
hitobject = hit.gameObject.tag;
if(hitobject == "Box")
{
Debug.Log("player is on box");
}
}
}