I am making a game where the player is moving automatically with this script
using UnityEngine;
public class MovementForward : MonoBehaviour {
public Rigidbody rb;
public float forwardForce = 2000f;
// Update is called once per frame
void FixedUpdate ()
{
rb.AddForce (0, 0, forwardForce * Time.deltaTime);
if (rb.position.y < -1f)
{
FindObjectOfType().EndGame();
}
}
}
I have buttons which move the player left and right. Right now I am using a script where when I use the buttons, the player goes forwards and backwards. I want to make the player move left and right instead of forwards and backwards. What do I do?
using UnityEngine;
using System.Collections;
public class LeftandRight : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void Left()
{
(GameObject.Find("Player")).transform.Translate(-500f * Time.deltaTime, 0, 0);
}
public void Right()
{
(GameObject.Find("Player")).transform.Translate(500f * Time.deltaTime, 0, 0);
}
}
↧