0
我有一个问题,当我写这个播放声音时,播放器距离4单位米的距离并按下“e”,但它给了我一个错误,hit
无法转换为float
。我现在应该怎么做?Raycast命中错误
public AudioSource sound;
public int rayLength = 4;
public GameObject doorText;
RaycastHit hit;
void Update()
{
var fwd = transform.TransformDirection(Vector3.forward);
if (Physics.Raycast(transform.position, fwd, hit, rayLength))
{
if (hit.collider.gameObject.tag == "Boxen")
{
doorText.gameObject.SetActive(true);
if (Input.GetKeyDown("e")) //or Input.GetKeyDown("e") Input.GetButtonDown("Fire1")
{
sound.Play();
}
}
}
else
{
doorText.gameObject.SetActive(false);
}
}