public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { base.OnStateEnter(animator, stateInfo, layerIndex); enemyS = animator.gameObject.GetComponent <AnimEnemy>(); enemyS.ChangeToPatrolling(); animator.SetInteger("AnimState", 1); }
protected void Awake() { AudioManager audioManager = AudioManager.Instance(); popSound = audioManager.GetAudioSource("PopSound"); gameManager = GameManager.Instance(); doneSpawning = false; //animator = GetComponentIn<Animator>(); collider = GetComponent <Collider>(); rigidbody = GetComponent <Rigidbody>(); if (!gameManager) { Debug.LogError("no gameManager found!"); } rigidbody.useGravity = false; transform.localScale = new Vector3(radius * 2, radius * 2, radius * 2); animEnemy = GetComponentInChildren <AnimEnemy>(); if (!animEnemy) { Debug.LogError("anim enemy not found!"); } }
public void MoedaFound() { if (!TauntVisto) { Taunt1.Play(); TauntVisto = true; } GetComponent <scrRotation>().enabled = false; GetComponent <scrPatrulha>().enabled = false; Transform[] positions = GetComponent <scrPatrulha>().posições; int Local = GetComponent <scrPatrulha>().Local; Rigidbody2D rbEnemy = GetComponent <Rigidbody2D>(); if (Moeda != null) { MoedaPos = Moeda.transform; PosFut = MoedaPos.position; } else { MoedaPos = transform; } if (!Already) { PosFut.z = 5f; PosFut.x -= transform.position.x; PosFut.y -= transform.position.y; float angle = Mathf.Atan2(PosFut.y, PosFut.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, angle)); } if (Vector2.Distance(transform.position, MoedaPos.position) < 0.5 || Moeda == null) { Already = true; if (Vector2.Distance(transform.position, MoedaPos.position) > 0.5 || Moeda != null && !Rotacionando) { Already = false; } if (Tempo <= 0) { Rotacionando = true; Vector3 PosFutLocal = positions[Local].position; PosFutLocal.z = 5f; PosFutLocal.x -= transform.position.x; PosFutLocal.y -= transform.position.y; float angleLocal = Mathf.Atan2(PosFutLocal.y, PosFutLocal.x) * Mathf.Rad2Deg; GetComponent <scrRotation>().Rotação(angleLocal); rotationIF = float.Parse(rbEnemy.rotation.ToString("N2")); anguloIF = float.Parse(angleLocal.ToString("N2")); if (anguloIF == rotationIF) { if (Moeda != null) { Destroy(Moeda); TauntVisto = false; } MoedaVista = false; Already = false; Rotacionando = false; GetComponent <scrRotation>().enabled = true; GetComponent <scrRotation>().lerp = 0f; GetComponent <scrPatrulha>().enabled = true; } } else { Tempo -= Time.deltaTime; } } else { transform.position = Vector2.MoveTowards(transform.position, MoedaPos.position, 2 * Time.deltaTime); if (Vector2.Distance(transform.position, MoedaPos.position) < 1) { Animator AnimEnemy; AnimEnemy = GetComponent <Animator>(); AnimEnemy.SetBool("Andando", false); } else { Animator AnimEnemy; AnimEnemy = GetComponent <Animator>(); AnimEnemy.SetBool("Andando", true); Tempo = TempoMoedaVista; } } }