using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerController : MonoBehaviour
{
public float speed = 12.0f;
public float brake = 0.5f;
private Rigidbody rB;
private Vector3 rbVelo;
public Text goalText;
public bool goalOn;
void Start ()
{
rB = GetComponent<Rigidbody>();
goalText.enabled = false;
goalOn = false;
}
void Update ()
{
if (goalOn == false)
{
rbVelo = Vector3.zero;
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
rbVelo = rB.velocity;
rB.AddForce(x * speed - rbVelo.x * brake, 0, z * speed - rbVelo.z * brake, ForceMode.Impulse);
}
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Goal")
{
other.gameObject.GetComponent<Renderer>().material.color = new Color(1, 0, 0, 1);
rB.AddForce(-rbVelo.x * 0.8f, 0, -rbVelo.z * 0.8f, ForceMode.Impulse);
goalText.enabled = true;
goalOn = true;
}
}
void OnCollisionEnter(Collision other)
{
if (other.gameObject.tag == "Kill")
{
this.gameObject.SetActive(false);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerTrigger : MonoBehaviour
{
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
this.gameObject.GetComponent<Renderer>().material.color = new Color(1, 0, 0, 1);
}
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "Player")
{
this.gameObject.GetComponent<Renderer>().material.color = new Color(0, 0, 1, 1);
}
}
}