Question by
Alex-Koba_Ownused · Jul 06, 2018 at 07:31 AM ·
scripting problemerrorcoroutinetagforeach
Foreach in coroutine (Really need a reply!)
The Newbies Fail: Chapter One
I'm kinda noob in scripting so i have this problem: Ok, I want to deselect (play function Deselected) on script of a found object with tag "Forest Union" but i have cought this error:
`PlayerControls.GetEnumerator()' must have a body because it is not marked abstract, extern, or partial
And I realy don't know what to do, i was looking for information on many forums, but no result! Please help! Here's my script:
using UnityEngine;
using System.Collections;
public class PlayerControls : MonoBehaviour {
[SerializeField]
private LayerMask clickablesLayer;
public Camera raycaster;
public GameObject[] yourUnits;
private GameObject unit;
private IEnumerator coroutine;
[SerializeField]
private string factionTag;
void Update () {
if (Input.GetButtonDown("LeftMouse"))
{
StartCoroutine("DeselectAll");
RaycastHit rayHit;
if (Physics.Raycast(raycaster.ScreenPointToRay(Input.mousePosition), out rayHit, Mathf.Infinity, clickablesLayer))
{
if (rayHit.collider.GetComponent<UnitStats>().FactionForestUnion)
{
rayHit.collider.GetComponent<UnitControls>().Clicked();
}
}
}
}
IEnumerator DeselectAll()
{
yield return new WaitForSeconds(0.0f);
GameObject yourUnits = GameObject.FindGameObjectWithTag (factionTag);
foreach (GameObject unit in yourUnits)
{
unity.GetComponent<UnitControls>().Deselected();
}
}
}
Really hope someone would help me, I need reply very fast and soon!
Comment
Answer by savante_2 · Apr 24, 2019 at 09:22 AM
A little late but:
IEnumerator DeselectAll(){
GameObject yourUnits = GameObject.FindGameObjectWithTag (factionTag);
foreach (GameObject unit in yourUnits)
{
unity.GetComponent<UnitControls>().Deselected();
yield return new WaitForSeconds(0.0f);
}
}