Tanoda
TriggerPainterInUpdate.cs
Go to the documentation of this file.
1using System;
2using UnityEngine;
3
5{
6 [RequireComponent(typeof(Collider), typeof(MeshRenderer))]
7 public class TriggerPainterInUpdate : MonoBehaviour
8 {
9 [SerializeField] private Brush brush;
10
11 private bool draw;
12
13 private Collider savedCollider;
14
15 private bool cantPaint;
16
17 public void Awake()
18 {
19 GetComponent<MeshRenderer>().material.color = brush.Color;
20 }
21
22 private void OnTriggerEnter(Collider other)
23 {
24 if (other.gameObject.layer == /*PREVIEW_LAYER*/20)
25 return;
26
27 savedCollider = other;
28 draw = true;
29 }
30
31 private void OnTriggerExit(Collider other)
32 {
33 draw = false;
34 }
35
36 private void Update()
37 {
38 if (!draw) return;
39 if (!savedCollider) return;
40
41 var canvas = savedCollider?.gameObject.GetComponent<InkCanvas>();
42 if (canvas != null)
43 try
44 {
45 canvas.Paint(brush, savedCollider.ClosestPoint(transform.position));
46 }
47 catch (Exception)
48 {
49 cantPaint = true;
50 }
51 }
52 }
53}
Class managing brush information.
Definition: Brush.cs:11
Color Color
The color of the brush.
Definition: Brush.cs:197