为什么用相同的脚本,挂载在正方体上时就可以控制它的旋转,但是挂载在P1上就旋转不了呢,P1是一个空的Object,但是脚本挂载在手臂里面的某个齿轮上可以控制旋转,但是旋转的时候方向好像控制不了,一直在抖,出现了四五个轴。
下面的是控制旋转的脚本,希望有人能帮我看看,十分感谢。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.UI;
using TMPro;
public class cs : MonoBehaviour
{
public InputField inputFieldcs;
public GameObject zfx;
private static float a = 0.0f;
private float timer = 0;
private float waitTime = 0.0f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update() //1秒30帧,那增量时间(Time.deltaTime)就是 1/30 秒,1秒60帧,那增量时间就是 1/60 秒,1秒166帧,那增量时间就是 1/166 秒
{
waitTime = a / 10;
if (timer < waitTime)
{
timer += Time.deltaTime;
print(timer);
transform.localEulerAngles += new Vector3(0, 10 * Time.deltaTime, 0);
}
}
public void InputFieldEditEnd(string EndValue)
{
if (EndValue == "")
{
EndValue = "0";
timer = 0.0f;
}
else
{
a = float.Parse(EndValue);
timer = 0.0f;
}
}
}
而且这个输入代码好像只要第一次输入时可以控制旋转,后面就输入就控制不了了。