仅当NPC对准动画时,才能启用拍摄功能?

时间:2019-04-20 05:25:14

标签: c# unity3d

我有一个动画师。首先,NPC开始行走,然后他慢慢停下来瞄准。然后使用脚本,当我单击鼠标左键时它将拍摄。这是“动画师”中的最后一个拍摄状态。 在步行状态和瞄准状态之间,我添加了一个参数,并在过渡过程中将其设置为true:

Animator

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Shooting : MonoBehaviour
{
    [SerializeField]
    private Transform[] firePoints;
    [SerializeField]
    private Rigidbody projectilePrefab;
    [SerializeField]
    private float launchForce = 700f;
    [SerializeField]
    private Animator anim;
    [SerializeField]
    private bool automaticFire = false;
    [SerializeField]
    private bool slowDownEffect = false;

    private void Start()
    {
        anim.SetBool("Shooting", true);
    }

    public void Update()
    {
        if (Input.GetButtonDown("Fire1") && automaticFire == false)
        {
            if (anim.GetBool("Shooting") == true)
            {
                anim.Play("SHOOTING");
                LaunchProjectile();
            }
        }
        else
        {
            if (automaticFire == true)
            {
                anim.Play("SHOOTING");
                LaunchProjectile();
            }
        }
    }

    private void LaunchProjectile()
    {
        foreach (var firePoint in firePoints)
        {
            Rigidbody projectileInstance = Instantiate(
                projectilePrefab,
                firePoint.position,
                firePoint.rotation);

            projectileInstance.AddForce(new Vector3(0, 0, 1) * launchForce);

            projectileInstance.gameObject.AddComponent<BulletDestruction>().Init();
        }
    }
}

问题是当我运行游戏时,如果我单击鼠标左键“ Fire1”,它将立即从步行动画跳转/更改为拍摄动画并开始拍摄。

我希望NPC首先行走,然后在他完成对目标的更改后才变为目标,然后才能够拍摄“ Fire1”。

如果npc仍在行走或正在转换为瞄准,则不允许射击。 仅当npc处于瞄准动画中时,才启用射击。

1 个答案:

答案 0 :(得分:0)

library(tidyverse)
library(relayer) # https://github.com/clauswilke/relayer

ex <- df %>% 
  mutate(r0 = cutoff_values[-length(cutoff_values)],
         r = cutoff_values[-1]) %>% 
  mutate(x0 = 100, 
         y0 = 50)

ggplot(ex, aes(x0 = x0, y0 = y0, r0 = r0, r = r)) +
  ggforce::geom_arc_bar(aes(start = 0, end = 2 * pi, fill = value),
                        colour = NA) +
  ggforce::geom_arc_bar(data = ex[ex$bucket_id == 15,], # Whatever bucket you want
                        aes(start = 0, end = 2 * pi, fill2 = as.factor(bucket_id))) %>% 
  rename_geom_aes(new_aes = c("fill" = "fill2")) +
  scale_fill_manual(aesthetics = "fill2", values = "red", guide = "legend") +
  theme_void() +
  labs(fill = 'colour', fill2 = "highlight")

我添加了isAnimationStatePlaying方法,并在Update中使用了它,现在效果很好。