示例#1
0
    /// <summary>
    /// When something hits us...
    /// </summary>
    /// <param name="collision"></param>
    public virtual void OnTriggerStay2D(Collider2D collision)
    {
        IHittable hit = collision.GetComponent <IHittable>();

        if (hit != null && hit.GetTeam() == Team.Player)
        {
            hit.OnHit(damageAmount, KNOCKBACK * velocity.x * damageAmount);
        }
    }
示例#2
0
    public override void OnTriggerStay2D(Collider2D collision)
    {
        IHittable hit = collision.GetComponent <IHittable>();

        if (hit != null && hit.GetTeam() == Team.Player)
        {
            Explode();
        }
    }
示例#3
0
    /// <summary>
    /// When we enter something...
    /// </summary>
    /// <param name="collision"></param>
    private void OnImpact(RaycastHit2D hit)
    {
        Collider2D other = hit.collider;

        //Check for collideable surface
        if (((1 << other.gameObject.layer) & collisionMask) != 0)
        {
            //Check for one way platforms
            if (!(other.CompareTag(PlatformerController.TAG_ONEWAYPLATFORM) && Vector2.Dot(velocity, Vector2.up) > .5f))
            {
                bool isEnemy = false;
                //Check for hittable
                IHittable hittable = other.gameObject.GetComponent <IHittable>();
                //If we hit something and it is not player affiliated
                if (hittable != null && hittable.GetTeam() != Team.Player)
                {
                    //Determine if it is an enemy
                    isEnemy = hittable.GetTeam() == Team.Enemy;

                    //If it is not a block
                    if (!(slimeType == SlimeType.Purple && other.CompareTag("Block")))
                    {
                        hittable.OnHit(1, 2 * (other.transform.position - transform.position));
                    }
                }

                //Do something, depending on what type of slime we are
                switch (slimeType)
                {
                case SlimeType.Green:
                    //Only do it on vertical faces
                    if (!isEnemy && Vector3.Dot(hit.normal, Vector3.up) > .9f)
                    {
                        //Make drop prefab
                        Instantiate(dropPrefab, hit.point - (Vector2.up * .25f), Quaternion.identity);
                    }
                    break;

                case SlimeType.Purple:
                    if (!isEnemy)
                    {
                        //Round position
                        Vector3 pos = transform.position;
                        pos.x = Mathf.Round(pos.x / 2) * 2;
                        pos.y = Mathf.Round(pos.y / 2) * 2;
                        Instantiate(blockPrefab, pos, Quaternion.identity);
                    }
                    break;

                case SlimeType.Gold:
                    //Make explosion prefab
                    Instantiate(explosionPrefab, hit.point, Quaternion.identity);
                    //Increase particle size
                    splashParticles.transform.localScale = Vector3.one * 1.5f;
                    break;
                }

                //Play particle effect
                splashParticles.transform.SetParent(null);
                splashParticles.Play();

                audio.Play();

                //Destroy self
                Destroy(gameObject);
            }
        }
    }