Beispiel #1
0
    void OnCollisionEnter2D(Collision2D coll)
    {
        //Debug.Log(decayed);

        if (coll.gameObject.tag == "Player" && decayed)
        {
            PlayerMovementController player = coll.gameObject.GetComponent <PlayerMovementController> ();
//			Debug.Log(decayed);
            if (player.amountOfBullets < 10)
            {
                SoundController.me.PlaySound(tick, .6f, 1, transform.position.x);
                player.amountOfBullets++;
                player.updateUI();
                Destroy(this.gameObject);
            }
        }


        else if (coll.gameObject.tag == "Player" && !decayed)
        {
            PlayerMovementController player = coll.gameObject.GetComponent <PlayerMovementController> ();
//			Debug.Log(decayed);
            if (!player.invuln)
            {
                //			player.health -= dmg;
                if (player.health == 1)
                {
                    SoundController.me.PlaySoundAtNormalPitch(lastHit, 1f);
                }
                else
                {
                    SoundController.me.PlaySoundAtNormalPitch(playerHit, 1f, transform.position.x);
                    //Debug.Log("???");
                }
                player.respawn();
                GameMaster.me.addColorDrift();
                GameObject flash = Instantiate(DamageFlash, transform.position, Quaternion.identity);
                Camera.main.GetComponent <Screenshake>().SetScreenshake(0.35f, .25f, player);
                Destroy(this.gameObject);
                Destroy(flash, .020f);
            }
            else
            {
                if (coll.contacts.Length > 0)
                {
                    vel = Geo.ReflectVect(prevVel.normalized, coll.contacts [0].normal) * (prevVel.magnitude * 0.65f);
                }
            }
        }


        if ((coll.gameObject.tag == "Stage" || coll.gameObject.tag == "Wall" || coll.gameObject.tag == "Pinata") && coll.contacts.Length > 0)
        {
            vel = Geo.ReflectVect(prevVel.normalized, coll.contacts [0].normal) * (prevVel.magnitude * 0.65f);
            bounceCount++;

            if (bounceCount >= 4)
            {
                decayed = true;
            }

            playBounceSound();
            //SoundController.me.PlaySound (bounce1, .2f, Mathf.Clamp(bounceCount, 1, 3f), Mathf.Clamp(transform.position.x, -1, 1));
            //ParticleEffect (coll.gameObject);
            GameMaster.me.SpawnParticle(bulletWall, coll.contacts[0].point, Color.white, coll.gameObject.GetComponent <SpriteRenderer>().color);
        }

        if (coll.gameObject.tag == "bullet")
        {
//			Debug.Log(coll.contacts.Length);
            Bullet b = coll.gameObject.GetComponent <Bullet>();
            if (coll.contacts.Length > 0)
            {
                if (b.vel == Vector2.zero)
                {
                    b.vel     = vel;
                    b.prevVel = vel;
                    b.spd     = spd;
                }
                else
                {
                    vel = Geo.ReflectVect(prevVel.normalized, coll.contacts [0].normal) * (prevVel.magnitude * 0.65f);
                }
            }
            bounceCount++;

            if (bounceCount >= 4)
            {
                decayed = true;
            }


            playBounceSound();
            ParticleEffect(coll.gameObject);
        }



        if (coll.gameObject.tag == "Pinata")
        {
            Pinata pinata = coll.gameObject.GetComponent <Pinata> ();
            //pinata.StartCoroutine(pinata.Scale());
            pinata.health--;

            if (pinata.physics)
            {
                pinata.physics.vel += -vel * 5f;
            }

            pinata.Shrink();
//			pinata.gameObject.GetComponent<Animator> ().enabled = false;
            ParticleEffect(coll.gameObject);
        }

//		Debug.Log ("Collided with " + coll.gameObject.name);
        //Debug.Log (coll.gameObject.layer.ToString());
        //Destroy (this.gameObject);
    }
 // Start is called before the first frame update
 void Start()
 {
     pinataManager = FindObjectOfType <Pinata>();
 }