12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using UnityEngine;
- public class Painter : MonoBehaviour
- {
-
-
-
- public Color32 penColor;
- public Transform rayOrigin;
- private RaycastHit hitInfo;
-
- private bool IsGrabbing;
- private static PaintBoard board;
- private void Start()
- {
-
- foreach (var renderer in GetComponentsInChildren<MeshRenderer>())
- {
- if (renderer.transform == transform)
- {
- continue;
- }
- renderer.material.color = penColor;
- }
- if (!board)
- {
- board = FindObjectOfType<PaintBoard>();
- }
- }
- private void Update()
- {
- Ray r = new Ray(rayOrigin.position, rayOrigin.forward);
- Debug.DrawLine(rayOrigin.position, rayOrigin.position + rayOrigin.forward * 10, Color.red);
- if (Physics.Raycast(r, out hitInfo, 0.1f))
- {
- if (hitInfo.collider.tag == "Board")
- {
-
- board.SetPainterPositon(hitInfo.textureCoord.x, hitInfo.textureCoord.y);
-
- board.SetPainterColor(penColor);
- board.IsDrawing = true;
- IsGrabbing = true;
- }
- }
- else if (IsGrabbing)
- {
- board.IsDrawing = false;
- IsGrabbing = false;
- }
- }
- }
|