using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Playerscript : MonoBehaviour
{
// Start is called before the first frame update
private float speed = 5f;
public Animator animator;
void Start()
{
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{ // kiểm tra người chơi có đụng tường không.
if (Input.GetKey(KeyCode.LeftArrow))
{
this.transform.Translate(Vector3.left * speed * Time.deltaTime);
this.transform.rotation = Quaternion.Euler(0f, -15f, 0f);
}
else if (Input.GetKey(KeyCode.RightArrow))
{
this.transform.Translate(Vector3.right * speed * Time.deltaTime);
this.transform.rotation = Quaternion.Euler(0f, 15f, 0f);
}
else
{
this.transform.rotation = Quaternion.identity;
}
}
private void OnCollisionEnter(Collision others)
{
if (others.gameObject.CompareTag("Bonked"))
{
animator.SetTrigger("Fall Flat");
animator.Play("Fall Flat");
}
}
}
When I use this code, the player move backwards in x direction.