UnityとC#を使ってスプラトゥーンみたいな、色を塗るゲームを作りたいのですが・・・
AssetStoreのInk Painterというものを使って実装したいと思っています。
そこでInk PainterのSample04というシーンがあるのですが、それを参考にしたいと思っています。
その中にあるMouse Painterという色を塗る座標を読み取る機能が付いているのですが、その機能を接触したとき(Collision)判定にしたいのですが、どこを変えればいいのかわかりません。
using UnityEngine; namespace Es.InkPainter.Sample { public class MousePainter : MonoBehaviour { /// <summary> /// Types of methods used to paint. /// </summary> [System.Serializable] private enum UseMethodType { RaycastHitInfo, WorldPoint, NearestSurfacePoint, DirectUV, } [SerializeField] private Brush brush; [SerializeField] private UseMethodType useMethodType = UseMethodType.RaycastHitInfo; [SerializeField] bool erase = false; private void Update() { if(Input.GetMouseButton(0)) { var ray = Camera.main.ScreenPointToRay(Input.mousePosition); bool success = true; RaycastHit hitInfo; if(Physics.Raycast(ray, out hitInfo)) { var paintObject = hitInfo.transform.GetComponent<InkCanvas>(); if(paintObject != null) switch(useMethodType) { case UseMethodType.RaycastHitInfo: success = erase ? paintObject.Erase(brush, hitInfo) : paintObject.Paint(brush, hitInfo); break; case UseMethodType.WorldPoint: success = erase ? paintObject.Erase(brush, hitInfo.point) : paintObject.Paint(brush, hitInfo.point); break; case UseMethodType.NearestSurfacePoint: success = erase ? paintObject.EraseNearestTriangleSurface(brush, hitInfo.point) : paintObject.PaintNearestTriangleSurface(brush, hitInfo.point); break; case UseMethodType.DirectUV: if(!(hitInfo.collider is MeshCollider)) Debug.LogWarning("Raycast may be unexpected if you do not use MeshCollider."); success = erase ? paintObject.EraseUVDirect(brush, hitInfo.textureCoord) : paintObject.PaintUVDirect(brush, hitInfo.textureCoord); break; } if(!success) Debug.LogError("Failed to paint."); } } } public void OnGUI() { if(GUILayout.Button("Reset")) { foreach(var canvas in FindObjectsOfType<InkCanvas>()) canvas.ResetPaint(); } } } }
https://teratail.com/help/question-tips まずはこちらをご覧ください。また、今回であれば「unity 接触したとき」などと調べればある程度情報は出て来ると思いますが、どこが分からないのでしょうか。