我有个小问题。我想在一段时间内增加Light.spotAngle属性。编写的代码可以工作,但我希望这个速度的提高,或类似的东西。我想以一定的速度增加聚光角的值,而不是直接增加到100,而是从30慢慢增加到10到100。
Transform thisLight = lightOB.transform.GetChild(0);
Light spotA = thisLight.GetComponent<Light>();
spotA.spotAngle = 100f;我尝试使用Time.DeltaTime,但不起作用。救命!
发布于 2018-02-01 20:32:33
使用Mathf.Lerp从值a到b进行lerp。根据您的问题,a值为10,b值为100。在协程函数中这样做。这让你可以控制你希望缓慢的愤怒发生多长时间。当您单击一个对象时,启动协程函数。
协程函数:
IEnumerator increaseSpotAngle(Light lightToFade, float a, float b, float duration)
{
float counter = 0f;
while (counter < duration)
{
counter += Time.deltaTime;
lightToFade.spotAngle = Mathf.Lerp(a, b, counter / duration);
yield return null;
}
}将在5秒内将光的SpotAngle从10更改为100。
public Light targetLight;
void Start()
{
StartCoroutine(increaseSpotAngle(targetLight, 30, 100, 5));
}有关如何检测点击任何GameObject的信息,请参阅this post。
https://stackoverflow.com/questions/48562115
复制相似问题