【问题标题】:How to swing knife with C# unity script [closed]如何使用 C# 统一脚本挥刀 [关闭]
【发布时间】:2016-07-27 16:20:47
【问题描述】:

我有一个人形模型(玩家),它可以正确行走,并且他正被一个敌人跟踪。现在我想

1) 将“刀”添加到我的播放器

2) 当按下空格键时,玩家应该拿出刀

3)当鼠标左键点击时,它应该攻击敌人(如果刀在外面,否则没有攻击)

我完全不知道该怎么做,你能告诉我应该怎么做吗?有没有脚本可以用来做这个任务

谢谢

【问题讨论】:

  • 向我们展示您尝试过的代码,特别是问题所在。 Stack Overflow 不是一个教程网站。

标签: c# unity3d unityscript unity5


【解决方案1】:

我希望这可以帮助您!但请确保您将刀游戏对象附在玩家的手上,或者您可以使用 instantiate() 方法生成

public GameObject Knife;  //  knife 3d model

public bool isKnifeActive;  // bool to check knife is there in hand or not

void Start()
{
    Knife.SetActive (false);
}

// Update is called once per frame
void Update ()
{
    if (Input.GetKeyDown (KeyCode.Space))
    {
        Knife.SetActive = true;
        isKnifeActive = true;
        StartCoroutine ("Knifedisable");
    }

    if (Input.GetMouseButtonDown (0)) 
    {
        playerAttack ();
    }
}

public void playerAttack()
{
    if (isKnifeActive) 
    {
        //********** play your knife - player attacking animation here ***************//
    }
}

IEnumerator Knifedisable()
{
    yield return new WaitForSeconds (5);
    Knife.SetActive = false;
    isKnifeActive = false;
}

void OnTriggerEnter()
{
    //********* write your opponent health reducing code here *************//
}

触发动画并编写减少敌人生命值的逻辑方式,但对于触发事件,您必须将碰撞器和刚体附加到同一个游戏对象并确保您已检查 isTrigger 字段享受!

【讨论】:

  • 谢谢,从这里得到了一个想法……太棒了
猜你喜欢
  • 1970-01-01
  • 2021-09-13
  • 1970-01-01
  • 2011-08-27
  • 2016-04-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多