2
私は自分のシーンでオブジェクトをインスタンス化しています。 オブジェクトはインスタンス化されますが、カメラのターゲットにオブジェクトを渡す方法はわかりません。 とあなたカントドラッグインスタンス化されたオブジェクトインスペクタにカメラにインスタンス化されたオブジェクトを渡す方法
public class TankManager : MonoBehaviour
{
void Start()
{
Instantiate (MenuManager.SelectedCharacter, Vector3.zero, Quaternion.identity);
}}
私のカメラコード:
public class FollowCamera : MonoBehaviour{
public Transform target;
public Vector3 offsetPosition;
public Space offsetPositionSpace = Space.Self;
public bool lookAt = true;
private void Update()
{
Refresh();
}
public void Refresh()
{
if(target == null)
{
Debug.LogWarning("Missing target ref !", this);
return;
}
if(offsetPositionSpace == Space.Self)
{
transform.position = target.TransformPoint(offsetPosition);
}
else
{
transform.position = target.position + offsetPosition;
}
if(lookAt)
{
transform.LookAt(target);
}
else
{
transform.rotation = target.rotation;
}
}
}
それは働いてくれてありがとう兄弟ですが、gameobjectを読んでいる人のための少しの強化は、変換する必要がありますもキャストが必要です。 –