using System.Collections; using System.Collections.Generic; using UnityEngine; namespace WildAttack { public class TestWay : MonoBehaviour { // Start is called before the first frame update void Start() { } public void Init(int i, int k, Vector2 pos, Color color) { gameObject.name = $"wayPoint{i + 1}_{k + 1}"; transform.position = new Vector3(pos.x, 30, pos.y); transform.localScale = Vector3.one * 2; transform.GetComponent().sharedMaterial.color = Color.white; transform.GetComponent().material.color = color; //gameObject.AddComponent(); //gameObject.AddComponent().freezeRotation = true; gameObject.layer = LayerMask.NameToLayer("WayPoint"); Ray ray = new Ray(new Vector3(transform.position.x, 30, transform.position.z), -transform.up); RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo, 100, 1 << LayerMask.NameToLayer("Plane"))) { transform.position = hitInfo.point; } } // Update is called once per frame void Update() { } } }