private void ThrowRight()
    {
        ThrowableObject to = null;

        if (gc.leftHandObjects.Count > 0 && !LevelEnd)
        {
            to = gc.leftHandObjects.Dequeue();
            to.throwRight();
            Debug.Log("Throw Left");
            gc.stackingIsAllowed = false;

            // Trigger throwing Animation
            timmyAnimator.SetTrigger("throwL");

            Debug.Log(to.gameObject.GetInstanceID() + "Size = " + gc.leftHandObjects.Count);
            ThrowEvent.Invoke();
        }
        else if (LevelEnd)
        {
            // Trigger throwing Animation
            timmyAnimator.SetTrigger("throwL");

            if (!uncontrollableBallsAnimationStarted)
            {
                uncontrollableBalls = Instantiate(uncontrollableBalls);
                uncontrollableBallsAnimationStarted = true;

                ThrowableObject[] _balls = FindObjectsOfType <ThrowableObject>();
                foreach (ThrowableObject ball in _balls)
                {
                    Destroy(ball.gameObject);
                }
            }
        }
    }
Exemplo n.º 2
0
 private void ResetState()
 {
     isHoldingThrowableObject.Value = false;
     throwingForce.Value            = 0f;
     throwableObject    = null;
     transform.rotation = Quaternion.Euler(Vector3.zero);
 }
Exemplo n.º 3
0
 public void Throw(ThrowableObject obj, Transform origin)
 {
     obj.Throw(this);
     obj.transform.position = origin.position + origin.forward * 2 + origin.up;
     obj.gameObject.SetActive(true);
     obj.GetComponent <Rigidbody>().AddForce(origin.forward * 500f);
 }
Exemplo n.º 4
0
    public AudioClip[] reactionsound; // array of soundclips for different results

    void Awake()
    {
        jugsound    = GetComponent <AudioSource>();
        throwable   = GameManager.managerWasa.playercharacter.GetComponent <ThrowableObject>();
        jugPickedup = false;
        hitOnce     = false;
    }
Exemplo n.º 5
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        Debug.Log("called");
        ThrowableObject throwableScript = collision.gameObject.GetComponent <ThrowableObject>();

        if (!throwableScript)
        {
            return;
        }

        if (parryFrames)
        {
            throwableScript.Deflect(GetComponent <Collider2D>());

            GameObject parryEffect = Instantiate(parryParticle, transform.position, transform.rotation);
            Destroy(parryEffect, parryEffectLifetime);

            audioSource.PlayOneShot(parrySound, 0.1f);

            StopCoroutine(parryRoutine);
            endParry();

            Camera.main.GetComponent <TwoPlayerCameraLogic>().beginShaking(0.1f);
            StartCoroutine(PauseScreen());
        }
        else if (!inHitStun && !invulnerable)
        {
            takeDamage(throwableScript.damage);
        }
    }
Exemplo n.º 6
0
 private void PickUpObject(ThrowableObject objectTryingToPickup)
 {
     coll.enabled = false;
     buttonIndicator.indicator.enabled   = false;
     playerState.throwingObject          = true;
     playerState.pickingUpObject         = true;
     playerState.carryingThrowableObject = objectTryingToPickup;
     OnObjectPickedUp.Raise(objectTryingToPickup);
 }
Exemplo n.º 7
0
    private void OnTriggerExit(Collider other)
    {
        ThrowableObject objectTryingToPickup = other.GetComponentInParent <ThrowableObject>();

        if (objectTryingToPickup != null)
        {
            buttonIndicator.indicator.enabled = false;
        }
    }
Exemplo n.º 8
0
    void AndroidUpdate()
    {
        if (!isGrabbing)
        {
            Grab();
        }
        else
        {
            if (Input.touchCount > 0)
            {
                for (int i = 0; i < Input.touchCount; i++)
                {
                    if (isRightSide(Input.GetTouch(i).position))
                    {
                        if (Input.GetTouch(i).phase == TouchPhase.Began)
                        {
                            throwBar.SetActive(true);
                        }

                        if (Input.GetTouch(i).phase == TouchPhase.Stationary)
                        {
                            if (throwForce >= MAX_THROW_FORCE)
                            {
                                isDecreasing = true;
                            }

                            if (throwForce <= MIN_THROW_FORCE)
                            {
                                isDecreasing = false;
                            }

                            if (isDecreasing)
                            {
                                throwForce -= Time.deltaTime * THROW_CHARGE_SPEED;
                            }
                            else
                            {
                                throwForce += Time.deltaTime * THROW_CHARGE_SPEED;
                            }

                            throwSlider.fillAmount =
                                (throwForce - MIN_THROW_FORCE) / (MAX_THROW_FORCE - MIN_THROW_FORCE);
                        }

                        if (Input.GetTouch(i).phase == TouchPhase.Ended)
                        {
                            _grabbedItem.Throw(throwForce);
                            _grabbedItem = null;
                            isGrabbing   = false;
                            RestThrowBar();
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 9
0
    public void PickUpObject(GameObject objectToPickUp)
    {
        throwableObject  = objectToPickUp;
        HasThrowableHead = true;
        ThrowableObject throwableScript = objectToPickUp.GetComponent <ThrowableObject>();

        throwableScript.BeingHeld      = true;
        throwableScript.ObjectToFollow = gameObject;
        throwableGrabbedThisFrame      = true;
    }
Exemplo n.º 10
0
    private void Grab()
    {
#if UNITY_ANDROID
        if (Input.touchCount > 0)
        {
            for (int i = 0; i < Input.touchCount; i++)
            {
                if (Input.GetTouch(i).phase == TouchPhase.Began)
                {
                    // Construct a ray from the current touch coordinates
                    Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
                    if (Physics.Raycast(ray, out RaycastHit hit))
                    {
                        // Grab game object with tab Grab
                        if (hit.transform.CompareTag("Grab"))
                        {
                            _grabbedItem           = hit.transform.GetComponent <ThrowableObject>();
                            hit.transform.position = sushiAnchorPos.position;
                            hit.transform.parent   = sushiAnchorPos.parent;
                        }
                    }
                }

                if (Input.GetTouch(i).phase == TouchPhase.Ended && _grabbedItem)
                {
                    isGrabbing = true;
                }
            }
        }
#elif UNITY_WEBGL || UNITY_EDITOR
        if (Input.GetMouseButtonDown(0))
        {
            // Construct a ray from the current touch coordinates
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out RaycastHit hit))
            {
                // Grab game object with tab Grab
                if (hit.transform.CompareTag("Grab"))
                {
                    _grabbedItem           = hit.transform.GetComponent <ThrowableObject>();
                    hit.transform.position = sushiAnchorPos.position;
                    hit.transform.parent   = sushiAnchorPos.parent;
                }
            }
        }

        if (Input.GetMouseButtonUp(0) && _grabbedItem)
        {
            if (_grabbedItem.transform.parent == sushiAnchorPos.parent)
            {
                isGrabbing = true;
            }
        }
#endif
    }
Exemplo n.º 11
0
    //private Projectile projectile;

    public override void Initialize(GameObject obj)
    {
        throwObject = obj.GetComponent <ThrowableObject>();
        //projectile = obj.GetComponent<Projectile>();
        throwObject.sprite       = sprite;
        throwObject.playerNum    = playerNum;
        throwObject.damage       = damage;
        throwObject.speed        = speed;
        throwObject.range        = range;
        throwObject.HitboxRadius = hitboxScale;
    }
Exemplo n.º 12
0
        IEnumerator Launch(ThrowableObject objectToThrow)
        {
            objectToThrow.onStartThrow.Invoke();
            inThrow = true;
            controlAI.RotateTo(targetDirection);
            controlAI.StrafeMoveTo(transform.position, targetDirection);
            timeToThrow = 0;
            Transform startingPoint  = objectToThrow.customStartingPoint ? objectToThrow.startingPoint : defaultThrowStartPoint;
            bool      canInstantiate = true;
            bool      canThrow       = true;

            while (timeToThrow < objectToThrow.throwObjectDelayTime)
            {
                timeToThrow += Time.deltaTime;
                if (controlAI == null || controlAI.isDead)
                {
                    canInstantiate = timeToThrow >= objectToThrow.minTimeToThrowAfterDead;
                    canThrow       = false;
                    break;
                }
                yield return(null);
            }
            timeToThrow = 0;
            if (canInstantiate)
            {
                var obj = Instantiate(objectToThrow.prefab, startingPoint.position, startingPoint.rotation) as Rigidbody;
                obj.isKinematic = false;
                if (canThrow)
                {
                    LaunchObject(obj, startingPoint, targetPosition, objectToThrow.throwAngle);
                }
                objectToThrow.onFinishThrow.Invoke();
                if (canThrow)
                {
                    yield return(new WaitForSeconds(2 * objectToThrow.activeCollisionDelayTime));
                }
                else
                {
                    yield return(new WaitForSeconds(1f));
                }
                var coll = obj.GetComponent <Collider>();
                if (coll)
                {
                    coll.isTrigger = false;
                }
            }
            else
            {
                objectToThrow.onFinishThrow.Invoke();
            }
            inThrow = false;
        }
Exemplo n.º 13
0
    private void OnTriggerStay(Collider other)
    {
        ThrowableObject objectTryingToPickup = other.GetComponentInParent <ThrowableObject>();

        if (objectTryingToPickup != null && objectTryingToPickup.hasBeenThrown == false && disableInput.Value == false && playerState.deflecting == false && playerState.sliding == false && playerState.throwingGrenade == false && playerState.meleeing == false)
        {
            buttonIndicator.indicator.enabled = true;
            if (input.yButtonPressed && playerState.grounded && playerState.jumping == false)
            {
                PickUpObject(objectTryingToPickup);
            }
        }
    }
Exemplo n.º 14
0
 public void Throw(string throwableObjectName)
 {
     if (controlAI.ragdolled || controlAI.isDead || controlAI.customAction)
     {
         return;
     }
     if (!inThrow)
     {
         ThrowableObject throwable = throwableObjects.Find(t => t.name.Equals(throwableObjectName));
         if (throwable != null)
         {
             StartCoroutine(Launch(throwable));
         }
     }
 }
Exemplo n.º 15
0
    public void OnThrow()
    {
        int randomThrowableIndex = Random.Range(0, throwablesLeft.Count);

        throwable = throwablesLeft[randomThrowableIndex];
        throwablesLeft.Remove(throwable);
        throwable.transform.position = throwPoint.position;

        currentThrowIndex++;
        throwAnimation.Play(true);
        if (currentThrowIndex < amountOfObjectsToThrow)
        {
            Invoke("OnThrow", objectThrowTimeout);
        }
    }
Exemplo n.º 16
0
    void GLUpdate()
    {
        if (!isGrabbing)
        {
            Grab();
        }

        else
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                throwBar.SetActive(true);
            }

            if (Input.GetKey(KeyCode.Space))
            {
                if (throwForce >= MAX_THROW_FORCE)
                {
                    isDecreasing = true;
                }

                if (throwForce <= MIN_THROW_FORCE)
                {
                    isDecreasing = false;
                }

                if (isDecreasing)
                {
                    throwForce -= Time.deltaTime * THROW_CHARGE_SPEED;
                }
                else
                {
                    throwForce += Time.deltaTime * THROW_CHARGE_SPEED;
                }

                throwSlider.fillAmount = (throwForce - MIN_THROW_FORCE) / (MAX_THROW_FORCE - MIN_THROW_FORCE);
            }

            if (Input.GetKeyUp(KeyCode.Space))
            {
                _grabbedItem.Throw(throwForce);
                _grabbedItem = null;
                isGrabbing   = false;
                RestThrowBar();
            }
        }
    }
Exemplo n.º 17
0
    public void PickUpObject(ThrowableObject newHeldObject)
    {
        if (heldObject == null)
        {
            heldObject = newHeldObject;

            if (heldObject.GetComponent <EnemyController>())
            {
                heldObject.GetComponent <EnemyController>().enabled = false;
            }
            heldObject.rb.velocity = Vector3.zero;
            offset = new Vector3(0, heldObject.mesh.bounds.size.y / 4, 0);
            heldObject.rb.useGravity = false;
            heldObject.GetComponent <Collider>().enabled = false;
            canThrow = true;
        }
    }
Exemplo n.º 18
0
    public void OnObjectPickedUp(object data)
    {
        ThrowableObject obj = (ThrowableObject)data;

        if (obj != null)
        {
            // now here we find out if it's small, medium, or large
            switch (obj.properties.objSize)
            {
            case "Small": mArgs[1] = "PickupSmall"; break;

            case "Medium": mArgs[1] = "PickupMedium"; break;

            case "Large": mArgs[1] = "PickupLarge"; break;
            }

            AUD_Manager.DynamicDialogue(mEvent, mArgs, gameObject);
        }
    }
Exemplo n.º 19
0
    private void MakeProjectileOnPlayerPosition()
    {
        Debug.Log("The ID of the object throwing is: " + playerInventory.currentWeaponID);
        Vector2 temp = new Vector2(_animator.GetFloat("moveX"),
                                   _animator.GetFloat("moveY"));

        // If it´s thor´s hammer we will play the animation to throw it back and forth
        if (playerInventory.currentWeaponID == 1)
        {
            StartCoroutine(ChangeAnim(temp, GameObject.Find("Mjolnir")));
            ThrowableObject projectile = Instantiate(this.projectiles[playerInventory.currentWeaponID], transform.position, Quaternion.identity).GetComponent <ThrowableObject>();
            projectile.GetComponent <SpriteRenderer>().enabled = false;
            projectile.Setup(temp, ChooseProjectileDirection());
        }
        else
        {
            ThrowableObject projectile = Instantiate(this.projectiles[playerInventory.currentWeaponID], transform.position, Quaternion.identity).GetComponent <ThrowableObject>();
            projectile.Setup(temp, ChooseProjectileDirection());
        }
    }
Exemplo n.º 20
0
    public void OnHitByBat(ThrowableObject throwableObj)
    {
        amountOfObjectsHitByPlayer++;

        if (amountOfObjectsHitByPlayer >= amountOfObjectsToThrow)
        {
            OnPlaySadAnimation();
            Destroy(rigidbody2D);

            Collider2D[] colliders2D = GetComponents <Collider2D>();
            for (int i = 0; i < colliders2D.Length; i++)
            {
                colliders2D[i].enabled = false;
            }

            killTrigger.collider2D.enabled = false;
        }

        DispatchMessage("OnBallHit", null);
    }
Exemplo n.º 21
0
    public void QueueRightHand(ThrowableObject throwableObject)
    {
        if (!stackingIsAllowed)
        {
            if (rightHandObjects.Count > 0 && !inputController.LevelEnd)
            {
                // Trigger Timmy's animations for the failing
                m_Animator.SetTrigger("failC");
                m_Animator.SetTrigger("failL");
                m_Animator.SetTrigger("failR");

                AkSoundEngine.PostEvent("failFeed_event", gameObject);

                //restart level
                StartLevel(currentLevel);
                StartCoroutine(_starManager.ResetStars(0f));
                Debug.Log("Fail!!");
                return;
            }
        }
        rightHandObjects.Enqueue(throwableObject);
    }
Exemplo n.º 22
0
    public IEnumerator ThrowObject()
    {
        canThrow = false;
        float time = 0;

        while (Input.GetKey(KeyCode.Space) && time < 1)
        {
            time += Time.deltaTime;
            gameManager.chargeUpImageFill.fillAmount = time / 1;
            yield return(new WaitForEndOfFrame());
        }

        gameManager.chargeUpImageFill.fillAmount     = 1;
        heldObject.GetComponent <Collider>().enabled = true;
        heldObject.rb.useGravity = true;
        heldObject.thrown        = true;
        if (time > 5)
        {
            time = 5;
        }
        heldObject.rb.AddForce(((transform.forward * forwardThrowPower) + (transform.up * upwardThrowPower)) * (time / 1), ForceMode.Impulse);
        gameManager.chargeUpImageFill.fillAmount = 0;
        heldObject = null;
    }
Exemplo n.º 23
0
    private void OnTriggerEnter(Collider other)
    {
        // Deal with the two deflectors
        BulletDeflector deflector = other.GetComponent <BulletDeflector>();

        if (deflector != null)
        {
            return;
        }

        // Deal with player damage
        IDamageable damageableObject = other.GetComponentInParent <IDamageable>();

        if (damageableObject != null)
        {
            if (other.GetComponentInParent <PlayerHealth>() && bullet.bouncedByPlayer == false && effectiveDeflectorActive.Value == false)
            {
                damageableObject.TakeDamage(bullet.damage);
                AUD_Manager.SetSwitch("ImpactObject", "Character", gameObject);
                AUD_Manager.SetSwitch("ImpactType", "Kinetic", gameObject);
                AUD_Manager.PostEvent("WP_ProjImpact_ST", gameObject);
                bullet.DestroyBullet();
                return;
            }

            // SimpleEnemy se = other.GetComponent<SimpleEnemy>();
            // if (se != null && bullet.bouncedByPlayer == true) {
            //     se.TakeDamage(bullet.damage);
            //     bullet.DestroyBullet();
            //     return;
            // }


            EnemyForceField forceField = other.GetComponent <EnemyForceField>();
            if (forceField != null && bullet.bouncedByPlayer)
            {
                damageableObject.TakeDamage(bullet.damage);
                bullet.DestroyBullet();
                return;
            }
        }

        // Deal with killing the enemy
        AI_Controller enemyController = other.GetComponentInParent <AI_Controller>();

        if (enemyController != null && bullet.bouncedByPlayer)
        {
            enemyController.TakeDamage(bullet.damage);
            bullet.DestroyBullet();
            return;
        }

        // Handle Turret as well.
        AI_Turret turController = other.GetComponentInChildren <AI_Turret>();

        if (turController != null && bullet.bouncedByPlayer)
        {
            turController.TakeDamage(bullet.damage);
            bullet.DestroyBullet();
        }

        // Deal with any object
        if (other.GetComponent <DestroyObjectOnCollision>() != null)
        {
            ThrowableObject throwableObj = other.GetComponent <ThrowableObject>();
            if (throwableObj != null && bullet.bouncedPerfectly)
            {
                throwableObj.DestroyObject();
                return;
            }
            AUD_Manager.SetSwitch("ImpactObject", "Environment", gameObject);
            AUD_Manager.SetSwitch("ImpactType", "Energy", gameObject);
            AUD_Manager.PostEvent("WP_ProjImpact_ST", gameObject);
            bullet.DestroyBullet();
        }
    }
 private void Awake()
 {
     ThrowableObject = GetComponent <ThrowableObject>();
 }
 private void Start()
 {
     th = handle.GetComponent <ThrowableObject>();
 }
Exemplo n.º 26
0
	public void Throw(ThrowableObject obj, Transform origin) {
		obj.Throw(this);
		obj.transform.position = origin.position + origin.forward * 2 + origin.up;
		obj.gameObject.SetActive(true);
		obj.GetComponent<Rigidbody>().AddForce(origin.forward * 500f);
	}
Exemplo n.º 27
0
 public void OnObjectPickedUp(object data)
 {
     throwableObject = playerState.carryingThrowableObject;
     throwableObject.PickUp(transform);
 }
Exemplo n.º 28
0
 public void OnHitByThrowable(ThrowableObject throwableObj)
 {
 }
Exemplo n.º 29
0
 void Awake()
 {
     throwScript = GetComponent <ThrowableObject>();
 }
Exemplo n.º 30
0
 private void Awake()
 {
     _throwableObject = GetComponent <ThrowableObject>();
     rb = GetComponent <Rigidbody>();
 }