Azarian

Feeding the Dragon

by Azarian

Feeding the Dragon Unity

Screenshots

Feeding the Dragon Unity
Feeding the Dragon Unity
Feeding the Dragon Unity
Feeding the Dragon Unity
Feeding the Dragon Unity

Specification

How to Use

Sample Code

using UnityEngine; using System.Collections; public class DragonControl : MonoBehaviour { public float speedMax = 10f; public GameManager gameManager; private Rigidbody2D body2d; private float spriteWidthHalf = 2.20f; private Vector3 scaleBase; public AudioClip[] sndDragonEat; public AudioClip sndBomb; public bool canPlay = false; void Awake() { body2d = GetComponent<Rigidbody2D>(); body2d.velocity = new Vector2(3, 0f); scaleBase = transform.localScale; Invoke("CanPlay", 0.5f); } void Update() { MoveByMouse(); if (transform.localPosition.y < -10) { Camera.main.gameObject.GetComponent<CameraShake>().Shake(); //gameManager.SoundPlay(gameManager.musicPlayer, gameManager.musicLoose); Destroy(gameObject); } } void CanPlay() { canPlay = true; } void MoveByMouse() { if (canPlay) { if (Input.GetMouseButton(0)) { body2d.velocity = new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x - transform.localPosition.x, 0f) * 10f; if (Mathf.Abs(body2d.velocity.x) > speedMax) { body2d.velocity = new Vector2(Mathf.Sign(body2d.velocity.x) * speedMax, 0f); } } else { body2d.velocity = new Vector2(body2d.velocity.x * 0.9f, 0f); } if (body2d.velocity.x < 0 && transform.localPosition.x < -spriteWidthHalf) { body2d.velocity = Vector2.zero; transform.localPositi Vector3(-spriteWidthHalf, transform.localPosition.y, transform.localPosition.z); } else if (body2d.velocity.x > 0 && transform.localPosition.x > spriteWidthHalf) { body2d.velocity = Vector2.zero; transform.localPositi Vector3(spriteWidthHalf, transform.localPosition.y, transform.localPosition.z); } } } void OnTriggerEnter2D(Collider2D col) { if (col.tag == "Fruit") { gameManager.ScoreUp(col.gameObject); Destroy(col.gameObject); StartCoroutine(GFXInflate()); gameManager.SoundPlay(gameObject, sndDragonEat [Random.Range(0, sndDragonEat.Length)]); } else if (col.tag == "Bomb" && canPlay) { col.gameObject.GetComponent<Bomb>().Explod(); GameOver(); body2d.velocity = new Vector2(0.1f, -2.5f); gameManager.SoundPlay(gameObject, sndBomb); gameManager.DragonFallMusic(); } else if (col.tag == "Time" && canPlay) { gameManager.TimeAddUp(col.gameObject); Destroy(col.gameObject); StartCoroutine(GFXInflate()); } } IEnumerator GFXInflate() { transform.localScale = scaleBase * 1.05f; //new Vector3(scaleBase * 0.9f, scaleBase * 0.9f, scaleBase * 0.9f); yield return new WaitForSeconds(0.2f); transform.localScale = scaleBase; } public void GameOver() { canPlay = false; body2d.isKinematic = false; body2d.velocity = new Vector2(0.1f, -1.5f); body2d.AddTorque(-40f); gameManager.Invoke("GameOver", 4); } }

Video

Comments (0)

  • {{com.username}}
    {{com.username}}
    Buyer
    Seller

    {{com.username}}

    {{com.ctime}}

    {{com.content}}

    • {{com2.username}}
      {{com2.username}}
      Buyer
      Seller

      {{com2.username}}

      {{com2.ctime}}

      {{com2.content}}