问题描述
是否有办法通过更改此代码中Vector3的y值使其下降?
我想创建一个带有y坐标7和x坐标的对象并随机下落,但是我想指定下落速度 使用刚性2D时,它会下降,但只会以恒定速度下降,因此我想使用变量而不是恒定速度来降低速度。
this.delta += Time.deltaTime;
if (this.delta > this.span)
{
//arrowController.speed = -0.000f;
this.delta = 0;
GameObject go = Instantiate(arrowPrefeb) as GameObject;
int px = Random.Range(-9,9);
go.transform.position = new Vector3(px,7,0);
if (span >= 0.1f)
{
this.span *= 0.9f;
this.round.GetComponent<Text>().text = "점점 빨라지는 중!";
}
else
{
span = 0.09f;
this.round.GetComponent<Text>().text = "피해 보아요!";
}
}
}```
解决方法
您可以介绍一个字段
public float FallSpeed = 0;
(您可以在开始游戏之前在检查器中更改此值)
然后在同一脚本的更新循环中。...
void Update()
{
this.transform.position += new Vector3(0f,FallSpeed,0f);
}