Skip to content
Permalink
ad32e0873f
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
131 lines (102 sloc) 3.04 KB
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class PlayerController : MonoBehaviour
{
public float speed =5f;
private Rigidbody rb;
public Animator animator;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
//Movement
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, 0.0f);
transform.position += movement * Time.deltaTime * speed;
if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.D))
{
//set y rotation to 0
transform.Rotate(0, 360, 0);
animator.SetBool("Run", true);
}
if ( Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.A))
{
//set y rotation to 180
transform.Rotate(0, -180, 0);
animator.SetBool("Run", true);
}
if (Input.GetKeyUp(KeyCode.LeftArrow) || Input.GetKeyUp(KeyCode.A))
{
//set y rotation to 180
transform.Rotate(0, 180, 0);
animator.SetBool("Run", false);
}
if (Input.GetKeyUp(KeyCode.RightArrow) || Input.GetKeyUp(KeyCode.D))
{
animator.SetBool("Run", false);
}
}
private void OnTriggerExit2D(Collider2D other)
{
if (other.gameObject.CompareTag("Boundary"))
{
;
}
}
void OnTriggerEnter2D(Collider2D other)
{
//Scene Walking and loading
if (other.gameObject.CompareTag("Cube"))
{
SceneManager.LoadScene("2D_1");
}
if (other.gameObject.CompareTag("Mage"))
{
SceneManager.LoadScene("Mage");
}
if (other.gameObject.CompareTag("Cube1"))
{
SceneManager.LoadScene("2D_2");
}
if (other.gameObject.CompareTag("Rogue1"))
{
SceneManager.LoadScene("Rogue");
}
if (other.gameObject.CompareTag("Cube2"))
{
SceneManager.LoadScene("2D_3");
}
//Fight yourself:)
if (other.gameObject.CompareTag("Yourself"))
{
SceneManager.LoadScene("Yourself");
if (other.gameObject.CompareTag("Blank"))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
if (other.gameObject.CompareTag("CubeBattle"))
{
SceneManager.LoadScene("2D_4Battle");
}
}
if (other.gameObject.CompareTag("Boundary1"))
{
SceneManager.LoadScene("2D_2");
}
if (other.gameObject.CompareTag("Boundary2"))
{
SceneManager.LoadScene("2D_3");
}
if (other.gameObject.CompareTag("Boundary3"))
{
SceneManager.LoadScene("2D_4");
}
//Enemy Contact
}
}