UnityAPI手册-2019.4官网版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Animator.GetBool
# [Animator](Animator.html).GetBool public bool **GetBool** (string **name**); public bool **GetBool** (int **id**); ## 参数 | name | 参数名称。 | | ------ | ------------ | | id | 参数 ID。 | ## 返回 **bool** 参数的值。 ## 描述 返回给定布尔参数的值。 返回动画控制器中 bool 参数的当前状态。使用参数的名称或 ID 搜索相应的参数。 ``` //Attach this script to a GameObject with an Animator component attached. //For this example, create parameters in the Animator and name them “Crouch” and “Jump” //Apply these parameters to your transitions between states //This script allows you to set a Boolean Animator parameter on and set another Boolean parameter to off if it is currently playing. Press the space key to do this. using UnityEngine; public class AnimatorGetBool : MonoBehaviour { //Fetch the Animator Animator m_Animator; // Use this to decide if the GameObject can jump or not bool m_Jump; void Start() { //This gets the Animator, which should be attached to the GameObject you are intending to animate. m_Animator = gameObject.GetComponent<Animator>(); // The GameObject cannot jump m_Jump = false; } void Update() { //Press the space bar to enable the "Jump" parameter in the Animator Controller if (Input.GetKey(KeyCode.Space)) { //Set the "Jump" parameter in the Animator Controller to true m_Animator.SetBool("Jump", true); //Check to see if the "Crouch" parameter is enabled if (m_Animator.GetBool("Crouch")) { //If the "Crouch" parameter is enabled, disable it as the Animation should no longer be crouching m_Animator.SetBool("Crouch", false); } } //Otherwise the "Jump" parameter should be false else m_Animator.SetBool("Jump", false); //Press the down arrow key to enable the "Crouch" parameter if (Input.GetKey(KeyCode.DownArrow)) m_Animator.SetBool("Crouch", true); else m_Animator.SetBool("Crouch", false); } } ```
da
2022年5月24日 00:02
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码