- Home /
4 C# errors Endless Runner
Hy I got 4 Errors and I can't find the problem I'm new and following this tutorial: https://www.youtube.com/watch?v=YOLpjdcBtpA
These are the errors I hope someone can help me: Assets/scripts/Platformgenerator.cs(22,37): error CS1061: Type UnityEngine.GameObject[]' does not contain a definition for
GetComponent' and no extension method GetComponent' of type
UnityEngine.GameObject[]' could be found (are you missing a using directive or an assembly reference?)
Assets/scripts/Platformgenerator.cs(34,62): error CS1061: Type UnityEngine.GameObject' does not contain a definition for
Length' and no extension method Length' of type
UnityEngine.GameObject' could be found (are you missing a using directive or an assembly reference?)
Assets/scripts/Platformgenerator.cs(34,39): error CS1502: The best overloaded method match for UnityEngine.Random.Range(float, float)' has some invalid arguments Assets/scripts/Platformgenerator.cs(34,39): error CS1503: Argument
#2' cannot convert object' expression to type
float'
The script:
using UnityEngine;
using System.Collections;
public class Platformgenerator : MonoBehaviour {
public GameObject[] thePlatform;
public Transform generationPoint;
public float distanceBetween;
private float platformWidth;
public float distanceBetweenMin;
public float distanceBetweenMax;
public GameObject thePlatforms;
private int platformSelector;
//public Objectpooler theObjectpool;
// Use this for initialization
void Start () {
platformWidth = thePlatform.GetComponent<BoxCollider2D> ().size.x;
}
// Update is called once per frame
void Update () {
if(transform.position.x < generationPoint.position.x)
{
distanceBetween = Random.Range(distanceBetweenMin, distanceBetweenMax);
transform.position = new Vector3(transform.position.x + platformWidth + distanceBetween, transform.position.y, transform.position.z);
platformSelector = Random.Range (0, thePlatforms.Length);
Instantiate (thePlatforms, transform.position, transform.rotation);
/*GameObject newPlatform = theObjectpool.GetpooledObject();
newPlatform.transform.position = transform.position;
newPlatform.transform.rotation = transform.rotation;
newPlatform.SetActive (true); */
}
}
}
if thePlatform
is an array then you can't get any components unless you specify a single element.
seems like you've probably mixed up uses of thePlatform
(an array) & thePlatforms
(game object)
also, remove the space between <BoxCollider2D>
and the parenthesis.
Thanks the most errors are now fixt only I got still this error:
Assets/scripts/Platformgenerator.cs(22,37): error CS1061: Type UnityEngine.GameObject[]' does not contain a definition for
GetComponent' and no extension method GetComponent' of type
UnityEngine.GameObject[]' could be found (are you missing a using directive or an assembly reference?)
I fixt it: public GameObject thePlatforms; had to be: public GameObject thePlatform;
but now I got this error:
the variable thePlatforms of Platformgenerator has not been assigned. You probably need to assign the thePlatforms variable of the Platformgenerator script in the inspector.
Your answer
![](https://koobas.hobune.stream/wayback/20220612053735im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
3D infinite runner game platform generation gives an error 0 Answers
Can anyone help me with my 2D endless runner overlapping platforms? 0 Answers
How to change variables inside FindGameObjectsWithTag objects 0 Answers
Multiple Cars not working 1 Answer
Endless Runner Overlapping Platforms Bug 0 Answers