Newer
Older
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ArrowSpawner : StateMachineBehaviour
{
[SerializeField] GameObject arrowPrefab;
GameObject arrow;
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (stateInfo.IsName("shoot"))
{
int directionArrow = 1;
if (animator.gameObject.transform.localScale.x < 0f)
{
directionArrow = -1;
}
Vector2 spawnPos = animator.gameObject.transform.position;
Debug.Log("Bevor:" + spawnPos.ToString());
spawnPos += new Vector2(1 * directionArrow, 0);
Debug.Log("After:" + spawnPos.ToString());
arrow = Instantiate(arrowPrefab,spawnPos,Quaternion.identity);
ChangeArrowDirection(arrow,directionArrow);
void ChangeArrowDirection(GameObject arrow, int directionArrow)
{
arrow.transform.Rotate(0, 0, 90 * directionArrow);
}