JavaScript - Error en C# Script Unity3D

 
Vista:
Imágen de perfil de José Antonio

Error en C# Script Unity3D

Publicado por José Antonio (1 intervención) el 14/05/2023 01:20:17
Buenas compañeros!

Me ha surgido un error de compilación en un Script que he creado para Unity 3D. He declarado como variables unas arrays y las recorro con un 'for'. Me falla en la línea 'this.createdDecals.Lenght'. Me da el siguiente error de compilación:

error CS1061: 'GameObject[]' does not contain a definition for 'Lenght' and no accessible extension method 'Lenght' accepting a first argument of type 'GameObject[]' could be found (are you missing a using directive or an assembly reference?)

¿Dónde puede estar el error?¿Cómo lo soluciono?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
public class Shooter : MonoBehaviour
{
    private Ray rayo;
    private RaycastHit hit;
    public float distanciaDisparo;
    private Camera camara;
    private Vector2 centroCamara;
 
 
    public GameObject[] decalsPrefabs; //Array de los Prefabs
    public GameObject[] createdDecals; //Array para crear los Decals
    public int decalIndex;
 
    public float tiempoDisparo;
    private float tiempoUltimoDisparo;
    private Quaternion rotDecal;
    private Vector3 posDecal;
    public LayerMask decalLayerMask;
 
    // Awake is called before the pay the game
    void Awake()
    {
        this.camara = gameObject.transform.GetChild(0).GetComponent<Camera>();
        this.centroCamara.x = Screen.width / 2;
        this.centroCamara.y = Screen.height / 2;
        this.tiempoUltimoDisparo = Time.time;
 
        for(int decalNum=0;decalNum<this.createdDecals.Lenght;decalNum++)
        {
            this.createdDecals[decalNum] = GameObject.Instantiate(this.decalsPrefabs[0], Vector3.zero, Quaternion.identity) as GameObject;
            this.createdDecals[decalNum].GetComponent<Renderer>().enabled = false;
        }
        this.decalIndex = 0;
    }
 
    // Update is called once per frame
    void Update()
    {
        if(Input.GetButtonDown("Fire1"))
        {
            if((Time.time-this.tiempoUltimoDisparo)>this.tiempoDisparo)
            {
                this.rayo = this.camara.ScreenPointToRay(this.centroCamara);
                this.tiempoUltimoDisparo = Time.time;
 
                if(Physics.Raycast(this.rayo,out this.hit,this.distanciaDisparo,this.decalLayerMask))
                {
                    this.rotDecal = Quaternion.FromToRotation(Vector3.forward, this.hit.normal);
                    this.posDecal = this.hit.point + this.hit.normal * 0.01f;
                    this.createdDecals[this.decalIndex].transform.position = this.posDecal;
                    this.createdDecals[this.decalIndex].transform.rotation = this.rotDecal;
                    this.createdDecals[this.decalIndex].GetComponent<Renderer>().enabled = true;
                    this.decalIndex++;
                    if(this.decalIndex>9)
                    {
                        this.decalIndex = 0;
                    }
                }
            }
        }
    }
}

¡¡Muchas gracias de antemano!!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Alejandro
Val: 1.448
Plata
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

Error en C# Script Unity3D

Publicado por Alejandro (532 intervenciones) el 15/05/2023 18:06:12
  • Alejandro se encuentra ahora conectado en el
  • chat de PHP
Este es el foro de Javascript, quizá en el de C Sharp tengas mayor oportunidad de obtener una respuesta.

Aun así por los mensajes de error y sin haber trabajado con Unity.
1 createdDecals no esta inicializado
2 se escribe lenght en lugar de Lenght

Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar