Search Unity

Assistance with Bad Array Declarator

Discussion in 'Editor & General Support' started by ppcsoldier, Dec 30, 2018.

  1. ppcsoldier

    ppcsoldier

    Joined:
    Dec 30, 2018
    Posts:
    5
    I am a complete newbie learning unity. Purchased a city building kit and getting this

    Error **** Assets/Scripts/Effects/Scale.cs(7,34): error CS0650: Bad array declarator: To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type.

    using UnityEngine;
    using System.Collections;

    public class Scale : MonoBehaviour
    { //scales some of the particle effects

    private float particleEmitter[] emitters; // This is the error I am getting right here!
    public float scale = 1;

    private float[] minSize, maxSize;
    private Vector3[] worldVelocity, localVelocity, rndVelocity, scaleBackUp;

    void Start()
    {

    ScaleEmitters();

    }

    private void ScaleEmitters()
    {
    int length = emitters.Length;

    minSize = new float[length];
    maxSize = new float[length];
    worldVelocity = new Vector3[length];
    localVelocity = new Vector3[length];
    rndVelocity = new Vector3[length];
    scaleBackUp = new Vector3[length];

    for (int i = 0; i < length; i++)
    {
    minSize = emitters.minSize;
    maxSize = emitters.maxSize;
    worldVelocity = emitters.worldVelocity;
    localVelocity = emitters.localVelocity;
    rndVelocity = emitters.rndVelocity;
    scaleBackUp = emitters.transform.localScale;

    emitters.minSize = minSize * scale;
    emitters.maxSize = maxSize * scale;
    emitters.worldVelocity = worldVelocity * scale;
    emitters.localVelocity = localVelocity * scale;
    emitters[i].rndVelocity = rndVelocity[i] * scale;
    emitters[i].transform.localScale = scaleBackUp[i] * scale;
    }
    }
    }[/i][/i][/i][/i]
     
  2. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    1,317
    You have a stray
    float
    in your declaration. Simple fix, but that error is indeed a bit obscure!

    Also, how old is that city building asset? ParticleEmitter is a legacy class used with the legacy particle system. The new Shuriken particle system uses ParticleSystem instead.
     
  3. ppcsoldier

    ppcsoldier

    Joined:
    Dec 30, 2018
    Posts:
    5
    You available for hire? :)
     
  4. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    1,317
    Depends on what you need! I'll let you know if you have extra
    float
    keywords in your code for free!
     
    Lurking-Ninja likes this.
  5. Gamebro9077

    Gamebro9077

    Joined:
    Mar 19, 2022
    Posts:
    1
    Whats Wrong??

    using UnityEngine;
    public class PlayerMovement : MonoBehaviour
    {
    private Vector3 PlayerMovementInput;
    private Vector2 PlayerMouseInput
    [SerializeField] private Transform PlayerCamera;
    [SerializeField] private Rigidbody PlayerBody;
    [Space]
    [SerializeField] private float Speed;
    [SerializeField] private float Sensitivity;
    [SerializeField] private float Jumpforce;
    }
    void Update()
    {
    PlayerMovementInput = new Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical"))
    PlayerMouseInpu = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
    MovePlayer();
    MovePlayerCamera();
    }
    private void MovePlayer()
    {
    Vector3 MoveVector = transform.TransformDirection(PlayerMovementInput) * Speed;
    PlayerBody.velocity = new Vector3(MoveVector.x, PlayerBody.velocity.y MoveVector.z);
    if (Input.GetKeyDown(KeyCode.Space)) ;
    {
    PlayerBody.AddForce(Vector3.up * Jumpforce, ForceMode.Impulse);
    }
    }
    private void MovePlayerCamera()
    }
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    Great question. Here's how YOU can find out yourself!!

    Remember: NOBODY here memorizes error codes. That's not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

    The complete error message contains everything you need to know to fix the error yourself.

    The important parts of the error message are:

    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)
    - also possibly useful is the stack trace (all the lines of text in the lower console window)

    Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.

    If you post a code snippet, ALWAYS USE CODE TAGS:

    How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/

    You may edit your post above.