Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class DubPlayer : MonoBehaviour
- {
- //public static bool carrotboost = false;
- public static float energy = 500;
- public static bool boostActive;
- bool isplaying;
- //Boost atack
- public float boost = 1500f;
- //Soul Component
- Soul soul;
- //Enemy component
- Enemy enemy;
- //Manager component
- Manager manager;
- //Bullet component
- Bullet bullet;
- public GameObject Title;
- // Call a coroutine inside the Start method
- IEnumerator Start()
- {
- energy = 500;
- Title = GameObject.Find ("Title");
- /*if (carrotboost == true)
- CarrotBoost();*/
- //Get soul component
- soul = GetComponent<Soul>();
- while (true)
- {
- // Make the bullet or power, using the player's position
- soul.Shot(transform);
- // Play the shot sound effect
- audio.Play();
- // Wait for shotDelay seconds
- yield return new WaitForSeconds(soul.shotDelay);
- }
- }
- // For determining which way the player is currently facing.
- [HideInInspector]
- public bool facingRight = true;
- // Summon animator
- Animator animator;
- public bool flying;
- void Update()
- {
- //animator.SetBool("flying", true);
- if (gameObject.layer != LayerMask.NameToLayer("Boost"))
- gameObject.layer = LayerMask.NameToLayer("Boost");
- //When Players reaches desired (L/R) possition make him stop
- if (transform.position.x <= -7.5f)
- transform.position = new Vector3(-7.5f, transform.position.y, transform.position.z);
- else if (transform.position.x >= 20.5f)
- transform.position = new Vector3(20.5f, transform.position.y, transform.position.z);
- //When Players reaches desired (U/P) possition make him stop
- if (transform.position.y <= -6f)
- transform.position = new Vector3(transform.position.x, -6f, transform.position.z);
- else if (transform.position.y >= 3f)
- transform.position = new Vector3(transform.position.x, 3f, transform.position.z);
- //Get animator
- animator = GetComponent<Animator>();
- //Boost condition
- {
- /*
- if (carrotboost)
- CarrotBoost();*/
- //boostActive = Input.GetButton("Fire1");
- if (boostActive)
- {
- //Drain energy
- energy -= 1;
- //Player dash
- animator.SetBool("flying", true);
- rigidbody2D.AddForce(new Vector2(0, boost));
- //Change layer type
- gameObject.layer = LayerMask.NameToLayer("Boost");
- //Delete the player
- //soul.Explosion();
- /*Explode
- Destroy(gameObject);*/
- // Play the shot sound effect
- if (isplaying == false)
- {
- audio.Play();
- isplaying = true;
- }
- }
- else
- {
- //Make player back to normal state
- animator.SetBool("flying", false);
- //Back to normal layer
- gameObject.layer = LayerMask.NameToLayer("Player");
- isplaying = false;
- }
- if (energy <= 0)
- {
- Application.LoadLevel (Application.loadedLevel);
- soul.Explosion();
- Destroy(gameObject);
- }
- if (energy > 500)
- energy = 500;
- energy = energy - 1*Time.deltaTime;
- }
- // Cache the horizontal input.
- float h = Input.GetAxis("Horizontal");
- // If the input is moving the player right and the player is facing left...
- if (h > 0 && !facingRight)
- // ... flip the player.
- Flip();
- // Otherwise if the input is moving the player left and the player is facing right...
- else if (h < 0 && facingRight)
- // ... flip the player.
- Flip();
- // Move left and right
- float x = Input.GetAxisRaw("Horizontal");
- // Move up and down
- float y = Input.GetAxisRaw("Vertical");
- // Get the direction of movement
- Vector2 direction = new Vector2(x, y).normalized;
- // Move
- soul.Move(direction);
- // while bunny is alive
- energy -= (1 * Time.deltaTime);
- }
- // Bunny movement
- void Move(Vector2 direction)
- {
- // Get the lower-left world coordinate of the viewport.
- Vector2 min = Camera.main.ViewportToWorldPoint(new Vector2(0, 0));
- // Get the upper-right world coordinate of the viewport.
- Vector2 max = Camera.main.ViewportToWorldPoint(new Vector2(1, 1));
- // Get the coordinates of the player
- Vector2 pos = transform.position;
- // Move by the proper amount
- pos += direction * soul.speed * Time.deltaTime;
- // Restrict the player from moving outside of the screen.
- pos.x = Mathf.Clamp(pos.x, min.x, max.x);
- pos.y = Mathf.Clamp(pos.y, min.y, max.y);
- // Assign the newly-restricted position value.
- transform.position = pos;
- }
- // Called when collision happens
- void OnTriggerEnter2D(Collider2D c)
- {
- if (boostActive)
- {
- }
- else
- {
- //Get the Layer name
- string layerName = LayerMask.LayerToName(c.gameObject.layer);
- // Delete the bullet, if it's in the "bullet (enemy)" layer
- if (layerName == "Bullet (Enemycorn)")
- {
- //Energy goes to zero
- soul.Explosion();
- //Delete the bullet
- Destroy(c.gameObject);
- }
- //Create an explosion if the layer is "Bullet (Enemy)" or "Enemy"
- if (layerName == "Bullet(Enemycorn)" || layerName == "Enemy" || layerName == "Enemycorn" || layerName == "Enemybullet")
- {
- // Find and acquire the Manager component within the scene, and call the GameOver method.
- FindObjectOfType<Manager>().GameOver();
- Application.LoadLevel (Application.loadedLevel);
- // Explode
- Destroy(gameObject);
- //Delete the player
- soul.Explosion();
- }
- }
- }
- void Flip()
- {
- // Switch the way the player is labelled as facing.
- facingRight = !facingRight;
- // Multiply the player's x local scale by -1.
- Vector3 theScale = transform.localScale;
- theScale.x *= -1;
- transform.localScale = theScale;
- }
- /*public void CarrotBoost()
- {
- for (float contador = 0; contador < 1; contador += 1)
- {
- animator = GetComponent<Animator>();
- //Change layer type
- gameObject.layer = LayerMask.NameToLayer("Boost");
- energy += 5;
- //Player dash
- animator.SetBool("flying", true);
- rigidbody2D.AddForce(new Vector2(0, 1780f));
- //Explosion
- soul.Explosion();
- audio.Play();
- }
- // ----------------------------------
- //player back to normal state
- animator.SetBool("flying", false);
- //Back to normal layer
- gameObject.layer = LayerMask.NameToLayer("Player");
- }
- */
- }
- //public bool boostActive { get; set; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement