Hello all,
I want to be able to click on any gameobject, and if it is tagged with “ClickArea”, an int increases. I have a script, but the click does not register:
-the gameobjects being clicked are tagged
-my script is attached in scene
-debug.log does not return.
While researching, I found this similar answer: OnMouseDown issues!! - Questions & Answers - Unity Discussions
@getyour411 , you mentioned that you thought you could take a look at this other thread. Does anyone know why this is happening?
my script:
using UnityEngine;
using System.Collections;
public class playerpref1 : MonoBehaviour {
public CarrotCount _carrotcount;
public int picked;
// Use this for initialization
void Start ()
{
picked = PlayerPrefs.GetInt ("picked");
StartCoroutine (c1 ());
}
void OnMouseDown ()
{
if (gameObject.tag == "ClickArea")
{
picked += 1;
Debug.Log ("tag");
}
}
IEnumerator c1 ()
{
yield return new WaitForSeconds (1);
PlayerPrefs.SetInt ("picked", picked);
Debug.Log (picked);
PlayerPrefs.Save ();
StartCoroutine (c1 ());
}
}
Any ideas?
Once again, thanks for the help.