Hello,
I have been working on a script to make the arrow in my game disappear temporarily and then reappear.Here is the script I made:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ArrowDisappear : MonoBehaviour {
public GameObject Arrow;
public bool isLaunched = false;
// Use this for initialization
void Start ()
{
{
if (isLaunched == true)
{
{
StartCoroutine(ShowAndHide(Arrow,1.0f));//1 second
}
IEnumerator ShowAndHide(GameObject go, float delay)
{
go.SetActive(false);
yield return new WaitForSeconds(1);
go.SetActive(true);
}
isLaunched = false;
}
}
}
}
I am getting the following errors:
Assets/Assets/Scripts/ArrowDisappear.cs(18,31): error CS1525: Unexpected symbol (', expecting
,‘, ;', or
=’
And
Assets/Assets/Scripts/ArrowDisappear.cs(18,47): error CS1525: Unexpected symbol float', expecting
,‘, ;', or
=’
On line 18,and
Assets/Assets/Scripts/ArrowDisappear.cs(29,0): error CS1525: Unexpected symbol `}’
On line 29.
Please Help
Even though you have as many opening brackets as you have closing brackets, the placement makes no sense. If you just indent your code according to your brackets you get this:
public class ArrowDisappear : MonoBehaviour
{
public GameObject Arrow;
public bool isLaunched = false;
// Use this for initialization
void Start ()
{
{
if (isLaunched == true)
{
{
StartCoroutine(ShowAndHide(Arrow,1.0f));//1 second
}
IEnumerator ShowAndHide(GameObject go, float delay)
{
go.SetActive(false);
yield return new WaitForSeconds(1);
go.SetActive(true);
}
isLaunched = false;
}
}
}
}
As you can see you did not declare your coroutine inside your class but inside your if statement body which makes no sense at all. Like others have said you have a few pretty pointless bracket-pairs you don’t need / which do not have any effect. It probably should look like this:
public class ArrowDisappear : MonoBehaviour
{
public GameObject Arrow;
void Start ()
{
StartCoroutine(ShowAndHide(Arrow,1.0f));
}
IEnumerator ShowAndHide(GameObject go, float delay)
{
go.SetActive(false);
yield return new WaitForSeconds(delay);
go.SetActive(true);
}
}
Since Start is only called once in the life-time of the object the boolean variable is kinda pointless. Finally you pass a “delay” paremeter to your ShowAndHide method but you don’t use it. Finally you named your method ShowAndHide while it actually does a HideAndShow action.
you have to assign delay in the waitforseconds paramenter. at line 3 is a bracket for useless reason
Soooo many things are wrong, you have so many useless brackets, I don’t know what IEnumerator is and if I did I don’t think you are supposed to have a space, I may be wrong but idk.