这是第一个 Unity 开放项目的repo,是 Unity 和社区合作创建的一个小型开源游戏演示,第一款游戏是一款名为 Chop Chop 的动作冒险游戏。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

43 行
1.2 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MovingCritterAttackController : MonoBehaviour
{
// Reference of the player transform to compute the propel target position
[SerializeField]
private TransformAnchor _playerTransform;
// Propel factor is the proportion of the distance between the critter and the player crossed by the critter during the propel animation
[SerializeField]
private float _propelFactor = 1.0f;
// Duration of the propel section of the animation.
[SerializeField]
private float _propelDuration = 0.2f;
private float _innerTime = 0.0f;
private Vector3 _propelTargetVector = default;
// When the attack starts, the position targeted by the attack is determined and is not changed afterward
public void SetAttackTarget()
{
_propelTargetVector = (_playerTransform.Transform.position - transform.position) * _propelFactor / _propelDuration;
}
// Trigger the propel movement during the attack
public void AttackPropelTrigger()
{
_innerTime = _propelDuration;
}
// Update is called once per frame
void Update()
{
if (_innerTime > 0)
{
transform.position += _propelTargetVector * Time.deltaTime;
_innerTime -= Time.deltaTime;
}
}
}