using UnityEngine;
using System.Collections;
public class Cursor : MonoBehaviour {
void Start ()
{
gameObject.GetComponent("Slicer").active = false;
}
void Update () {
gameObject.transform.position = Camera.main.ScreenToWorldPoint( new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0));
if (Input.GetMouseButton(0))
{
Debug.Log("mouse pressed");
try
{
gameObject.GetComponent("Slicer").active = true;
}
catch
{
Debug.Log("falied");
}
}
else
{
Debug.Log("mouse not pressed");
try
{
gameObject.GetComponent("Slicer").active = false;
}
catch
{
Debug.Log("falied");
}
}
}
}
i want to acivate a script named “Slicer” attached to the Object only when the left mouse button is pressed, but it keep diactivate the object itself, any ideas why?