Question by
El-Deiablo · Apr 23, 2016 at 06:00 PM ·
transformtranslatehorizontal movement
X-Axis Movement Using Transform Issue
I have a very simple code here that I am trying to use to make an enemy run across the screen depending on the side it is spawned. When I play the scene the enemy moves, but then halts at the center of the screen. What is causing this issue?
My Code:
using UnityEngine; using System.Collections;
public class RunningPlayerMove : MonoBehaviour { public GameObject runningPlayer; public float speed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(runningPlayer .transform .position .x<0){
//transform.Translate(Vector3.forward * Time.deltaTime);
transform.Translate(speed,0,0);
}
if(runningPlayer .transform .position .x>0){
//transform.Translate(Vector3.forward * Time.deltaTime);
transform.Translate(-speed,0,0);
} } }
Comment
Your answer
Follow this Question
Related Questions
"transform.Translate" doesn't works 2 Answers
How to Move an Object to a Random Position 0 Answers
GameObject doesn't move 1 Answer
What is the difference between translate and position 1 Answer
Perspective camera touch movement 2 Answers