private IEnumerator AnimateEffect()
    {
        _activeCoroutines++;

        GameObject activeEffect = null;

        DelegatesAndEvents.ElementActivated();

        if (_interactionSound != null)
        {
            _as.PlayOneShot(_interactionSound);
        }

        if (_interactionEffect != null)
        {
            activeEffect = Instantiate(_interactionEffect, transform.position, transform.rotation, transform);
        }

        while (activeEffect != null)
        {
            yield return(null);
        }

        _activeCoroutines--;
        CalculateActiveStatus();
        yield return(null);
    }
    // Method to check if any rigidbody (ball) hits the capsule collider of the player.
    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Ball")                                            // Only check collision with objects with correct Tag
        {
            DelegatesAndEvents.ballHitPlayer(this.gameObject);              // Trigger event.
        }

        if (other.tag == "PickUp")                                                              // Only check collision with objects with correct Tag
        {
            Destroy(other.transform.parent.gameObject);
            DelegatesAndEvents.HealthPickedUp(1);
        }
    }
Exemple #3
0
    // Update is called once per frame
    void Update()
    {
        // the movement part of the script

        // Read horizontal and vertical movements into a vector and apply character speed
        Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")) * speed;

        // clamp diagonal movement so that you can't move faster than speed variable
        movement = Vector3.ClampMagnitude(movement, speed);

        // apply gravity
        movement.y = gravity;

        // make the movement independent on computer
        movement *= Time.deltaTime;

        // transforms movement from local space to world space
        movement = transform.TransformDirection(movement);

        // send movement vector to the character controller to make the character move
        _charController.Move(movement);

        // escape to make the cursor visible so it's possible to "drag it outside" of the game window
        if (Input.GetKeyDown("escape"))
        {
            Cursor.lockState = CursorLockMode.None;
        }

        // script for what happens when firing
        if (Input.GetButtonDown("Fire1"))
        {
            DelegatesAndEvents.ShotFired(1);

            // create an instance of a bullet at bullet emitter position and at the same rotation as the bullet emitter
            GameObject temporaryBulletHandler;
            temporaryBulletHandler = Instantiate(bulletPrefab, bulletEmitter.transform.position, bulletEmitter.transform.rotation) as GameObject;

            // change the velocity so the bullet moves forward with bulletSpeed
            temporaryBulletHandler.GetComponent <Rigidbody> ().velocity = temporaryBulletHandler.transform.TransformDirection(Vector3.forward * bulletSpeed);

            // make sure that bullets are destroyed after a while if the bullet doesn't hit anything
            Destroy(temporaryBulletHandler, 10.0f);
        }
    }
 // make a public method that can trigger the ball to be destroyed
 public void Explode()
 {
     // this triggers the event that a ball is destroyed
     DelegatesAndEvents.BallDestroyed(this.gameObject);
 }