Hi, i need help with my script. I have this error: Type DoorScript' does not contain a definition for index’ and no extension method index' of type DoorScript’ could be found (are you missing a using directive or an assembly reference?). I don’t know how to fix it. I search this solution on google, but it doesn’t match any solutions for this. Here’s the script:
using UnityEngine;
using System.Collections;
public class interactScript : MonoBehaviour {
public float interactDistance = 5f;
public AudioClip keyPickup;
void Update ()
{
if(Input.GetKeyDown(KeyCode.Mouse0))
{
Ray ray = new Ray(transform.position, transform.forward);
RaycastHit hit;
if(Physics.Raycast(ray, out hit, interactDistance))
{
if(hit.collider.CompareTag("Door"))
{
DoorScript doorScript = hit.collider.transform.parent.GetComponent<DoorScript>();
if(doorScript == null) return;
if(doorScript.name == "hinge")
{
doorScript.ChangeDoorState();
return;
}
if(Inventory.keys[doorScript.index] == true)
{
doorScript.ChangeDoorState();
}
}
else if(hit.collider.CompareTag("Key"))
{
Inventory.keys[hit.collider.GetComponent<Key>().index] = true;
AudioSource.PlayClipAtPoint(keyPickup, hit.collider.transform.position);
Destroy(hit.collider.gameObject);
}
else if(hit.collider.CompareTag("NextLeveldoor"))
{
Application.LoadLevel(1);
}
}
}
}
}
Please help me with this error quickly!!!
That code still has the error that I fixed yesterday (see comment above). You need a second closing bracket after
– Bonfire-Boy("Enemy"). I just checked the fixed code, it compiles for me.Also worth noting that the error you're posting looks odd - it's saying "can't convert from X to X" when obviously no conversion would be needed as X=X. <p> It's possible that something's getting lost when you're copy-pasting the error message, due to the
– Bonfire-Boy<and>not getting rendered in html. You can use back-quotes or code blocks to get around this. </p>