❔ Help with a unity Inventory
im making an Inventory for my unity game and im getting this CS1061 error, i Know what the error is, but i can´t find whats wrong, if someone could help me, i can screenshot the unity or send the code, thanks
11 Replies
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class InventoryController : MonoBehaviour
{
public Objects[] slots;
public Image[] slotImage;
public int[] slotAmount;
void Start()
{
} void Update() { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width/ 2, Screen.height / 2)); if(Physics.Raycast(ray, out hit, 5f)) { if(hit.collider.tag == "Object") { if(Input.GetKeyDown(KeyCode.E)) { for(int i = 0; i < slots.Lenght; i++) { if (slots[i] == null || slots[i].name == hit.transform.GetComponent<ObjectType>().objectType.name) { slots[i] = hit.transform.GetComponent<ObjectType>().objectType; slotAmount[i]++; slotImage[i].sprite = slots[i].itemSprite; Destroy(hit.transform.gameObject); break; } } } } } } } Assets\Inventory\InventoryController.cs(29,46): error CS1061: 'Objects[]' does not contain a definition for 'Lenght' and no accessible extension method 'Lenght' accepting a first argument of type 'Objects[]' could be found (are you missing a using directive or an assembly reference?)
} void Update() { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width/ 2, Screen.height / 2)); if(Physics.Raycast(ray, out hit, 5f)) { if(hit.collider.tag == "Object") { if(Input.GetKeyDown(KeyCode.E)) { for(int i = 0; i < slots.Lenght; i++) { if (slots[i] == null || slots[i].name == hit.transform.GetComponent<ObjectType>().objectType.name) { slots[i] = hit.transform.GetComponent<ObjectType>().objectType; slotAmount[i]++; slotImage[i].sprite = slots[i].itemSprite; Destroy(hit.transform.gameObject); break; } } } } } } } Assets\Inventory\InventoryController.cs(29,46): error CS1061: 'Objects[]' does not contain a definition for 'Lenght' and no accessible extension method 'Lenght' accepting a first argument of type 'Objects[]' could be found (are you missing a using directive or an assembly reference?)
@ju_siolive Length, not Lenght.
Sorry i dont get it
The message explicitly states "Objects[]' does not contain a definition for 'Lenght' "
You're trying to call a property
Lenght
. That's not how you write that word.
In your IDE, you should have a big squiggly red line under that word too.i sware im trynna to understand, is Lenght wrong ? how do i write that then
they literally told you
im using vscode but its not showing me the error
CTRL-F the word spelt wrong, then replace it.
Sorry for the bothering guys, it didnt work, im probly doing it wrong but thanks anyway for the help
oh it worked thanks guys
Great
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.