提问人:Алексей Фёдоров 提问时间:11/8/2023 更新时间:11/8/2023 访问量:27
我怎样才能停止太空中的物体?
How can i stop object in space?
问:
Unity,如何停止我的对象?
我是Unity的新手,但我已经在制作一个小游戏了。问题的本质如下: 我有一枚火箭飞向目标,在某些空间间隔内,我需要停止火箭,以便以文本形式显示其他参数 如何以及在何处将代码插入到我的脚本中,或者最好强加一个新代码 更详细地解释,我将不胜感激!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class missileparticles : MonoBehaviour
{
private Transform target;
public enum Missile_state
{
idle,
start,
fly,
end
}
public Missile_state missile_state_t;
float timer = 0;
public float speed_move;
public float speed_rotate;
Vector3 start_pos;
public Transform GetTarget()
{
return target;
}
public void SetTarget(Transform value)
{
target = value;
}
void Start()
{
SetTarget(GameObject.FindGameObjectWithTag("Target").transform);
start_pos = gameObject.transform.position;
}
void Update()
{
switch (missile_state_t)
{
case Missile_state.idle:
if (timer <= 5) { timer += Time.deltaTime; }
if (timer > 5)
{
missile_state_t = Missile_state.start;
}
break;
case Missile_state.start:
float start_dist = Vector3.Distance(gameObject.transform.position, start_pos);
gameObject.transform.Translate(Vector3.back * speed_move * Time.deltaTime);
if (start_dist >= 20)
{
missile_state_t = Missile_state.fly;
}
break;
case Missile_state.fly:
gameObject.transform.Translate(Vector3.up * speed_move * Time.deltaTime);
Vector3 target_vector = GetTarget().transform.position - gameObject.transform.position;
gameObject.transform.up = Vector3.Slerp(gameObject.transform.up, target_vector, speed_rotate * Time.deltaTime);
if (target_vector.magnitude < 1)
{
missile_state_t = Missile_state.end;
}
break;
case Missile_state.end:
break;
}
}
}
答: 暂无答案
评论
speed_move = 0;
speed_move
FlightPaused
Missile_state.paused