using System.Collections;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public bool dead = false;
public float speed;
private Rigidbody2D rb2d;
public GameObject[] health;
public GameObject Hazard;
public GameObject HealthPickup;
private bool facingRight;
private void Start()
{
facingRight = true;
rb2d = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
if (Input.GetKey("w") || Input.GetKey("a") || Input.GetKey("s") || Input.GetKey("d"))
{//find controller inputs
float moveHorizontal = Input.GetAxisRaw("Horizontal");
float moveVertical = Input.GetAxisRaw("Vertical");
transform.Translate(moveHorizontal * speed * Time.deltaTime, moveVertical * speed * Time.deltaTime, 0);
}
else
{
float moveHorizontal = Input.GetAxisRaw("JoystickHorizontal");
float moveVertical = Input.GetAxisRaw("JoystickVertical");
transform.Translate(moveHorizontal * speed * Time.deltaTime, moveVertical * speed * Time.deltaTime, 0);
//wowie here im trying
}
}
private void Flip(float moveHorizontal)
{
if (moveHorizontal > 0 && !facingRight || moveHorizontal < 0 && facingRight)
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
public void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Hazard"))
{
SendMessage("TakeDamage", 1);
Destroy(other.gameObject);
}
if (other.CompareTag("HealthPickup"))
{
SendMessage("Heal");
Destroy(other.gameObject);
}
}
}
I'm sorry if I'm making a stupid mistake somewhere, I am very new to this. Any help would be appreciated. I'm trying to make my 2D character flip by making the x Scale -1 when the character switches direction.