Project Boost Oscillator Script Question

I would like to modify the oscillator script with a permanent variable of 8 to the y axis, rather than enter it manually every time I run the program.

This is what I thought the code would be: Vector3 movementVector(0,8,0);

But it gives me 9 error messages.

What is the code to set up the oscillator to go up and down on Y axis with code rather than by entering the 8 in the Serialized field?

I tried to resolve this by reading the Unity Docs vector3 but with no success :frowning: .

Thank you

Hi, can you show us the line in your code where you define the serialized field?

First, this is not how you initialise a variable. Here you defined a variable and tried to set the value on the definition. It should rather be

Vector3 movementVector = new Vector3(0, 8, 0);

As you can see, there’s the definition followed by the assignment.

Second, like @edc237 asked; show us the script. It should not be necessary to enter the value each time. Once it is set in the inspector it is serialised and saved to a file.

1 Like

[SOLVED] Thank you, thank you. That’s exactly the code I was looking for. I wanted to see an example of assigning a value to a Vector3 variable. That worked perfectly! But it looks like I also didn’t know that when I apply a value in the inspector for a serialized field that the value is remembered after I log out. I thought it would reset.

When I was posting my question I only included the code that I thought was applicable. I can post the entire script next time if that’s more helpful for debugging questions. Thanks again ::slight_smile:

[SerializeField] Vector3 movementVector;

The whole point of serialized fields is so that you can configure the game without changing the code. If you now extend the game and want to add another oscillator that moves with a different speed or on a different axis, you’d have to create another script because you hard-coded the value into this one. If you use the inspector you can just adjust the value there and reuse the same code.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms