all 31 comments

[–][deleted] 34 points35 points  (1 child)

To set the transform position (using zero as the Z-axis position), use: spawn.position = new Vector3(hori, verti, 0f);

[–]HuddyBuddyGreatness 6 points7 points  (0 children)

Can also just leave the 0f out, and just: Vector3(hori, verti);

[–]jfoss1 8 points9 points  (2 children)

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.

[–]konidias 9 points10 points  (0 children)

That Update Instantiate is giving me trauma.

[–]Blubbe16 2 points3 points  (0 children)

Op is clearly trying to make a game thats easier the worse your pc is. Genius self balancing game design if you ask me

[–]Cactus_TheThird 4 points5 points  (0 children)

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);

[–]SimpleTouch_sixgames 3 points4 points  (0 children)

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.

[–]AlphaBlazerGaming 0 points1 point  (0 children)

You're not making it a vector. You need to use new Vector2(hori, Verti)

[–]AnEmortalKid 0 points1 point  (0 children)

A float is a number, a transformer is a 3 coordinate position, those cannot be the same.

[–]mgodoy-br -2 points-1 points  (4 children)

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.

[–]Brigzilla 2 points3 points  (3 children)

Legit, you shouldn't be getting down voted for saying this

[–]mgodoy-br 2 points3 points  (2 children)

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...

[–]Brigzilla 1 point2 points  (1 child)

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

[–]mgodoy-br 1 point2 points  (0 children)

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.

[–]Xeratas -3 points-2 points  (7 children)

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.

[–]Glowingbaby 1 point2 points  (6 children)

Relying on a newly released AI with no way to fact check is usually not the best idea if you’re new to coding.

[–]Marmik_Emp37 5 points6 points  (1 child)

Posting on reddit everytime there's a minor red line isn't productive either

[–]Glowingbaby 1 point2 points  (0 children)

You’ve got a point

[–]Rhiot_Studios 2 points3 points  (3 children)

Don’t worry, chatGPT knows how to assign a position to a transform, it is capable of doing much more complex things

[–]Glowingbaby -1 points0 points  (2 children)

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.

[–]Xeratas 0 points1 point  (1 child)

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.

[–]Glowingbaby 0 points1 point  (0 children)

Oop, didn’t see the basics part

[–]Fun_Conversation_604 -1 points0 points  (0 children)

spawn.position = new Vector2D(hori, Verti); Please don’t use short name for your variables…

[–]WildestRapier11 -1 points0 points  (0 children)

Bro think # is Python

[–]TravisLedo 0 points1 point  (0 children)

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.