- Home /
OnMouse...() Does not working.
What im doing wrong? No one of last functions dont workig (OnMouseDrag(), OnMouseDown(), etc.)
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
public class Letter : MonoBehaviour {
bool mouse=false;
public GameObject letter;
void Start () {
GameObject letterclone = (GameObject)Instantiate (letter,transform.position,transform.rotation);
letterclone.transform.position = new Vector3(0,0,5);
}
void Update () {
GameObject let = GameObject.Find("Letter(Clone)");
Vector3 mousepos;
mousepos = Input.mousePosition;
mousepos.z = 5;
mousepos.x -= 648;
mousepos.y -= 330;
let.transform.position = mousepos;
//Debug.Log (mousepos);
//Debug.Log ( let.transform.position);
}
void onMouseDown() {
Debug.Log ("On Mouse Down Event");
}
void OnMouseUp() {
Debug.Log("On Mouse Up Event");
}
void OnMouseOver() {
Debug.Log("On Mouse Over Event");
}
void OnMouseEnter() {
Debug.Log("On Mouse Enter Event");
}
void OnMouseDrag() {
Debug.Log("On Mouse Drag Event");
}
}
Does the letter object have any kind of 3d collider? Because that's how Unity knows that it is being clicked. Also there must not be any colliders between the letter collider and the camera to block the 'view'.
@RyFridge is correct, collider is required in this case for ease of use. Also ensure that you watch your method names, they are case-sensitive, in the case of On$$anonymous$$ouseDown() you had a lower case 'ohh' on line: 24.
void on$$anonymous$$ouseDown() {
should be
void On$$anonymous$$ouseDown() {
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Only Allow One Click on GameObject? 2 Answers
Reference creator of gameObject 1 Answer
How can I move a player toward a gameobject by clickling an image 0 Answers
Distribute terrain in zones 3 Answers