❔ cs0670 unity 2d (very simple)
so basically, i was bored and decided to just make a "game" and yeah its weird. but basically i have a circle that spins infinitely that im trying to get to "if rotation = 310* stop" basically making a wheel of fortune or whatever. and my pc doenst have enough space to make a 180 frame photoshop animation (trust me, i would, i was really bored) and i just need to know what is wrong with the code, i keep getting cs0670 "field cannot have void type", lmk if u need more info. Code below (please dont judge i know, im bad at coding, i do it for school)
using System.Collections; using System.Collections.Generic; using UnityEngine; public class SpinGray : MonoBehaviour { public static void Stop() { transform.Rotate(new Vector3(0, 0, 320)); } // Start is called before the first frame update void Start() {
} // Update is called once per frame void Update() { transform.Rotate(new Vector3(0, 0, 120 * Time.deltaTime)); if (transform.Rotate(new Vector3(0,0,319))) { Stop; } } }
using System.Collections; using System.Collections.Generic; using UnityEngine; public class SpinGray : MonoBehaviour { public static void Stop() { transform.Rotate(new Vector3(0, 0, 320)); } // Start is called before the first frame update void Start() {
} // Update is called once per frame void Update() { transform.Rotate(new Vector3(0, 0, 120 * Time.deltaTime)); if (transform.Rotate(new Vector3(0,0,319))) { Stop; } } }
59 Replies
the basic "keep spinning" script on the circle is just void Update()
{
transform.Rotate(new Vector3(0, 0, 120 * Time.deltaTime));
}
oh fun now my rotate script dont work anymore either
worked perfectly a couple minutes ago and didnt touch it.
check the debug log
there could be some error messages printed
i got this that i got when i tried new thing, tried something simpler earlier and only got 0670
Transform.Rotate
does not return you anything
That is why you have the void
errorwhich file/ line number throws that?
here
Also
can you show that line?
Don't check for
float
values like that9 or all of em
lets go with 9 first
which line is 9?
sorray
Your
if
wants to get a boolean from a void
method. transform.Rotate
does not returns anything, it is void
first
Stop
must be called as a method: Stop();
why did you set ur Stop method as static?
idfk, some dude on the internet
i suggest you learn the basics of C# before you start unity, or ur gonna have a tough time
check links below $helloworld
Written interactive course https://learn.microsoft.com/en-us/users/dotnet/collections/yz26f8y64n7k07
Videos https://dotnet.microsoft.com/learn/videos
dont just write random stuff and expect things to work magically, u have to know what u are doing
fixed one error, i am tired and stupid, ty
The
transform.Rotate
simply rotates the objectyeah
It won't return you anthing you could use to check the object rotation
yeah i know, ive been trying to figure it out and just put that and it has stayed and i havent changed it
You can check it by the EulerAngles, tho, which could be asier
havent gotten that far
but yeah, as i said, im pretty bad at coding and wont have big use of it as im switching schools, as i said, im just bored and have nothing to do
Also, you don't have to make your
Stop
function static. You can remove the static
keywordmakes decent sense
Wait
ohkey
just tried some stuff i thought made decent sense, and only get one error now, 0029 void to bool. probably my worst side, still cant get into my head what words give what
Try using my code
Read the comments
yeesh, spoon-feeding. let them learn the fundamentals at their own pace
I see no problem. I've been spoon-feeded thousand of times when I was learning :V
But read the comments @Istix so you can start making some idea of what the code is doing
readin
checked my lesson planning as well, learning about eulerangles in 2 weeks : >
If you're on Visual Studio, hover the mouse over a method, like the
Rotate
, if you see void
in the beginning of the method declaration, it does not return anything, so you can't use this method result inside an If
Like this one, a
void
, it does not return anything(Took this from my code, just an example)
the fact that i understand more from u people telling me stuff than i do from my teacher must mean something
University teaching methods sucks
Ppl still teaching C/CPP here where I live as the
programming basis
university O.O
im in high school xd
Universities here (Brazil) are no different
swedish school is special
ah
Don't get upset bc you don't understand stuff right now, you'll surely become a good programmer if you focus on it
noone is probably stupid enough to try same thing as me and get the same error. but just letting u know, u had theshold on 2 thingymajigs and threshold on the private float
Typo, tks
im swapping from programming to mechanic cuz im still tryna figure out what to do with my life, i liked programming for a bit but imo its just fun when u get those kicks like "i wanna do this"
Then my job here is done...lol
and also, just looking at the logs and stuff, im guessing the "minValue" is supposed to be minRange?
cuz currently its just a bunch of does not exist in current context
Yah, it was just superfast typing, I'm about to go
name minrange name maxrange
well thank u a lot for all your help, i appreciate it
i had a really dumb way of doing it damn
was gonna do like "if button is clicked then randomize a number between 1 and 100, if the number is 50-100 its a common reward, etc etc" and damn, this seems a LOT smarter
You can do that, there are better ways to do that on Unity, like
Coroutines
, you could take a look, but I guess you should learn a bit more about the fundamentals before itok so quick update
unity is screaming at me
so i changed this to 90. literally nothing else.
script class cannot be found....
im so annoyed
and magic. it works
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.