【发布时间】:2021-01-25 16:00:40
【问题描述】:
我实际上是在尝试创建一个游戏,其中玩家默认设置为空闲动画,因此当钩子抓住宝石时触发时绳子包裹动画开始,但我似乎无法停止绳子包裹动画并回到空闲状态。钩子也能抓到一件以上的东西,有人能帮我吗?这是动画的视觉插图
Rope Wrap - The player starts winching in the jewel
Hook 脚本的代码如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HookScripts : MonoBehaviour {
[SerializeField]
private Transform itemHolder;
private bool itemAttached;
private HookMovement hookMovement;
private PlayerAnimation playerAnim;
void Awake() {
hookMovement = GetComponentInParent<HookMovement>();
playerAnim = GetComponentInParent<PlayerAnimation>();
}
void OnTriggerEnter2D(Collider2D target) {
if (target.tag == Tags.PINK_GEM || target.tag == Tags.GREEN_GEM || target.tag == Tags.BLUE_GEM
|| target.tag == Tags.ORANGE_GEM || target.tag == Tags.PURPLE_GEM
|| target.tag == Tags.LIGHT_BLUE_GEM || target.tag == Tags.PINK_GEM_SMALL
|| target.tag == Tags.LARGE_STONE || target.tag == Tags.SMALL_STONE){
itemAttached = true;
target.transform.parent = itemHolder;
target.transform.position = itemHolder.position;
// Set the position of the hook to the position of the item
hookMovement.move_Speed = target.GetComponent<ItemScripts>().hook_Speed;
hookMovement.HookAttachedItem();
//animate player
playerAnim.PullingItemAnimation();
if (target.tag == Tags.PINK_GEM || target.tag == Tags.GREEN_GEM || target.tag == Tags.BLUE_GEM
|| target.tag == Tags.ORANGE_GEM || target.tag == Tags.PURPLE_GEM
|| target.tag == Tags.LIGHT_BLUE_GEM || target.tag == Tags.PINK_GEM_SMALL)
{
SoundManager.instance.HookGrab_Jewel();
}
else if (target.tag == Tags.LARGE_STONE || target.tag == Tags.SMALL_STONE){
SoundManager.instance.HookGrab_Stone();
}
SoundManager.instance.WinchCrank(true);
} // If the target is an item
if (target.tag == Tags.DELIVER_ITEM){
if(itemAttached){
itemAttached = false;
Transform objChild = itemHolder.GetChild(0);
objChild.parent = null;
objChild.gameObject.SetActive(false);
playerAnim.IdleAnimation();
SoundManager.instance.WinchCrank(false);
}
}// Remove items after winching
}// On trigger enter
}
这是播放器动画脚本的代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerAnimation : MonoBehaviour
{
private Animator anim;
void Awake()
{
anim = GetComponent<Animator>();
}
public void IdleAnimation()
{
anim.SetTrigger("Idle");
}
public void PullingItemAnimation()
{
anim.SetTrigger("ropeWrap");
}
}
【问题讨论】:
标签: c# unity3d game-physics 2d-games