C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class Player : MonoBehaviour 6{ 7 private Rigidbody2D myRigidBody; 8 9 public float playerSpeed = 10; 10 // Start is called before the first frame update 11 void Start() 12 { 13 myRigidBody = this.gameObject.GetComponent<Rigidbody2D>(); 14 } 15 16 // Update is called once per frame 17 void FixedUpdate() 18 { 19 Vector2 force = Vector2.zero; 20 21 if (Input.GetKey(KeyCode.LeftArrow)) 22 { 23 force = new Vector2(playerSpeed * -1, 0); 24 } 25 26 if (Input.GetKey(KeyCode.RightArrow)) 27 { 28 force = new Vector2(playerSpeed, 0); 29 } 30 myRigidBody.Moveposition(myRigidBody.position + force * Time.fixedDeltaTime); 31 } 32} 33
エラー内容
Assets/Player.cs(30,21): error CS1061: 'Rigidbody2D' does not contain a definition for 'Moveposition' and no accessible extension method 'Moveposition' accepting a first argument of type 'Rigidbody2D' could be found (are you missing a using directive or an assembly reference?)
どこか構文が間違ってると思うんですがどこがエラーかわからないためわかる方いましたら教えてください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/01/25 08:55