Why are the 'bool' wrong and why is Vector3 greyed out?

Visual Studio says this is wrong:
"
private float timer = 3f;

private bool gehnachlinks = false;
private bool gehnachrechts = false;
private bool gehnachoben = false;
private bool gehnachunten = false;
private bool defaultpos = false;
private Vector3 MoveObject;
"
of this code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Jobs;
using Unity.Jobs;


namespace DyCamMover_IJob2.Jobsystem
{
    public struct DyCamMover_IJob : IJobParallelForTransform
    {

        private float timer = 3f;

        private bool gehnachlinks = false;
        private bool gehnachrechts = false;
        private bool gehnachoben = false;
        private bool gehnachunten = false;
        private bool defaultpos = false;
        private Vector3 MoveObject;

        // Update is called once per frame
        public void Execute(int index, TransformAccess transform)
        {
            #region LinksRechtsHochRunter-Mover
            //Kamera bewegt sich durch folgendes nach Links:
            if (gehnachlinks == true)
            {
                // INFO:
                if (transform.position.x < 0.1f)
                {
                    MoveObject = new Vector3(0.175f * Time.deltaTime, 0, 0);
                    //transform.position = Vector3.SmoothDamp(transform.position, MoveObject, ref Velocity, smoothtime); //reparieren oder loeschen!
                }
                else
                {
                    gehnachlinks = false;
                }
            }
            //Kamera bewegt sich durch folgendes nach Rechts:
            if (gehnachrechts == true)
            {
                if (transform.position.x > -0.80f)
                {
                    MoveObject = new Vector3(-0.175f * Time.deltaTime, 0, 0);
                    //transform.position = Vector3.SmoothDamp(transform.position, MoveObject, ref Velocity, smoothtime);
                }
                else
                {
                    gehnachrechts = false;
                }
            }

            //Kamera bewegt sich durch folgendes nach Oben:
            if (gehnachoben == true)
            {
                if (transform.position.y < -0.8f)
                {
                    MoveObject = new Vector3(0, 0.150f * Time.deltaTime, 0);
                    //transform.position = Vector3.SmoothDamp(transform.position, MoveObject, ref Velocity, smoothtime);
                }
                else
                {
                    gehnachoben = false;
                }
            }
            //Kamera bewegt sich durch folgendes nach Unten:
            if (gehnachunten == true)
            {
                if (transform.position.y > -1.4f)
                {
                    MoveObject = new Vector3(0, -0.150f * Time.deltaTime, 0);
                    //transform.position = Vector3.SmoothDamp(transform.position, MoveObject, ref Velocity, smoothtime);
                }
                else
                {
                    gehnachunten = false;
                }
            }
            //=====
            #region DefaultKameraPos-Mover
            //Kamera bewegt sich in die Default Position:
            if (defaultpos == true)
            {
                if (transform.position.x > -0.264f)
                {   //soll nach rechts bewegen
                    MoveObject = new Vector3(-0.100f * Time.deltaTime, 0, 0);
                }
                if (transform.position.x < -0.266f)
                {//soll nach links bewegen
                    MoveObject = new Vector3(0.100f * Time.deltaTime, 0, 0);
                }
                if (transform.position.y > -1.002f)
                {   // soll runter bewegen
                    MoveObject = new Vector3(0, -0.080f * Time.deltaTime, 0);
                }
                if (transform.position.y < -1.004f)
                {// soll hoch bewegen
                    MoveObject = new Vector3(0, 0.080f * Time.deltaTime, 0);
                }

                // Wenn DefaultPos an seine gewuenschte Position angekommen ist:
                // INFO: Wird erst auf "false" geschalten sobald der alle Positionen sich in der Tolleranz befinden!
                if (transform.position.x < -0.264f && transform.position.x > -0.266f && transform.position.y < -1.002f && transform.position.y > -1.004f)
                {
                    defaultpos = false;
                }
            }
            #endregion
            #endregion

            // Rechnet den Countdown runter um eine neue richtung einzuschreiben.
            timer = timer - Time.deltaTime;
            // Wenn der Timer "0" ist, wird die Kamera selber in eine neue Richtung geschupst und dafĂźr muss eine Richtung Aktiviert werden hier drinnen:
            if (timer <= 0)
            {
                //Resetet diese zwei werte zurueck.
                timer = 8f;
                int randomrichtung = 0;

                #region ZufallsrichtungBewegungsAktivierer
                #region HighquallityZufallsGenerator
                int ix4;
                ix4 = Random.Range(1, 5);
                int ii = 0;
                switch (ix4)
                {
                    case 1:
                        while (ii < 3)
                        {
                            randomrichtung = Random.Range(1, 10);
                            ii++;
                        }
                        break;

                    case 2:
                        while (ii < 5)
                        {
                            randomrichtung = Random.Range(1, 10);
                            ii++;
                        }
                        break;

                    case 3:
                        while (ii < 7)
                        {
                            randomrichtung = Random.Range(1, 10);
                            ii++;
                        }
                        break;

                    case 4:
                        while (ii < 9)
                        {
                            randomrichtung = Random.Range(1, 10);
                            ii++;
                        }
                        break;

                }

                #endregion

                // Hier wird ein zufall bestimmt, der in eine zufällige richtung sich bewegt von 4 moeglichen Richtungen.
                switch (randomrichtung)
                {
                    //"Links" bewegung aktiv
                    case 1:
                        defaultpos = false;
                        gehnachlinks = true;
                        gehnachrechts = false;
                        gehnachoben = false;
                        gehnachunten = false;

                        //Debug.Log("Linkshinbewegen ist aktiv");
                        break;
                    //"Rechts" bewegung aktiv
                    case 2:
                        defaultpos = false;
                        gehnachlinks = false;
                        gehnachrechts = true;
                        gehnachoben = false;
                        gehnachunten = false;

                        //Debug.Log("Rechtsshinbewegen ist aktiv");
                        break;
                    //"Hoch" bewegung aktiv
                    case 3:
                        defaultpos = false;
                        gehnachlinks = false;
                        gehnachrechts = false;
                        gehnachoben = true;
                        gehnachunten = false;

                        //Debug.Log("Hochhinbewegen ist aktiv");
                        break;
                    //"Runter" bewegung aktiv
                    case 4:
                        defaultpos = false;
                        gehnachlinks = false;
                        gehnachrechts = false;
                        gehnachoben = false;
                        gehnachunten = true;

                        //Debug.Log("Runterhinbewegen ist aktiv");
                        break;

                    //===============================================
                    //"Links + Hoch" bewegen aktiv
                    case 5:
                        defaultpos = false;
                        gehnachlinks = true;
                        gehnachrechts = false;
                        gehnachoben = false;
                        gehnachunten = true;

                        //Debug.Log("Links+Hoch = aktiv");
                        break;
                    //"Links + Runter" bewegen aktiv
                    case 6:
                        defaultpos = false;
                        gehnachlinks = true;
                        gehnachrechts = false;
                        gehnachoben = false;
                        gehnachunten = true;

                        //Debug.Log("Links+Runter = aktiv");
                        break;
                    //"Rechts + Hoch" bewegung aktiv
                    case 7:
                        defaultpos = false;
                        gehnachlinks = false;
                        gehnachrechts = true;
                        gehnachoben = true;
                        gehnachunten = false;

                        //Debug.Log("Rechts+Hoch = aktiv");
                        break;
                    //"Rechts + Runter" bewegung aktiv
                    case 8:
                        defaultpos = false;
                        gehnachlinks = false;
                        gehnachrechts = true;
                        gehnachoben = false;
                        gehnachunten = true;

                        //Debug.Log("Rechts+Runter = aktiv");
                        break;
                    //"defaultpos" bewegung aktiv
                    case 9:
                        defaultpos = true;
                        gehnachlinks = false;
                        gehnachrechts = false;
                        gehnachoben = false;
                        gehnachunten = false;

                        //Debug.Log("DefaultPosition = aktiv");
                        break;

                        #endregion
                }
            }


        }

    }
   
}
public class DyCamMover_IJob : MonoBehaviour
{
    private Vector3 MoveObject;
    private void Update()
    {
        transform.Translate(MoveObject);
    }
}

Says what is wrong? What are your errors? Copy and paste them here as part of your post.

Fields of structs can not have field initializers. So remove all your = and the default value behind it.

In other words it should look like this:

public struct DyCamMover_IJob : IJobParallelForTransform
    {
        private float timer;
        private bool gehnachlinks;
        private bool gehnachrechts;
        private bool gehnachoben;
        private bool gehnachunten;
        private bool defaultpos;
        private Vector3 MoveObject;
        // [ ... ]
3 Likes

And then how should I assign the value? Because I can’t place a void start there and if I try that in an additional monobehavior, then it doesn’t know the bool and float variables from the: “public struct DyCamMover_IJob : IJobParallelForTransform”…

First, it’s worth noting that all value-types in C# have a default value when not initialized.
For your specific use-case:

  • float defaults to 0.0f

  • bool defaults to false

  • Vector3 defaults to Vector3.zero

  • Technically this is because the x,y,z floats inside the Vector3 all default to 0.0f.

If you want to keep the struct’s fields private/readonly, then you would have to initialize them all in a constructor, which isn’t very convenient when it has a decent number of fields to initialize:

public struct DyCamMover_IJob : IJobParallelForTransform {
   private float timer;
   private bool gehnachlinks;
   private bool gehnachrechts;
   private bool gehnachoben;
   private bool gehnachunten;
   private bool defaultpos;
   private Vector3 MoveObject;

   public DyCamMover_IJob(float timer, bool gehnachlinks, bool gehnachrechts, bool gehnachoben, bool gehnachunten, bool defaultpos, Vector3 moveObject) {
      this.timer = timer;
      this.gehnachlinks = gehnachlinks;
      this.gehnachrechts = gehnachrechts;
      this.gehnachoben = gehnachoben;
      this.gehnachunten = gehnachunten;
      this.defaultpos = defaultpos;
      this.MoveObject = moveObject;
   }
}
//Example
DyCamMover_IJob instance = new DyCamMover_IJob(3f, false, false, false, false, false, false, Vector3.zero);

If some or all of these fields can be initialized optionally, you can make the constructor a bit more convenient by giving the parameters default values:

public DyCamMover_IJob(float timer = 0f, bool gehnachlinks = false, bool gehnachrechts = false, bool gehnachoben = false, bool gehnachunten = false, bool defaultpos = false, Vector3 moveObject = Vector3.zero) {
   this.timer = timer;
   this.gehnachlinks = gehnachlinks;
   this.gehnachrechts = gehnachrechts;
   this.gehnachoben = gehnachoben;
   this.gehnachunten = gehnachunten;
   this.defaultpos = defaultpos;
   this.MoveObject = moveObject;
}

Then you could initialize only the parameters you want:

//Example of just initializing the "timer" field
DyCamMover_IJob instance = new DyCamMover_IJob(3f);

If the fields can be public/writable, then the most convenient way is to turn them into properties and use the curly-brace method of instantiation. A constructor can be omitted, and each property could be optionally assigned:

public struct DyCamMover_IJob : IJobParallelForTransform {
   public float Timer { get; set; }
   public bool Gehnachlinks { get; set; }
   public bool Gehnachrechts { get; set; }
   public bool Gehnachoben { get; set; }
   public bool Gehnachunten { get; set; }
   public bool DefaultPos { get; set; }
   public Vector3 MoveObject { get; set; }
}
//Example instantiating with some property assignments:
DyCamMover_IJob instance = new DyCamMover_IJob {
   Timer = 3f,
   DefaultPos = true,
   MoveObject = Vector3.one
};
2 Likes

I hardly understood anything about it because all the possibilities are mixed together and I don’t know what to separate from what now in order not to have 5 different puzzles.

And what should I do with the rest of the code?
Where should I put the rest of the code?

Apart from that I would highly recommnd to replace your booleans with an enun unless you really need two directions in the same frame.

The rest of the code? You keep your struct the same, you just have to make sure you initialize your variables either through a constructor or from the outside. Since your direction booleans don’t look like they need initialization at all you can just remove all the “= false” from your code. The only variable left would be your timer variable. This could be initialized from the constructor. Another way would be to provide a SetTimer method where you can set the timer to a value after you created the struct.

Note that values types are not initialized explicitly. The memory where they are stored is simply zero filled. So all bytes are set to 0. All types will therefore have a default value depending on that. References will have a value of null and integral types will just have a value of 0.

Note that in my code example I had a // [ ... ] at the end to indicate that the rest of your struct should follow since this was just about removing the field initializers.

@Vryken please I need your help, its a very important task for me and I have got no idea how to do it, its a mp4 custom player.

Example: play your videos from your hard drive by copying your video and pasting it in the specific folder C:/User/%appdata%/locallow/‘Game Name’/videos.

I hope I get an answer soon enough.

Sincerely,
Jack Alfred.

Please post your question on the forums instead of PM’ing me and waiting for an answer. I don’t have the answers to everything, and there are lots of people here who might be able to help you.

Personally, I’ve never even touched Unity’s video-playing features yet, let alone tried making a custom MP4 player, so I have as much knowledge on the subject as you do.