Created
December 21, 2020 01:05
-
-
Save marulango/a1ba067f304a0c10f9a25419038a1dff to your computer and use it in GitHub Desktop.
This file contains hidden or 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; | |
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