TestWay.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace WildAttack
  5. {
  6. public class TestWay : MonoBehaviour
  7. {
  8. // Start is called before the first frame update
  9. void Start()
  10. {
  11. }
  12. public void Init(int i, int k, Vector2 pos, Color color)
  13. {
  14. gameObject.name = $"wayPoint{i + 1}_{k + 1}";
  15. transform.position = new Vector3(pos.x, 30, pos.y);
  16. transform.localScale = Vector3.one * 2;
  17. transform.GetComponent<Renderer>().sharedMaterial.color = Color.white;
  18. transform.GetComponent<Renderer>().material.color = color;
  19. //gameObject.AddComponent<BoxCollider>();
  20. //gameObject.AddComponent<Rigidbody>().freezeRotation = true;
  21. gameObject.layer = LayerMask.NameToLayer("WayPoint");
  22. Ray ray = new Ray(new Vector3(transform.position.x, 30, transform.position.z), -transform.up);
  23. RaycastHit hitInfo;
  24. if (Physics.Raycast(ray, out hitInfo, 100, 1 << LayerMask.NameToLayer("Plane")))
  25. {
  26. transform.position = hitInfo.point;
  27. }
  28. }
  29. // Update is called once per frame
  30. void Update()
  31. {
  32. }
  33. }
  34. }