if(Input.GetKeyDown(KeyCode.F)){
StartCourotine(“AddApple”);
}
IEnumerator AddApple() {
yield return new WaitForSeconds(7);
inventory.AddItem(InventoryManager.DeepCopy(item));
}
What am i Doing wrong ;-;
The IEnumerator is underlined red.
Assets/ApplePick.cs(34,21): error CS1525: Unexpected symbol (', expecting )‘, ,', ;’, [', or =’
I basically want a 7 second delay before this happens inventory.AddItem(InventoryManager.DeepCopy(item));
3 Answers
3
I don’t know if this is a code fragment or if this is your real code. ‘StartCoroutine’ is still misspelled. Your code should be something like:
void Update() {
if(Input.GetKeyDown(KeyCode.F)){
StartCoroutine(AddApple());
}
}
IEnumerator AddApple() {
yield return new WaitForSeconds(7.0f);
inventory.AddItem(InventoryManager.DeepCopy(item));
}
StartCoroutine(nameof(“AddApple”));
You can also give parameters to IEnumerator
if(Input.GetKeyDown(KeyCode.F)){
StartCourotine(AddItem(item));
}
IEnumerator AddItem(var item) {
yield return new WaitForSeconds(7);
inventory.AddItem(InventoryManager.DeepCopy(item));
}
How is it not working? In the code snippet here you've misspelled 'StartCoroutine()', but that would generate a compile time error. If this is not your problem, please edit your question to include more of your script and add more description on how it is not working.
– robertbuUpdated it.
– colorcraft