Skip to content

Instantly share code, notes, and snippets.

@ahmadnaser
Created December 3, 2015 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmadnaser/4396aa89b95b32df7e73 to your computer and use it in GitHub Desktop.
Save ahmadnaser/4396aa89b95b32df7e73 to your computer and use it in GitHub Desktop.
PointsHandler.cs Raycast Mouse with Click Event for points game object
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