Exemple #1
0
    private void OnTriggerEnter(Collider other)
    {
        Bobtroller bob = other.gameObject.GetComponent <Bobtroller>();

        if (bob != null)
        {
            Debug.Log("Caught in a Trap! -- Boom!");
            bob.Health -= 25f;
            bob.Health  = Mathf.Max(0, bob.Health);

            if (aud != null)
            {
                aud.Play();
            }

            SoundsListener.RegisterSoundEvent(new SoundEvent {
                eventTime  = Time.time,
                isInternal = false,
                source     = transform.position,
                strength   = 200
            });

            if (particles != null)
            {
                particles.Play();
            }
        }
    }
 // Start is called before the first frame update
 void Start()
 {
     if (instance == null)
     {
         instance = this;
     }
 }
Exemple #3
0
    //public void AddListener(Bobtroller listener)
    //{
    //    listeners.Add(listener);
    //}

    public void OnCollisionEnter(Collision collision)
    {
        Rigidbody rb = this.GetComponent <Rigidbody>();
        //listeners.ForEach((x) => x.HearSound(new SoundEvent { source = collision.GetContact(0).point, strength = collision.relativeVelocity.magnitude * rb.mass, eventTime = Time.time, isInternal=false }));
        SoundEvent se = new SoundEvent {
            source = collision.GetContact(0).point, strength = collision.relativeVelocity.magnitude * rb.mass, eventTime = Time.time, isInternal = false
        };

        SoundsListener.RegisterSoundEvent(se);
    }
Exemple #4
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }

        //Checked for Death
        if (Health <= 0)
        {
            //DIE
            animator.SetBool("fall_backward", true);
            isDead = true;
            return;
        }


        RaycastHit hit;
        Ray        ray          = currentCam.ScreenPointToRay(Input.mousePosition);
        bool       hitSomething = Physics.Raycast(ray, out hit, 100.0f);

        if (Input.GetMouseButtonDown(throwButton))
        {
            if (hitSomething)
            {
                SoundMaker sm = hit.transform.gameObject.GetComponent <SoundMaker>();
                if (sm == null && CurrentDistractions > 0)
                {
                    var        prefab = GetNewSoundMakerPrefab();
                    GameObject obj    = GameObject.Instantiate(prefab, hit.point + (Vector3.up * dropHeight), UnityEngine.Random.rotation);
                    SoundMaker smc    = obj.GetComponent <SoundMaker>();
                    if (smc == null)
                    {
                        smc = obj.AddComponent <SoundMaker>();
                    }

                    //smc.AddListener(this);


                    CurrentDistractions--;
                }
                else
                {
                    //Debug.Log("Kick the box:" + (ray.direction.normalized * 100).ToString());
                    //hit.rigidbody.AddForceAtPosition(hit.transform.worldToLocalMatrix * ray.direction.normalized * flickPower, hit.point);
                    hit.rigidbody.AddForce(ray.direction.normalized * flickPower, ForceMode.Impulse);

                    SoundsListener.RegisterSoundEvent(new SoundEvent
                    {
                        eventTime  = Time.time,
                        isInternal = false,
                        source     = hit.point,
                        strength   = flickPower * hit.rigidbody.mass
                    });
                }
            }
        }

        if (hitSomething)
        {
            SoundMaker sm = hit.transform.gameObject.GetComponent <SoundMaker>();
            if (sm == null)
            {
                Cursor.SetCursor(DropCursor, new Vector2(63, 97), CursorMode.Auto);
            }
            else
            {
                Cursor.SetCursor(ThumpCursor, new Vector2(20, 30), CursorMode.Auto);
            }
        }
        else
        {
            Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
        }

        //animator.SetBool("walking", isWalking);
        //animator.SetBool("aggressive", aggressive);
    }