Skip to content

Instantly share code, notes, and snippets.

@marulango
Created December 21, 2020 01:05
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 marulango/a1ba067f304a0c10f9a25419038a1dff to your computer and use it in GitHub Desktop.
Save marulango/a1ba067f304a0c10f9a25419038a1dff to your computer and use it in GitHub Desktop.
using UnityEngine;
public class drawManager : MonoBehaviour
{
public GameObject drawPrefab;
GameObject theTrail;
Plane planeObj;
Vector3 startPos;
// This script will simply instantiate the Prefab when the game starts.
void Start()
{
planeObj = new Plane(Camera.main.transform.forward * -1, this.transform.position);
}
void Update()
{
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began || Input.GetMouseButtonDown(0))
{
theTrail = (GameObject)Instantiate(drawPrefab, this.transform.position, Quaternion.identity);
Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
float _dis;
if (planeObj.Raycast(mouseRay, out _dis))
{
startPos = mouseRay.GetPoint(_dis);
}
}
else if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved || Input.GetMouseButton(0))
{
Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
float _dis;
if (planeObj.Raycast(mouseRay, out _dis))
{
theTrail.transform.position = mouseRay.GetPoint(_dis);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment