Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question error cs1585

Discussion in 'Getting Started' started by alex56frag, Apr 17, 2024.

  1. alex56frag

    alex56frag

    Joined:
    Nov 26, 2023
    Posts:
    9
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Spawner : MonoBehaviour
    6. {
    7.    
    8.     public GameObject[Spawner1]
    9.     public float  speed;
    10.     public float speedIncrease;
    11.    
    12.     private void Update()
    13.    
    14.     {
    15.         speed += speedIncrease * Time.deltaTime;
    16.     }
    17.     public void SpawnWave()
    18.     {
    19.         int rand = Random.Range(0, blocklines.Lenght);
    20.         Instantiate(blocklines[rand], transform.position, Quaternion.identity);        
    21.     }
    22.  
    23. }
    24.  
    upload_2024-4-17_16-46-42.png
     
  2. DrDemencio

    DrDemencio

    Joined:
    Sep 2, 2022
    Posts:
    72
    I'm sure you realize asking in a forum how to fix every compilation error you find is going to get you nowhere fast (because believe me, you're going to get lots of these).
    There are 2 problems here:
    • You forgot the semicolon at the end of line 8.
    • Line 8 is wrong because:
      • It's a definition that only specifies the type (
        GameObject[Spawner1]
        ), you need to provide a name for the member (in this case provably blocklines).
      • Sorry about this part because I got it wrong in the previous post. When you define an array in C# you don't need to specify the size (
        GameObject[] blocklines
        ). In this case you'll be able to configure the dimension in the Unity inspector. If you actually want to specify the size you need to do it like this:
        GameObject[] blocklines = new GameObjects[NumberOfElements]
     
    CassClay likes this.
  3. alex56frag

    alex56frag

    Joined:
    Nov 26, 2023
    Posts:
    9
    thank you