public override IEnumerator TakeDamage(float dmgAmt) { if (!healthCanvas.isActiveAndEnabled) { healthCanvas.enabled = true; } healthStat.CurrentVal -= dmgAmt; if (!IsDead) { MyAnimator.SetTrigger("Damage"); GameManager.Instance.score += 10; } else { MyAnimator.SetTrigger("Die"); yield return(null); } }
public void HandleLayers() { if (IsMoving) { ActivateLayer("Walk"); MyAnimator.SetFloat("x", direction.x); MyAnimator.SetFloat("y", direction.y); } else if (isAttacking) { ActivateLayer("Attack"); } else { ActivateLayer("Idle"); } }
public override void Start() { base.Start(); if (gm.IsPvp) { nm = NetworkManager.Instance; } sr = GetComponent <SpriteRenderer>(); healthBar.Initialize(); staminaBar.Initialize(); boxCol = GetComponent <BoxCollider2D>(); sight = GetComponentInChildren <PlayerSight>(); myVoice = GetComponent <AudioSource>(); Dead += (() => MyAnimator.SetTrigger("Dead")); Dead += (() => boxCol.enabled = false); }
private void HandleMovement(float horizontal) { if (MyRigidbody.velocity.y < 0) { MyAnimator.SetBool("land", true); } if (!Attack && !Slide && (OnGround || airControl)) { MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y); } //if (Jump && MyRigidbody.velocity.y == 0) //{ // MyRigidbody.AddForce(new Vector2(0, jumpForce)); //} MyAnimator.SetFloat("speed", Mathf.Abs(horizontal)); }
public override void Death() { fellOff = false; rained = false; time = 0; this.tag = "Enemy"; MyAnimator.SetTrigger("idle"); MyAnimator.ResetTrigger("die"); healthStat.MaxVal = GameManager.Instance.EnemyHealth; healthStat.CurrentVal = healthStat.MaxVal; monsterLevel = GameManager.Instance.EnemyLevel; //for when not death //healthStat.CurrentVal += 10; healthCanvas.enabled = false; Target = null; transform.position = new Vector3(startPos.x + UnityEngine.Random.Range(2.5f, 6.5f), startPos.y, startPos.z); }
public virtual void OnTriggerEnter2D(Collider2D other) { if (other.tag == "SwordCollider") { health.MyCurrentValue -= 5; if (health.MyCurrentValue <= 0) { Direction = Vector2.zero; MyAnimator.SetTrigger("die"); SceneManager.LoadScene("MainMenu"); // Application.Quit(); //works //////////////////INSERT GAME OVER SCENE HERE!!!!!!!!!//////////////////////////////(but since enemy is using this, it will also trigger this event when enemy dies) //character dies } } }
void HandleMovements(float horizontal) { if (Body.velocity.y < 0) { MyAnimator.SetBool("land", true); } if (!Attack && !Slide && (OnGround || airControl)) { Body.velocity = new Vector2(horizontal * maxSpeed, Body.velocity.y); } if (Jump && Body.velocity.y == 0) { Body.AddForce(new Vector2(0, jumpForce)); } MyAnimator.SetFloat("speed", Mathf.Abs(horizontal)); }
/// <summary> /// Stops the attack /// </summary> public void StopAttack() { SpellBook.MyInstance.StopSpell(); IsAttacking = false; //Makes sure that we are not attacking MyAnimator.SetBool("attack", IsAttacking); //Stops the attack animation foreach (GearSocket g in gearSockets) { g.MyAnimator.SetBool("attack", IsAttacking); } if (attackRoutine != null) //Checks if we have a reference to an co routine { StopCoroutine(attackRoutine); } }
// Swaps the animator controller for specified one when active as a puppet. public void SetAnimatorControllerActive(bool isActive) { if (isActive) { if (activatedAnimatorController != null) { MyAnimator.runtimeAnimatorController = activatedAnimatorController; MyAnimator.AnimatorSetDirection(FacingDirection); } } else { MyAnimator.runtimeAnimatorController = inactiveAnimatorController; MyAnimator.AnimatorSetDirection(FacingDirection); } }
private void OnCollisionExit2D(Collision2D other) { if (other.transform.tag == "SwingingPlatform") { transform.parent = null; transform.rotation = Quaternion.identity; OnGround = false; } if (other.transform.tag == "Ground") { OnGround = false; } if (other.transform.name == "Catapult_Bowl") { LaunchPlayer(); MyAnimator.SetBool("land", true); } }
//METHODS: private void HandleMovement(float horizontal) // The horizontal in the parenthesis gets its value from the float Horizontal = blah blah in the fixed update { if (!Attack && (OnGround || airControl)) { MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y); } if (Jump && MyRigidbody.velocity.y == 0) { MyRigidbody.AddForce(new Vector2(horizontal * movementSpeed, jumpForce)); } MyAnimator.SetFloat("Speed", Mathf.Abs(horizontal)); if (Crouch) { MyRigidbody.velocity = new Vector2(0, MyRigidbody.velocity.y); } }
private void LookAtTarget() { if (MyTarget != null) { Vector2 directionToTarget = (MyTarget.transform.position - transform.position).normalized; Vector2 faceing = new Vector2(MyAnimator.GetFloat("x"), MyAnimator.GetFloat("y")); float angleToTarget = Vector2.Angle(faceing, directionToTarget); if (angleToTarget > fieldOfView / 2) { MyAnimator.SetFloat("x", directionToTarget.x); MyAnimator.SetFloat("y", directionToTarget.y); updateDirection = true; } } }
public void ToGrab() { if (Input.GetKeyDown(KeyCode.E)) { if (!grabbed) { Physics2D.queriesStartInColliders = false; hit = Physics2D.Raycast(transform.position, Vector2.right * transform.localScale.x, distance); if (hit.collider != null && hit.collider.tag == "Pick Up") { grabbed = true; hit.transform.SetParent(this.transform, true); MyAnimator.SetTrigger("pickup"); MyAnimator.SetBool("carry", true); MyAnimator.ResetTrigger("throw"); } } else if (Physics2D.OverlapPoint(holdpoint.position, notgrabbed)) { grabbed = false; if (hit.collider.gameObject.GetComponent <Rigidbody2D>() != null) { hit.rigidbody.isKinematic = false; hit.collider.isTrigger = false; hit.transform.parent = null; hit.collider.gameObject.GetComponent <Rigidbody2D>().velocity = new Vector2(transform.localScale.x, 1) * throwforce; MyAnimator.SetTrigger("throw"); MyAnimator.SetBool("carry", false); } } if (grabbed) { hit.collider.gameObject.transform.position = holdpoint.position; } } }
private void HandleInputs() { if (Input.GetButtonDown("Jump")) { MyAnimator.SetTrigger("jump"); } else if (Input.GetButtonUp("Jump")) { if (rb2d.velocity.y > 0) { rb2d.velocity = new Vector2(rb2d.velocity.x, rb2d.velocity.y * 0.5f); } } if (Input.GetButtonDown("Fire1")) { MyAnimator.SetTrigger("attack"); } }
//Handle player inputs and it animations private void handleInput() { if (Input.GetKeyDown(KeyCode.Space)) { MyAnimator.SetTrigger("jump"); } if (Input.GetKeyDown(KeyCode.L)) { MyAnimator.SetTrigger("attack"); } if (Input.GetKeyDown(KeyCode.K)) { MyAnimator.SetTrigger("slide"); } if (Input.GetKeyDown(KeyCode.P)) { MyAnimator.SetTrigger("shoot"); } }
private void HandleInput() { if (Input.GetKeyDown(KeyCode.Space)) { MyAnimator.SetTrigger("jump"); } if (Input.GetKeyDown(KeyCode.LeftShift)) { MyAnimator.SetTrigger("attack"); } //if(Input.GetKeyDown(KeyCode.LeftControl)){ // MyAnimator.SetTrigger ("slide"); //} if (Input.GetKeyDown(KeyCode.V)) { MyAnimator.SetTrigger("throw"); ThrowKnife(0); } }
public override IEnumerator TakeDamage() { health -= 10; if (!IsDead) { MyAnimator.SetTrigger("Damage"); } else { MyAnimator.SetTrigger("Death"); if (health == 0) { gameMenuController.SetLifeImages(); StartCoroutine("Respawn"); } health = 50; } yield return(null); }
protected new void Awake() { base.Awake(); _coll = GetComponent <PolygonCollider2D>(); _rend = GetComponent <SpriteRenderer>(); _anim = GetComponent <MyAnimator>(); _audio = GetComponent <MyAudioSource>(); _coll.enabled = false; _rend.enabled = false; enabled = false; PushingSmallState s1 = new PushingSmallState(_ASM, this); PushingBigState s2 = new PushingBigState(_ASM, this); s1.SetTargetStates(s2); _ASM.InitializeWithStates(new InactiveBaseAttackState(_ASM), s1); }
public virtual void Move(Vector2 dir) { if (!Moveable) { return; } movingDir = dir.normalized; if (dir.magnitude < 0.01f) { isMoving = false; MyRigidbody.velocity = Vector3.zero; MyAnimator.SetBool("isMoving", false); } else { isMoving = true; MyAnimator.SetBool("isMoving", true); } }
// This is a function for player movement private void HandleMovement(float horizontal) { // If we are falling then start the landing animation if (MyRigidbody.velocity.y < 0) { MyAnimator.SetBool("land", true); } // Horizontal movement if (!Attack && !Slide && (OnGround || airControl)) { MyRigidbody.velocity = new Vector2(movementSpeed * horizontal, MyRigidbody.velocity.y); } if (Jump && MyRigidbody.velocity.y == 0) { MyRigidbody.AddForce(new Vector2(0, jumpForce)); } // Set the speed in the Animator MyAnimator.SetFloat("speed", Mathf.Abs(horizontal)); }
void Start( ) { if (useLivesOnly) { maxHealth = 1.0f; startingHealth = 1.0f; } if (this.tag == "Enemy") { anim = GetComponent <MyAnimator> (); } currentHealth = startingHealth; GameObject obj = GameObject.FindWithTag("GameController"); gameController = obj.GetComponent <WinLoseMessage> (); GameObject model = GameObject.FindWithTag("Animated"); charAnim = model.GetComponent <CharAnim> (); }
// проверка на нажатие клавиш и запуск анимации private void HandleInput() { if (Input.GetKeyDown(KeyCode.Space)) { MyAnimator.SetTrigger("jump"); } if (Input.GetKeyDown(KeyCode.LeftControl)) { MyAnimator.SetTrigger("slide"); } if (Input.GetKeyDown(KeyCode.Keypad4)) { MyAnimator.SetTrigger("attack"); } if (Input.GetKeyDown(KeyCode.Keypad5) && !Die) { MyAnimator.SetTrigger("shoot"); } }
public void Move() { if (rightEdge == null) { MyAnimator.SetFloat("speed", 1); transform.Translate(GetDirection() * (maxSpeed * Time.deltaTime)); } else if ((GetDirection().x > 0 && transform.position.x < rightEdge.position.x) || (GetDirection().x < 0 && transform.position.x > leftEdge.position.x)) { MyAnimator.SetFloat("speed", 1); transform.Translate(GetDirection() * (maxSpeed * Time.deltaTime)); } else if (currentState is PatrolState) { ChangeDirection(); } }
public void Move() { if (!Attack) { if (transform.right.x > 0 && transform.position.x < rightEdge.position.x || transform.right.x < 0 && transform.position.x > leftEdge.position.x) //if (GetDirection().x > 0 && transform.position.x < rightEdge.position.x || GetDirection().x < 0 && transform.position.x > leftEdge.position.x) { MyAnimator.SetFloat("speed", 1); transform.Translate(transform.right * movementSpeed * Time.deltaTime); //transform.Translate(GetDirection() * (movementSpeed * Time.deltaTime)); } else if (currentState is PatrolState) { ChangeDirection(); } } }
protected virtual void Move() // 몬스터 이동 { if (MyAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Walk")) // 이동 { if (transform.localScale.x >= 1) // 오른쪽 보고있을때 { transform.Translate(transform.right * MonsterSpeed * Time.deltaTime, Space.World); } else // 왼쪽 보고있을때 { transform.Translate(-transform.right * MonsterSpeed * Time.deltaTime, Space.World); } } if (MyAnimator.GetCurrentAnimatorStateInfo(0).IsTag("NoMove")) { transform.Translate(Vector2.zero, Space.World); } }
private void handleImput() { if (Input.GetKeyDown(KeyCode.E)) { if (IsGrounded()) { MyAnimator.SetTrigger("attack"); } } if (Input.GetKeyDown(KeyCode.LeftControl)) { MyAnimator.SetTrigger("slide"); } if (Input.GetKeyDown(KeyCode.Space) && !IsFalling) { onAir = true; MyAnimator.SetTrigger("jump"); } }
private void HandleInput() { if (Input.GetKeyDown(KeyCode.LeftShift)) { MyAnimator.SetTrigger("attack"); } if (Input.GetKeyDown(KeyCode.S)) { MyAnimator.SetTrigger("slide"); } if (Input.GetKeyDown(KeyCode.Space)) { MyAnimator.SetTrigger("jump"); } if (Input.GetKeyDown(KeyCode.F)) { MyAnimator.SetTrigger("throw"); } }
public void Move() { MyAnimator.SetFloat("speed", 1); transform.Translate(GetDirection() * (movementSpeed * Time.deltaTime)); if (facingRight) { Vector3 scale = transform.localScale; scale.x = 1; transform.localScale = scale; } if (!facingRight) { Vector3 scale = transform.localScale; scale.x = -1; transform.localScale = scale; } }
private void HandleInput() // Verifica apasarea unor taste care activeaza triggere care activeaza aniamatii -> altceva { if (Input.GetKeyDown(KeyCode.X)) { MyAnimator.SetTrigger("attack"); } if (Input.GetKeyDown(KeyCode.Z)) { MyAnimator.SetTrigger("throw"); } if (Input.GetKeyDown(KeyCode.UpArrow)) { MyAnimator.SetTrigger("jump"); } if (Input.GetKeyDown(KeyCode.DownArrow) && OnGround) { MyAnimator.SetTrigger("slide"); } }
public override IEnumerator TakeDamage() { if (!healthCanvas.isActiveAndEnabled) { healthCanvas.enabled = true; } healthStat.CurrentValue -= 10; if (!IsDead) { MyAnimator.SetTrigger("damage"); } else { MyAnimator.SetTrigger("die"); yield return(null); } }