Problems with simple cube click
I created "main script" and in Start() created simple Cube:
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); cube.transform.localScale = new Vector3 (1,2,1); cube.GetComponent().material.color = new Color(0,0,255); cube.Addcomponent();
and than in CubeScript I have empty Start() and Update() but just your OnMouseDown with
Debug.Log("click detected");
and I can never see logs despite clicking on cube.. Any advice? did I missed something?
Answer by TreyH · Feb 16, 2016 at 12:23 PM
Works for me, check syntax? Are you altering any colliders somewhere? http://i.imgur.com/UgYj4lM.gif
using UnityEngine;
using System.Collections;
public class cubeScript : MonoBehaviour {
void OnMouseDown()
{
Debug.Log("click");
}
}
using UnityEngine;
using System.Collections;
public class makeCube : MonoBehaviour {
// Use this for initialization
void Start () {
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.localScale = new Vector3(1, 2, 1);
cube.AddComponent<cubeScript>();
}
}
Your answer
Follow this Question
Related Questions
I need help with a click to destroy game 1 Answer
ScreenPointToRay 0 Answers
How can I change image when click Icon? 1 Answer
How to make an avatar pop up when clicking a button??/ 0 Answers