Skip to content

Instantly share code, notes, and snippets.

@ahmadnaser
Created December 8, 2015 07:57
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/2380c062f173014bcaea to your computer and use it in GitHub Desktop.
Save ahmadnaser/2380c062f173014bcaea to your computer and use it in GitHub Desktop.
Generate Points from mouse click in c# unity
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