C
C#2y ago
ju_siolive

❔ 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
ju_siolive
ju_sioliveOP2y ago
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?)
Yawnder
Yawnder2y ago
@ju_siolive Length, not Lenght.
ju_siolive
ju_sioliveOP2y ago
Sorry i dont get it
Yawnder
Yawnder2y ago
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.
ju_siolive
ju_sioliveOP2y ago
i sware im trynna to understand, is Lenght wrong ? how do i write that then
Saber
Saber2y ago
they literally told you
ju_siolive
ju_sioliveOP2y ago
im using vscode but its not showing me the error
Yawnder
Yawnder2y ago
CTRL-F the word spelt wrong, then replace it.
ju_siolive
ju_sioliveOP2y ago
Sorry for the bothering guys, it didnt work, im probly doing it wrong but thanks anyway for the help oh it worked thanks guys
Yawnder
Yawnder2y ago
Great
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server