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); } } } }
private void ResetState() { isHoldingThrowableObject.Value = false; throwingForce.Value = 0f; throwableObject = null; transform.rotation = Quaternion.Euler(Vector3.zero); }
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); }
public AudioClip[] reactionsound; // array of soundclips for different results void Awake() { jugsound = GetComponent <AudioSource>(); throwable = GameManager.managerWasa.playercharacter.GetComponent <ThrowableObject>(); jugPickedup = false; hitOnce = false; }
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); } }
private void PickUpObject(ThrowableObject objectTryingToPickup) { coll.enabled = false; buttonIndicator.indicator.enabled = false; playerState.throwingObject = true; playerState.pickingUpObject = true; playerState.carryingThrowableObject = objectTryingToPickup; OnObjectPickedUp.Raise(objectTryingToPickup); }
private void OnTriggerExit(Collider other) { ThrowableObject objectTryingToPickup = other.GetComponentInParent <ThrowableObject>(); if (objectTryingToPickup != null) { buttonIndicator.indicator.enabled = false; } }
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(); } } } } } }
public void PickUpObject(GameObject objectToPickUp) { throwableObject = objectToPickUp; HasThrowableHead = true; ThrowableObject throwableScript = objectToPickUp.GetComponent <ThrowableObject>(); throwableScript.BeingHeld = true; throwableScript.ObjectToFollow = gameObject; throwableGrabbedThisFrame = true; }
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 }
//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; }
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; }
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); } } }
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)); } } }
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); } }
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(); } } }
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; } }
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); } }
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()); } }
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); }
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); }
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; }
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>(); }
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); }
public void OnObjectPickedUp(object data) { throwableObject = playerState.carryingThrowableObject; throwableObject.PickUp(transform); }
public void OnHitByThrowable(ThrowableObject throwableObj) { }
void Awake() { throwScript = GetComponent <ThrowableObject>(); }
private void Awake() { _throwableObject = GetComponent <ThrowableObject>(); rb = GetComponent <Rigidbody>(); }