M
M
MarioKrut2020-06-14 13:44:00
Unity
MarioKrut, 2020-06-14 13:44:00

Wrong C# script?

I have 2 scripts for 3D object

PlayController

using UnityEngine;

public class PlayController : MonoBehaviour
{

  [SerializeField]
    private float speed = 5f;

    void Update(){
    	if(Input.GetKey (KeyCode.D)){
    		transform.Translate(Vector3.right * Time.deltaTime * speed);
    }
    if(Input.GetKey (KeyCode.A)){
    		transform.Translate(Vector3.left * Time.deltaTime * speed);
    }
    if(Input.GetKey (KeyCode.W)){
    		transform.Translate(Vector3.forward * Time.deltaTime * speed);
    }
    if(Input.GetKey (KeyCode.S)){
    		transform.Translate(Vector3.back * Time.deltaTime * speed);
    }		
    if
    }
}


PlayMotor
using UnityEngine;

public class PlayMotor : MonoBehaviour
{

    void Update(){
    float yRot = Input.GetAxisRaw("Mouse X");
    
 		transform.Rotate(0, yRot, 0);
    }

}


PlayController is responsible for moving forward, backward, left, right!
PlayMotor is responsible for turning left and right!

But when walking and turning, the game hangs terribly and the object does not obey button presses!
Tell me why this is happening and how to fix it!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-06-14
@MarioKrut

Update your computer

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question