- Home /
2D Collider Isnt working
Hi,
Im not sure what I am doing wrong, as the code works on a 3d object. I have tryed applying it to a UI image that is set in screen space, but it isnt picking up being clicked on can anyone help me with why it isnt working.
using UnityEngine;
using System.Collections;
public class ExitScript : MonoBehaviour {
[SerializeField]
DisplayBoxInitializer boxInitializer;
[SerializeField]
GameObject Exit ;
public CharacterMotor charactermotor;
public Player player;
public MouseLook mouselook;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnMouseDown (){
{
charactermotor.enabled = true;
mouselook.enabled = true;
//player.enabled = true;
Screen.lockCursor = true;
GetComponent<Renderer>().material.color = Color.red;
StartCoroutine ("wait");
//Exit.enabled = false;
}
}
IEnumerator wait(){
yield return new WaitForSeconds (0.5f);
player.enabled = true;
}
}
Answer by GameVortex · Jan 26, 2015 at 03:05 PM
As per the manual, the OnMouseDown event is only sent through the GUIElement and Collider components. Collider2D does not trigger this event.
Thanks but how would i go about changing it to have a collider?
You add a normal collider (BoxCollider, SphereCollider etc..) component ins$$anonymous$$d of a Collider2D.
But if what you want is to detect mouse clicks on an UI image then you should use the EventTrigger component.
I am a little lost with whhat he is saying, I have done all up to 5 and I cant see my fuctions anywhere
Now select the function to be called from the list of functions.
i dont have a list of any fuctions of $$anonymous$$e, do I have to rewright some code?