Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class PlayerControll : MonoBehaviour {
- public bool isGrounded;
- public float jumpHeight = 5F;
- public float speed = 0.1F;
- private Vector3 spawn;
- public GameObject deathParticles;
- public bool standardPlayer;
- public Material[] materials;
- private BoxCollider BC;
- private Rigidbody rb;
- void Start (){
- standardPlayer = true;
- spawn = transform.position;
- rb = this.gameObject.GetComponent<Rigidbody>();
- // Checks if there is a rigidbody component
- if (rb == null) {
- Debug.Log ("this gameobject" + this.gameObject.name + "dose not contain a rigidbody");
- return;
- }
- }
- void OnCollisionEnter (Collision other) {
- isGrounded = true;
- if (other.transform.tag == "Enemy") {
- Instantiate (deathParticles, transform.position, Quaternion.identity);
- transform.position = spawn;
- }
- if (other.transform.tag == "Poison" && standardPlayer == true){
- Instantiate(deathParticles, transform.position, Quaternion.identity);
- transform.position = spawn;
- }
- }
- void FixedUpdate (){
- // Moves the player horizontally
- rb.position += new Vector3 (Input.GetAxis ("Horizontal") * speed, 0, 0);
- // Check and jump
- if (Input.GetKeyDown (KeyCode.UpArrow) || Input.GetKeyDown (KeyCode.W) || Input.GetKeyDown (KeyCode.Space)) {
- if (isGrounded == true) {
- rb.velocity = new Vector3 (0, jumpHeight, 0);
- isGrounded = false;
- }
- }
- if (standardPlayer == true) {
- if (Input.GetKeyDown(KeyCode.Q)){
- standardPlayer = false;
- Renderer rend = GetComponent<Renderer>(); rend.material = materials[1];
- }
- }
- if (standardPlayer == false) {
- if (Input.GetKeyDown (KeyCode.Q)) {
- standardPlayer = true;
- Renderer rend = GetComponent<Renderer> (); rend.material = materials[0];
- }
- }
- }
- void update () {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement