我正在处理一个新项目,其中我的核心机制之一是一个钩子,如果一个物体被击中,它们要么被拉动要么被摧毁。
现在我只是想让这个运动机制工作,这是我的代码:
public class Hook : MonoBehaviour
{ //Remember Couroutine is pretty much update()
public Transform Target;
private float Thrust; // Int for motion
public Rigidbody rb;
public float HookTravelTime = 5f; //Define float for seconds
private bool moving = false; //Are we currently moving?
public int time;
// Use this for initialization
void Start()
{
Thrust = 75f;
rb = GetComponent<Rigidbody>();
print("working");
}
void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == "enemy")
{
print("xd");
Destroy(col.gameObject);
}
}
void ThrowHook()
{
if (Input.GetKeyDown(KeyCode.H) && !moving)
{
moving = true;
var moveIncrement = new Vector3(Thrust, 0, 0 * Time.deltaTime); // setting values? difference between var and int?
while (time <= HookTravelTime)
{
time = Time.deltaTime + 1;// I want the int time to increase by 1 every "second". Cannot impicitly convert type float to iny. An explicit conversion exists.???
// How do I put VAR MOVEINCREMENT into here? I still don't understand what a var is. Why can't I just make a void()
}
if (time >= HookTravelTime)
{
transform.position = Vector3.MoveTowards(transform.position, Target.position, Thrust); // return to empty object which is in front of player.
}
}
}
// Update is called once per frame
void Update()
{
ThrowHook();
}
}
这些问题是我在代码中注释的,但我将通过它们。
在 Void ThrowHook() 中,我试图将游戏中每一秒的 Int(time) 减少到 +1。我试图将其与 Time.Delta Time 同步,但这不起作用。我不知道我在这里做什么。
在 ThrowHook() 中的 while 循环上方,有人告诉我创建一个 var 来在其中存储信息(Var MoveIncrement)。我试图将恒定运动代码放入其中,但我不知道如何调用它。如果可能的话,你能告诉我这行代码是否错误
请暂时忽略 Bool Moving,因为我一直没有始终如一地试图解决这个问题。
希望我已经把这些问题说清楚了,如果没有,我很抱歉,我急于去橄榄球练习。
TLDR:我想要一个钩子在“时间”还没有超过 5 秒的时候有一个恒定的力量向前。如果有,则钩子移回玩家面前的目标位置。
呼如林
ITMISS
随时随地看视频慕课网APP
相关分类