Created
December 3, 2015 17:49
-
-
Save ahmadnaser/4396aa89b95b32df7e73 to your computer and use it in GitHub Desktop.
PointsHandler.cs Raycast Mouse with Click Event for points game object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class PointsHandler : MonoBehaviour { | |
GameObject CurrentPoint; | |
// Use this for initialization | |
void Start () { | |
} | |
// Update is called once per frame | |
void Update () { | |
if (Input.GetMouseButtonUp (0)) { | |
Debug.Log("Up"); | |
if(CurrentPoint!=null){ | |
CurrentPoint.SetActive(true); | |
} | |
} | |
RaycastHit2D hit2d = Physics2D.Raycast (Camera.main.ScreenToWorldPoint(Input.mousePosition),Vector2.zero); | |
if (hit2d.collider != null) { | |
string ob=hit2d.collider.gameObject.tag; | |
if(ob=="point"){ | |
if (Input.GetMouseButtonDown (0)) { | |
CurrentPoint= hit2d.collider.gameObject; | |
CurrentPoint.SetActive(false); | |
} | |
Vector3 forward = hit2d.collider.transform.TransformDirection (Vector3.forward) * 10; | |
Debug.DrawRay (hit2d.collider.transform.position,forward,Color.green); | |
Debug.Log("Ray is here!"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment