Created
December 8, 2015 07:57
-
-
Save ahmadnaser/2380c062f173014bcaea to your computer and use it in GitHub Desktop.
Generate Points from mouse click in c# unity
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 SinglePoint : MonoBehaviour { | |
public GameObject circlePointPrefab; | |
public GameObject currentLineRenderer; | |
public GameObject lineRendererPrefab; | |
public Material drawingMaterial; | |
// Use this for initialization | |
void Start () { | |
} | |
// Update is called once per frame | |
void Update () { | |
if(currentLineRenderer==null){ | |
currentLineRenderer=(GameObject)Instantiate(lineRendererPrefab); | |
} | |
if (Input.GetMouseButtonDown (0)) { | |
Vector3 currentPosition=Camera.main.ScreenToWorldPoint(Input.mousePosition); | |
currentPosition.z=-5.0f; | |
InstatiateCirclePoint(currentPosition,currentLineRenderer.transform); | |
} | |
} | |
private void InstatiateCirclePoint(Vector3 pos,Transform parent){ | |
GameObject currentCircle=(GameObject)Instantiate(circlePointPrefab); | |
currentCircle.transform.parent = parent; | |
currentCircle.GetComponent<Renderer> ().material = drawingMaterial; | |
currentCircle.transform.position = pos; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment