- Home /
error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected
Hello everyone. I have an error and I don't know how can I fix it.
Here is the code!
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Spawn : MonoBehaviour {
public float maxHeight;
public float minHeight;
public float rateSpawn;
private float currentRateSpawn;
public GameObject tubePrefab;
public int maxSpawnTubes;
public List<GameObject> tubes;
private GameController gameController;
// Use this for initialization
void Start () {
for (int i=0; i<maxSpawnTubes; i++) {
GameObject tempTube = Instantiate (tubePrefab) as GameObject;
tubes.Add (tempTube);
tempTube.SetActive (false);
}
currentRateSpawn = rateSpawn;
gameController = FindObjectOfType (typeof(GameController)) as GameController;
}
// Update is called once per frame
void Update () {
if (gameController.GetCurrentState () != GameStates.INGAME)
return;
currentRateSpawn += Time.deltaTime;
if (currentRateSpawn > rateSpawn) {
currentRateSpawn = 0;
Spawn();
}
}
private void RateSpawn(){
float randHeight = Random.Range(minHeight, maxHeight);
GameObject tempTube = null;
for (int i=0; i<maxSpawnTubes; i++) {
if(tubes[i].activeSelf == false){
tempTube = tubes[i];
break;
}
}
if(tempTube != null){
tempTube.transform.position = new Vector3(transform.position.x, randHeight, transform.position.z);
tempTube.SetActive(true);
}
}
}
and the error is it (error CS0119: Expression denotes a type', where a
variable', value' or
method group' was expected)
"46. Spawn();" - error
Thankyou for all answers.
Answer by DoTA_KAMIKADzE · Jun 03, 2015 at 11:20 PM
Spawn is your class name so I've looked quickly through your code and seems like you most likely wanted to call RateSpawn function:
//change your line#46 to this:
RateSpawn();
If not then let me know what you expected from calling class like a function? so that I'll be able to help you further.
@Qand : Please, don't forget to accept DoTA_$$anonymous$$A$$anonymous$$I$$anonymous$$ADzE's answer by pressing the check mark under the down vote button of DoTA_$$anonymous$$A$$anonymous$$I$$anonymous$$ADzE's answer ;)
Your answer
![](https://koobas.hobune.stream/wayback/20220613200616im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Space opening main menu (undesired) 0 Answers
Keep getting this error CS8025 1 Answer
2D platformer- getting errors I don't understand (c#) 1 Answer
Multiple Cars not working 1 Answer