I am trying to move a gameobject to right when the right arrow key is pressed. I don’t want to use physics, so i try to add the transform position but it doesn’t work. I have tried using translate to but it didn’t work. I can move the object in the scene view and the transform’s value is changed, but in the play mode i can’t move it. Need some explanation from the expert ^^.
Here is the code i am using to move the object
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
public float speed = 0.1f;
public GameObject player;
// Use this for initialization
void Start () {
}
float x = 0;
// Update is called once per frame
void Update ()
{
if (Input.GetKey(KeyCode.RightArrow))
{
x += speed;
Vector3 newposition = new Vector3(x, 0, 0);
player.transform.position = newposition;
Debug.Log(newposition);
}
}
}