- Home /
Question by
Theacesofspades · Oct 18, 2014 at 06:37 PM ·
c#listadditem
Add item to string by name?
I have:
public Class Item
{
public string name = "Stick";
}
public List<Item> items = new List<Item>();
void Start ()
{
if (Physics.Raycast(transform.position, Vector3.down, out hit, 10))
{
items.Add(hit.collider.name);
}
}
I am trying to add an item with the same name as the hit.collider. Not the collider but an item that has already been created with the same name. How could I go about doing this? Thanks
Comment
Best Answer
Answer by Theacesofspades · Oct 18, 2014 at 08:24 PM
I figured it out myself. I had to put:
foreach (Item item in items)
{
if (item.name == hit.collider.name)
{
AddItem(items[item.id]);
}
}
Your answer
Follow this Question
Related Questions
How to make a deep copy instead of a shallow one? 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
[C#] Programm does not add to list 1 Answer
A node in a childnode? 1 Answer