C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4namespace EVP 5{ 6 7 public class CarCustomManager : MonoBehaviour 8 { 9 10 11 [System.Serializable] 12 public class CarBodyStatus 13 { 14 15 public string BodyName; 16 public GameObject Body; 17 public float BodyWeight; 18 public Transform TirePosFR; 19 public Transform TirePosFL; 20 public Transform TirePosRR; 21 public Transform TirePosRL; 22 23 } 24 [System.Serializable] 25 public class CarTireStatus 26 { 27 public string TireName; 28 public GameObject Tire; 29 public GameObject TireIcon; 30 public float TireWeight; 31 } 32 public List<CarBodyStatus> CarBody = new List<CarBodyStatus>(); 33 34 public int ChooseCarBody; 35 36 public List<CarTireStatus> CarTire = new List<CarTireStatus>(); 37 38 public int ChooceFrontTire; 39 public int ChooceRearTire; 40 41 public GameObject CustomUICanvas; 42 43 public Transform CarPosition; 44 45 46 public GameObject SubjectCar; 47 48 [Header("WheelColliders")] 49 50 public GameObject WheelClolliderFL; 51 public GameObject WheelClolliderFR; 52 public GameObject WheelClolliderRL; 53 public GameObject WheelClolliderRR; 54 55 [Header("UI")] 56 public Animation Anim; 57 public GameObject FrontTireButton; 58 public AnimationClip animclip; 59 void Start() 60 { //UIcon 61 GameObject FrontTireIcon = Instantiate(CarTire[ChooceFrontTire].TireIcon, new Vector3(1670, 982, 0), Quaternion.identity, CustomUICanvas.transform); 62 63 GameObject RearTireIcon = Instantiate(CarTire[ChooceRearTire].TireIcon, new Vector3(1670, 782, 0), Quaternion.identity, CustomUICanvas.transform); 64 // Anim = this.gameObject.GetComponent<Animation>(); 65 //Customer 66 GameObject Car = Instantiate(new GameObject("Car"), SubjectCar.transform.position, SubjectCar.transform.rotation, SubjectCar.transform); 67 Transform CarTrf = Car.transform; 68 GameObject Carbody = Instantiate(CarBody[ChooseCarBody].Body, SubjectCar.transform.position, SubjectCar.transform.rotation, CarTrf);//cabody 69 Carbody.AddComponent<MeshCollider>(); 70 GameObject Tires = Instantiate(new GameObject("Tires"), CarTrf.position, CarTrf.rotation, CarTrf);//Tires gameobject 71 72 GameObject TireFL = Instantiate(CarTire[ChooceFrontTire].Tire, CarBody[ChooseCarBody].TirePosFL.position, CarBody[ChooseCarBody].TirePosFL.rotation, Tires.transform);//TireFL 73 74 GameObject TireFR = Instantiate(CarTire[ChooceFrontTire].Tire, CarBody[ChooseCarBody].TirePosFR.position, CarBody[ChooseCarBody].TirePosFR.rotation, Tires.transform);//TireFR 75 76 GameObject TireRL = Instantiate(CarTire[ChooceRearTire].Tire, CarBody[ChooseCarBody].TirePosRL.position, CarBody[ChooseCarBody].TirePosRL.rotation, Tires.transform);//TireRL 77 78 GameObject TireRR = Instantiate(CarTire[ChooceRearTire].Tire, CarBody[ChooseCarBody].TirePosRR.position, CarBody[ChooseCarBody].TirePosRR.rotation, Tires.transform);//TireRR 79 80 81 82 83 84 SubjectCar.transform.localScale = new Vector3(2, 2, 2); 85 VehicleController vehicleCon = SubjectCar.GetComponent<VehicleController>(); 86 87 Car.transform.position = CarPosition.position; 88 WheelClolliderFL.transform.position = TireFL.transform.position; 89 WheelClolliderFR.transform.position = TireFR.transform.position; 90 WheelClolliderRL.transform.position = TireRL.transform.position; 91 WheelClolliderRR.transform.position = TireRR.transform.position; 92 93 vehicleCon.wheels[0].wheelTransform = TireFL.transform; 94 vehicleCon.wheels[1].wheelTransform = TireFR.transform; 95 vehicleCon.wheels[2].wheelTransform = TireRL.transform; 96 vehicleCon.wheels[3].wheelTransform = TireRR.transform;//allocation wheel 97 98 } 99 100 void UIcon() 101 { 102 103 Anim.Play("FrontTireMenuOpen"); 104 } 105 void Update() 106 { 107 108 } 109 void OnClick() 110 { 111 Anim.Play("FrontTireMenuOpen"); 112 113 // UIcon(); 114 } 115 } 116}
上のコードでOnClock()を実行すると
The animation state FrontTireMenuOpen could not be played because it couldn't be found!
Please attach an animation clip with the name 'FrontTireMenuOpen' or call this function only for existing animations.
UnityEngine.Animation:Play (string)
EVP.CarCustomManager:OnClick () (at Assets/Original Scripts/CarCustomManager.cs:111)
UnityEngine.EventSystems.EventSystem:Update ()
というエラーコードが出てしまいます。
FrontTireMenuOpenというAnimationClipはAnimationコンポーネントのAnimationsの中にしっかりと入っているのにも関わらず、です。
Anim.play("Animationのanimationsの中にあるanimationClip")ではだめなのでしょうか?
どなたか解決よろしくおねがいします。
あなたの回答
tips
プレビュー