Unityについての質問です。
人型のオブジェクトのグラフィックの挙動がおかしいのですが、どうすれば直るのでしょうか。
具体的にいうと、このオブジェクトのグラフィックは Spriterendererを動的に変更することとAnimationのふた通りで変えているのですが、前者がうまくいきません。おそらく、その理由はアニメーションが常時発動して邪魔をしているためと思われますが、Animationspeedを0にしても、Animationが優先されてしまい、またAnimationのExitを使用しても再びAnimationがEntryから始まってしまうので、常時アニメーションで上書きされてしまいます。
どうすればいいですか?
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class PlayerS : MonoBehaviour { SpriteRenderer SPRE; public Sprite PDOWN; public Sprite PRIGHT; public Sprite PUP; public int[] EventsS = new int[10] { 0, 0, 0, 0, 0, 00, 0, 0, 00, 0, }; AudioSource[] sounds; Animator animator; MapManager MMS; public GameObject MapManagerR; public GameObject Gary; Doctor GaryS; public int FieldNUM; public bool EnCount; public bool BattleS; public bool S;//歩けるか public GameObject Chat; string T; string C; bool AS = false; public float movespeed; // Start is called before the first frame update void Start() { SPRE = gameObject.GetComponent<SpriteRenderer>(); SPRE.sprite = PDOWN; Debug.Log(SPRE.sprite); GaryS = Gary.GetComponent<Doctor>(); EventsS = new int[] { 0, 0, 0 }; this.animator = GetComponent<Animator>(); MMS = MapManagerR.GetComponent<MapManager>(); transform.position = new Vector2(-26.5f, 41); sounds = GetComponents<AudioSource>(); if (EventsS[0] == 1) { Gary.SetActive(false); } else { GaryS.Down(); } } void FixedUpdate() //void Update() { //if (Input.GetKeyDown(KeyCode.R)) //{ // //transform.position = new Vector2(320, -77); // EnCount = true; //} transform.rotation = Quaternion.Euler(0, 0, 0); if (S == false) { if ((Input.GetKey(KeyCode.LeftShift))|| (Input.GetKey(KeyCode.RightShift))) { movespeed = 0.2f; } else { movespeed = 0.15f; } if (BattleS == true && EnCount == true && FieldNUM != 0) { Battle(); } if (Input.GetKey(KeyCode.UpArrow) || (Input.GetKey(KeyCode.DownArrow) || (Input.GetKey(KeyCode.RightArrow) || (Input.GetKey(KeyCode.LeftArrow) || ((Input.GetKey(KeyCode.W) || (Input.GetKey(KeyCode.A) || (Input.GetKey(KeyCode.S) || (Input.GetKey(KeyCode.D)))))))))) { if (AS== false) { this.animator.speed = (movespeed / 0.1f); } else { this.animator.speed = 0; } } else { movespeed = 0; this.animator.speed = 0; } //if (BattleS == true && EnCount == true && FieldNUM != 0) //{ // Battle(); //} } else { movespeed = 0; this.animator.speed = 0; }
このコードでGameを実行すると、voidStartでSPRE.spriteをPDOWNに切り替えようとしているのですが、切り替わらずに、InspectorのspriterendererにはNoneが表示されます。
その時のアニメーターは、Entryの次のplayerに設定されていて、速度は0になっていました。
あなたの回答
tips
プレビュー