Well, you might not want to hear that but you definitely should learn programming in general first. Buy a book about C# and learn the basic principles first!
Note: You shouldn’t use an array if you don’t really need to. A List might be better for your task.
Could you pls just anwser my question i need this and not a list i know alot im pretty good at programming i just dont know this little bit how can i add things to arrays. I know how to edit them but not how to add stuff to them.
Nvm i found the anwser once i knew it was called an array in english… I thought you could use a ArrayName.Add but apperently that only works for lists. Anyway you can just do +[obj] and it’ll add one, but you cant change the size of the array so i will have to switch over to lists which will be a pain in the ass since a ton of my code is based on that variable being an array… haha
Gameobjects cannot hold gameobjects. Gameobjects can have components plugged into them (such as scripts).
You can parent one game object’s transform to another game object’s transform. This is appropriate if there is a scene graph dependency hierarchy between the components. In the editor this is accomplished by parenting. In code this is accomplished by setting the transform.parent to the other object’s transform.
You can write a script ( a component) that contains some type of either array, list or other sequence container that contains references to game objects. In the editor this is done by exposing the list as public and dragging the desired “things” into it, which could be GameObjects or any other Component. In code you would simply use whatever was appropriate to add a reference to the item to your list/array.
Yeah, you cannot ‘add’ to a GameObject[ ] array, only change the items already in the array, change to List, or:
You could write a method that outwardly looks like an Add method, which creates a new, bigger GameObject[ ] array, copies the old array into the new array (system.array.copyTo), and puts the gameobject in the last position
Yupp switched to list i thought i had to change a ton of code but apperantly i only need to change .Length into .Count. Everything else is exactly the same it even kept all the script and variables that were in the array. I never used list but they are so much easier then arrays i will definitely use them more often now.
Oke so i cant get it to work this my script that creates the list:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ItemManager : MonoBehaviour
{
public List <ItemCollector> Items;
void Start(){
}
void Awake()
{
//Debug.Log("Setting All Items");
}
}
and this is the itemcollector script
using UnityEngine;
using System.Collections;
public enum ItemType
{
Weapon = 0,
Edible = 1,
Misc = 2,
}
public enum WeaponType
{
Melee = 0,
Ranged = 1,
}
[System.Serializable]
public class ItemCollector
{
public Texture2D Icon;
public string Name = "Item Name";
public string Description = "Description";
public int Price;
public ItemType ItemType;
public GameObject ItemPrefab;
public GameObject ItemPrefabDrop;
}
public enum ItemRenderMode{
Player,
Sell,
Buy
}
now how can i add one to this list it just wont work idk why.
Just to be sure, Are you declaring your list at the top inside of your class and adding your item inside of your Start()? Also, what error is it giving you?
i didnt need list but an array then someone told me an array was impossible so now i have to use a list. And it is easy to use never said lists werent easy. Hahaha looked at myself very very criticly and i came to the conclusion that you are a ******. But dont worry these forums are fluded with people like you infact every forum is. I got used to it. Oh let me re phrase that i know enough about programming to have fun with it when i want to make the games i want and if that fact that i never used a list because i didnt know they existed makes me not know alot about it in your opinion than good for you i hope you are now happy… Because i certainly am ;D
But thanks again DChristy87 for the helpful anwser.