自宅のマシンと大学のマシンに、異なるバージョンのUnityがインストールされています。私の家では新しく、大学では年上で、それが私の問題を引き起こしたのだろうかと思います。ゲームは私の家のコンピュータでさらに開発しようとするまでうまくいった。UnityEngine.Componentに定義が含まれていません... C#
'UnityEngine.Component' does not contain a definition for 'bounds' and no extension method 'bounds' of type 'UnityEngine.Component' could be found. Are you missing an assembly reference?
そして:
は、2つのエラーメッセージを取得
'UnityEngine.Component' does not contain a definition for 'MovePosition' and no extension method 'MovePosition' of type 'UnityEngine.Component' could be found. Are you missing an assembly reference?
をここに私のコードです:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SantaBagController : MonoBehaviour {
public Camera cam;
private float maxWidth;
// Use this for initialization
void Start() {
if (cam == null) {
cam = Camera.main;
}
Vector3 upperCorner = new Vector3 (Screen.width, Screen.height, 0.0f);
Vector3 targetWidth = cam.ScreenToWorldPoint (upperCorner);
float SantaBagWidth = renderer.bounds.extents.x;
maxWidth = targetWidth.x - SantaBagWidth;
}
// Update is called once per frame
void FixedUpdate() {
Vector3 rawPosition = cam.ScreenToWorldPoint (Input.mousePosition);
Vector3 targetPosition = new Vector3 (rawPosition.x, 0.0f, 0.0f);
float targetWidth = Mathf.Clamp (targetPosition.x, -maxWidth, maxWidth);
targetPosition = new Vector3 (targetWidth, targetPosition.y, targetPosition.z);
rigidbody2D.MovePosition (targetPosition);
}
}
助けてください!どうもありがとう!代わりに "MonoBehaviourのプロパティ"(な変換など、レンダラーが、...減価償却される使用
:
その後、
GetComponent<Renderer>().bounds.extents.x;
とレンダラを取得するためにコード全体をGetComponentを使用'Rigidbody2D meRigidbody = GetComponent()'のようなコンポーネントのメンバであれば、正しい 'Component'型を使用していることを確認できます。 –
'rigidbody2D'変数はどこにありますか?どのタイプですか? –