The script to move my enemy “left” worked yesterday on my work PC.
Opening to today on laptop and its spits out compiler errors?
//GetComponent ().velocity = Vector2.left;
Is vector2.left not supported in certain versions of unity?
How can I modify this script below to move my enemy left right now it just moves right?
GetComponent().velocity = new Vector2 (velocity, GetComponent().velocity.y);
Is there a better way to move an enemy across the screen towards left? In fixed update?
Thanks
negative velocity?
GetComponent().velocity = new Vector2 (-velocity, GetComponent().velocity.y)
What error do you get when trying to do Vector2.left?
- velocity did not work
Am i missing a using statement for vector2 left?
here is the error message i get.
Assets/scripts/MoveEnemy.cs(14,65): error CS0117: UnityEngine.Vector2' does not contain a definition for left’
Problem solved
GetComponent ().velocity = -Vector2.right;
using UnityEngine;
using System.Collections;
public class MoveEnemy : MonoBehaviour {
public GameObject Player;
public float velocity = -1.0f;
void Start () {
}
// Update is called once per frame
void FixedUpdate () {
GetComponent<Rigidbody2D> ().velocity = -Vector2.right;
}
void OnTriggerEnter(Collider other){
if(other.gameObject.CompareTag("Player")){
Destroy (Player);
Debug.Log ("Hit");
}
}
}