Easy question: X axis overriding Y. Please help! :D
So.. i have two public floats: speeds and speeds2.. for some reason, i can't figure out how using x and y axis together, because for some reason, the two variables override each other. Please Help :/ p.s = I want that the player will be able to shoot in every direction ( Up down Left Right pressing arrow keys ) ( shooting script)
using UnityEngine;
public class test : MonoBehaviour {
public float speeds;
public float speeds2;
public PlayerController player;
// Use this for initialization
void Start()
{
player = FindObjectOfType<PlayerController>();
if (Input.GetButton("DownArrow"))
{
speeds = -speeds;
}
}
// Update is called once per frame
void Update()
{
GetComponent<Rigidbody2D>().velocity = new Vector2(speeds, GetComponent<Rigidbody2D>().velocity.y);
GetComponent<Rigidbody2D>().velocity = new Vector2(speeds2, GetComponent<Rigidbody2D>().velocity.x);
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Collider")
{
Destroy(this.gameObject);
}
}
}
Comment
On line 24 you have the arguments the wrong way around, the .x value is being used in the 'y' position