using System.Collections; using System.Collections.Generic; using UnityEngine; public enum SorghumState { Healthy, Diseased } public class SorghumController : MonoBehaviour { public GameObject DiseasedStrain; public GameObject HealthyStrain; public SorghumState State = SorghumState.Healthy; public bool RandomRotate = true; public void Init(SorghumState _state = SorghumState.Healthy, bool _rand = false) { State = _state; DiseasedStrain.SetActive(State == SorghumState.Diseased); HealthyStrain.SetActive(State == SorghumState.Healthy); RandomRotate = _rand; if (RandomRotate) { // 获取当前旋转角度 Vector3 currentRotation = transform.eulerAngles; // 设置Y轴为随机角度(0到360度) currentRotation.y = Random.Range(0f, 360f); // 应用新的旋转角度 transform.eulerAngles = currentRotation; } } // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } }