Home > other >  Questions about the cameras follow moving objects
Questions about the cameras follow moving objects

Time:09-28

I built a null object put main cameras on the empty under then I give it a transform input monitoring used in the script for the mobile, but I run after he gave me a lot of error, there are big this way this is what is wrong with you
An error screenshot:
Move scripts:
 
using System.Collections;
Using System. Collections. Generic;
using UnityEngine;

Public class move: MonoBehaviour {
The Transform _transform;
//Use this for initialization
Void the Start () {
_transform=gameObject. GetComponent (a);
}

//Update is called once per frame
Void the Update () {
MonitorUserSelectMoveGameObjet ();
}
///& lt; Summary>
///use iput monitoring user input in the use of the transform mobile game objects
///& lt;/summary>
Private void MonitorUserSelectMoveGameObjet ()
{
If (Input. GetKey (KeyCode. W))
{
_transform. Translate (_transform. Position + Vector3. Forward, Space. The World);
}
If (Input. GetKey (KeyCode. A))
{
_transform. Translate (_transform. Position + Vector3. Left, Space. The World);
}
If (Input. GetKey (KeyCode. S))
{
_transform. Translate (_transform. Position + Vector3. Back to Space. The World);
}
If (Input. GetKey (KeyCode. D))
{
_transform. Translate (_transform. Position + Vector3. Right, Space. The World);
}
}
}

CodePudding user response:

Error message clearly beyond the coordinates of camera screen before
You can know about the difference between camera coordinate system and world coordinate system
I think you want this code?
Float speed=1 f;
//
_transform. Translate (Vector3. Speed up * * Input. GetAxis (" Vertical ") * Time. DeltaTime);

_transform. Translate (Vector3. Right * * Input speed. GetAxis (" Horizontal ") * Time. DeltaTime);

//WASD can refer to the similar
  • Related