Unityでゲームを作っているのですが、Playerのインスペクターを開いていないと質量や重力などの変更が反映されません。重力が無くなってしまうとかいうのではなく変更だけが反映されません。
どなたか心当たりのある方はいますでしょうか?
使っているUnityのバージョンは 2021.2.8f1 です。
↓↓Playerにつけているスクリプトです。
C#
コード using System.Collections; using System.Collections.Generic; using UnityEngine; public class Controller: MonoBehaviour { public bool click; public float Jumppower; public Jump script; public GameObject jumpbox; private SpriteRenderer spr; private Rigidbody2D rb; private Animator anim; public float speed; void Start() { Jumppower = 20; this.jumpbox = GameObject.Find("GroundBox"); this.script = jumpbox.GetComponent<Jump>(); this.rb = GetComponent<Rigidbody2D>(); this.anim = GetComponent<Animator>(); this.spr = GetComponent<SpriteRenderer>(); } void Update() { bool onground = script.ground; //移動 float x = Input.GetAxisRaw("Horizontal"); //反転 if (Input.GetKey(KeyCode.A)) { spr.flipX = true; }else if(Input.GetKey(KeyCode.D)) { spr.flipX = false; } //移動のアニメーション anim.SetFloat("Speed", Mathf.Abs( x * speed)); rb.AddForce(new Vector2( x * speed, 0)); //ジャンプのアニメーション anim.SetBool("OnGround", onground); //ジャンプ if (Input.GetKey(KeyCode.Space)) { if(onground == true) { rb.AddForce(new Vector2(0, Jumppower)); } } //速度の上限設定 float velX = rb.velocity.x; float velY = rb.velocity.y; if(Mathf.Abs(velX) > 10) { if (velX > 10.0f) { rb.velocity = new Vector2(10.0f, velY); } if (velX < -10.0f) { rb.velocity = new Vector2(-10.0f, velY); } } //左クリックの判定 if (Input.GetMouseButtonDown(0)) { click = true; } if (Input.GetMouseButtonUp(0)) { click = false; } //弾を発射するアニメーション anim.SetBool("Click", click); } }
まだ回答がついていません
会員登録して回答してみよう