Search Unity

I... have some problems

Discussion in 'Scripting' started by Allgames88, Sep 19, 2020.

  1. Allgames88

    Allgames88

    Joined:
    Sep 14, 2020
    Posts:
    2
    I started making simple code, with variables and all of those things, but now i get an error 1012, its extrange because i investigated, and i can't find any tipe of failure.

    This is my code:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class Selection_seed : MonoBehaviour
    {
    // Start is called before the first frame update
    void Start()
    {}
    public bool Selected;
    public int Plant;
    public int position;
    public bool OcupedA;
    public bool OcupedB;
    public bool OcupedC;
    public bool OcupedD;
    public bool OcupedE;
    public bool OcupedF;
    }

    // Update is called once per frame
    void Update()
    {
    if (position = 0)
    {
    GetComponent(MeshRenderer).enabled = false;
    } else if(position = 1)
    {
    gameObject.Transform.position = new Vector3(-41.8f, 16.2f, 0.1f);
    } else if (position = 2)
    {
    gameObject.Transform.position = new Vector3(-41.8f, 9.2f, 0.1f);
    } else if (position = 3)
    {
    gameObject.Transform.position = new Vector3(-41.8f, 2.2f, 0.1f);
    } else if (position = 4)
    {
    gameObject.Transform.position = new Vector3(-41.8f, -5.2f, 0.1f);
    } else if (position = 5)
    {
    gameObject.Transform.position = new Vector3(-41.8f, -12.2f, 0.1f);
    } else if (position = 6)
    {
    gameObject.Transform.position = new Vector3(-41.8f, -19.2f, 0.1f);
    }
    }
    }
     
  2. Allgames88

    Allgames88

    Joined:
    Sep 14, 2020
    Posts:
    2
    In line 9, if I remove the "}" error appears and I don't understand it
     
  3. adehm

    adehm

    Joined:
    May 3, 2017
    Posts:
    369
    Your Update is not in your MonoBehaviour class.
    Code (CSharp):
    1. public bool OcupedF;
    2. }//class is closed here
    Your Start is empty but likely should be because why would you declare variables in Start and not even use them before they are removed from memory; but might be why you are confused with your brackets.
    Code (CSharp):
    1. void Start()
    2. {}
    Also please use code tags when putting code in the forum. Toolbar->Insert->Code
     
    Allgames88 likes this.