示例#1
0
    public void Play(Enums.HitType type)
    {
        switch (type)
        {
        case Enums.HitType.Miss:
            audioSource.clip = AudioClipMiss;
            break;

        default:
            audioSource.clip = AudioClipHit;
            break;
        }

        audioSource.Play();
    }
示例#2
0
    public void Hit(Enums.HitType hitType)
    {
        // Only let the symbol be hit once
        if (isHit)
        {
            return;
        }

        // Set to true when player does hit the Symbol
        isHit = true;

        // Play audio depending on the type of hit
        audioManager.Play(hitType);

        StartCoroutine(Deactivate());
    }
示例#3
0
    void Update()
    {
        // Displays the raycast for debugging purposes
        Debug.DrawRay(lineOfSight, direction * HitRange, Color.red);

        // Creates a raycast using an object's origin point, the direction the ray cast is facing, and length of the raycast
        RaycastHit2D hit = Physics2D.Raycast(lineOfSight, direction, HitRange);

        if (hit.collider != null) // Fixes null reference errors
        {
            Symbol symbol = hit.collider.gameObject.GetComponent <Symbol>();
            if (hit.distance <= HitRange && symbol != null)
            {
                // UserInput is adjustable through unity's inspector
                if (Input.GetKeyDown(UserInput)) // Use GetKeyDown instead of GetKey
                {
                    Enums.HitType type = DetermineHitType(hit.distance);
                    Debug.Log("HIT: " + UserInput + " | Type: " + type + " | Distance:" + hit.distance);
                    symbol.Hit(type);
                }
            }
        }
    }