- Home /
Question by
alexc847 · Dec 14, 2020 at 07:17 PM ·
animationmovementcollision detectiontriggers
Enemy not going up during attack animation
so i've got a very basic game, in which I have a basic enemy and player sprite. The problem is that even though the attack animation makes the "graphics" compnent of it go up in relation to the parent, it doesn't do so. Everything else works though.
Heres the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
{
private GameObject wayPoint;
private Vector3 wayPointPos;
public float speed;
Animator anim;
bool CanMove;
void Start()
{
wayPoint = GameObject.Find("wayPoint");
anim = gameObject.GetComponent<Animator>();
anim.ResetTrigger("Attack");
CanMove = true;
}
void FixedUpdate()
{
if (CanMove)
{
wayPointPos = new Vector3(wayPoint.transform.position.x, transform.position.y, wayPoint.transform.position.z);
transform.position = Vector3.MoveTowards(transform.position, wayPointPos, speed * Time.deltaTime);
transform.LookAt(wayPointPos);
}
}
void OnTriggerEnter(Collider other)
{
if (CanMove)
{
Debug.Log("Attack");
anim.SetTrigger("Attack");
StartCoroutine(Attack());
}
}
IEnumerator Attack()
{
CanMove = false;
anim.SetTrigger("Attack");
yield return new WaitForSeconds(1);
CanMove = true;
anim.ResetTrigger("Attack");
}
}
I have a box collider, rigidbody, and a trigger box collider.
Thanks in advance!
Comment
Answer by MrSpecjal · Dec 30, 2020 at 09:54 AM
Check collider type. If you're working with sprites, I assume you are using 2d collider. If that is true, change on trigger enter method
void OnTriggerEnter2D(Collider2D other)
oh sorry, i didn't mean sprite. Just a habit moving from pygame. It is a 3d game. I have found a way to go around this problem, but I would still like the answer