10
u/jfoss1 Feb 22 '23
There's a few issues here that I think you're going to run into. First, I'm not sure what you're trying to do with the script, but your Start method is trying to assign a transform to a combination of 2 floats. Transforms don't work like this. Perhaps you're trying to set the position which you could do with spawn.position =... But the way this is written you'll end up with a Null Reference Exception as spawn has not yet been assigned.
Further you're update is going to instantiate a new enemy slider EVERY frame, I'm sure that you don't want to do this.
Can you explain what you're trying to achieve? I think a little more insight into the end goal will help others find solutions beyond just getting it to compile.
10
3
u/Blubbe16 Feb 23 '23
Op is clearly trying to make a game thats easier the worse your pc is. Genius self balancing game design if you ask me
5
u/Cactus_TheThird Feb 22 '23
I'm assuming you're trying to set the position.
First of all "Transform" is a class that holds more than just the position, it also accounts for the rotation and scale of the GameObject. If you want to set the Transform's position you do
transform.position = [vector3]
Second in order to set a vector you need to actually gove a vector as input. If you have 2 values for x and y you can write
transform.position = new Vector3(hori, verti, 0);
4
u/SimpleTouch_sixgames Feb 23 '23
you should read some books like C# Programming Guide.
After having a certain programming language foundation, you will find that these are very simple common sense.
1
u/TravisLedo Feb 23 '23
Before you even fix that part. add some kind of counter inside the update that triggers the Instantiate or you are gonna be in enemySlider hell.
1
u/AlphaBlazerGaming Feb 22 '23
You're not making it a vector. You need to use new Vector2(hori, Verti)
1
u/AnEmortalKid Feb 23 '23
A float is a number, a transformer is a 3 coordinate position, those cannot be the same.
0
u/mgodoy-br Feb 22 '23
Do you know the OOP paradigm? There are a term called "polimorfism". One of its kinds you can assign an object of more specific kind (bus, truck, for instance) for less specific (car, for instance). However, you can't assign from totally diferent ones.
You got float type and is trying to assign on a transform. That's the issue. Float as nothing to do with transform. Probably is missing something. I guess you was trying to set an attribute of type float of transform (such as transform.localposition.x) that is a float too.
Or feed a Vector3 assign one o its float attributes, like this.transform.localposition = new Vector3( yourFloatHere, 0, 0).
I sugest you study OOP. It's very important and it worth for Java too, in case you want to work as a Software Programmer too. It's easy to learn (but hard to master it) but it is totally worthy.
3
u/Brigzilla Feb 23 '23
Legit, you shouldn't be getting down voted for saying this
3
u/mgodoy-br Feb 23 '23
No problem. It's good though someone has validate my comment. Thanks! :)
About down votes, I don't care for them much. The worst thing is when people gave impolite answers. Like I said: Indie community produces amazing stuff, but there a lot of us walking like a crab: we are a lot of amateurs game designs along with a lot of amateurs streamers and instead of we help each other, we sabotage ourselves...
2
u/Brigzilla Feb 23 '23
My issue with down voting is it bumps the reply to the bottom of the list of answers so unless someone reads through everything they won't see it
2
u/mgodoy-br Feb 23 '23
I didn't know that. It's bad because avoid people seeing the right answer.
But it isn't the reddit exclusivity. In Stackoverflow there a lot of impolate people too. Sometimes I've seen answers like "why do you trying to do that??", in a way of make the person sounds stupid, you know? Instead of help, or just doesn't answer anything, whether the person didn't get the question.
-2
u/Xeratas Feb 22 '23
you guys should learn to use chatGPT. Really, would have found the bug and gave a very detailed explaination.
Don't let it write code for you, always try it yourself first. but using it for Debugging is actually pretty good. especially on basics like this.
2
u/Glowingbaby Feb 23 '23
Relying on a newly released AI with no way to fact check is usually not the best idea if you’re new to coding.
6
u/Marmik_Emp37 Feb 23 '23
Posting on reddit everytime there's a minor red line isn't productive either
2
3
u/Rhiot_Studios Feb 23 '23
Don’t worry, chatGPT knows how to assign a position to a transform, it is capable of doing much more complex things
0
u/Glowingbaby Feb 23 '23
Yeah I know that, but he’s saying it like it knows how to fix all your coding problems. And while usually it can fix one, yes. That fix can also cause several problems down the road.
1
u/Xeratas Feb 23 '23 edited Feb 23 '23
I said especially for basics. iam talking to OP in my post and on this sub most code related error could be fixed by asking chatGPT and the explaination would be better than what some people write here. Obviously don't ask it for super complex Problems. If you have super complex problems you are very likely smart enough to solve them yourself anyway.
1
-8
u/ripshitonrumham Feb 22 '23
🤦🏻♂️
7
u/AdTiny3493 Feb 22 '23
I'm new to coding leave me alone 😕
3
1
u/abramsmatthew99 Feb 23 '23
They’re getting downvoted for a reason, being a beginner is something everybody has to go through.
1
0
u/Fun_Conversation_604 Feb 23 '23
spawn.position = new Vector2D(hori, Verti); Please don’t use short name for your variables…
0
0
35
u/[deleted] Feb 22 '23
To set the transform position (using zero as the Z-axis position), use:
spawn.position = new Vector3(hori, verti, 0f);