#💻┃code-beginner

1 messages · Page 252 of 1

swift crag
#

because it's trying to do 50 fixed updates per in-game second

dusty silo
#

I am using this https://gdl.space/wuvufeliqo.cs triangulator that I found online and edited slightly. When I run the code, I get the following error:
"Failed setting triangles. Some indices are referencing out of bounds vertices. IndexCount: 24, VertexCount: 0"
There isn't a code problem with the triangulator, but it seems to be doing something wrong. The problem is that it is completely opaque to me. Can anyone here see if & where something is going wrong?

swift crag
#

Scaling fixedDeltaTime based on the timescale means that it's always doing the same number of fixed updates per real world second

brazen canyon
#

Hey guys, I need a little help
Here I have this method
This method spawns an item in a position that's empty, but I want it to spawn item a few second after that position is emptied.
So I use Coroutine
But it doesn't work, the new items kept being spawned immediately
Please help, where do I have to put the yield return ?

swift crag
#

Show the entire script.

#

!code

eternal falconBOT
brazen canyon
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FloorManager : MonoBehaviour
{
    [SerializeField] private List<Transform> floorSpawnPoints = new List<Transform>();
    [SerializeField] private List<GameObject> floorBricks = new List<GameObject>();
    [SerializeField] private GameObject brickPrefab;
    [SerializeField] private GameObject gate;
    [SerializeField] private bool canSpawnBricks = true;
    [SerializeField] private GameObject player;
    [SerializeField] private bool test;

    private GameObject brick;
    private GameObject respawnedBrick;
    private bool canRespawn;

    private void Awake()
    {
        if(canSpawnBricks)
        {
            SpawnBricks();
        }
    }
    private void Update()
    {
        StartCoroutine(RespawnBrick());
    }
    public void SpawnBricks()
    {
        for (int i = 0; i < floorSpawnPoints.Count; i++)
        {
            if (floorSpawnPoints[i].GetComponent<SpawnPoint>().HasBrick == false) {
                brick = Instantiate(brickPrefab, new Vector3(floorSpawnPoints[i].position.x, floorSpawnPoints[i].position.y, floorSpawnPoints[i].position.z), Quaternion.Euler(0, 90, 0));
                brick.GetComponent<BrickColorChange>().ColorChange();
                floorBricks.Add(brick);
            }
            floorSpawnPoints[i].GetComponent<SpawnPoint>().HasBrick = true;
        }
    }
    public IEnumerator RespawnBrick()
    {
        float timer = Random.Range(3,5);
        yield return new WaitForSeconds(timer);
        SpawnBricks();
    }
}
swift crag
#

The code you showed looks fine -- it waits for either 3 or 4 seconds, then calls SpawnBricks

#

You're starting a coroutine every single frame

#

So there are tons and tons of coroutines running all at once

#

Perhaps you wanted to start it once when the brick was destroyed

#

(note that if you want a range of 3 to 5 seconds, you should do Random.Range(3f, 5f))

#

if you give it two integers, you get an integer in the range [low, high)

#

excluding the high value

swift crag
#

You should be getting a line number.

dusty silo
#

It's coming from UnityEngine. There is no error in the triangulator, just in the array that it spits out

dusty silo
# swift crag You should be getting a line number.
public void render() {
        Mesh mesh = new Mesh();
        mesh.triangles = new Triangulator(_points).Triangulate();
        mesh.vertices = _points.ConvertAll(p => new Vector3(p.x, p.y, 0)).ToArray();
        mesh.uv = _points.ConvertAll(p => new Vector2(p.x / (MAX[0] - MIN[0]), p.y /(MAX[1] - MIN[1]))).ToArray();

        GetComponent<MeshFilter>().mesh = mesh;
    }

It is being called line 3 of render()

native seal
#

right now im creating all my data in a static class with static readonly dictionaries, is this a fine way to do it?

#

for example, all the tiers for each stat along with its weight, etc that can roll on an item

swift crag
#

You need to assign vertices first

swift crag
#

It immediately tries to validate the mesh when you do that.

rocky canyon
#

i'll have to find out where..

rocky canyon
#

i'd rather pitch the volume up and down... than scale the timescale.. not sure whats going on

swift crag
#

it's two differeent things

rocky canyon
#

ya, sadly i dont understand what thats doing..

swift crag
#

It's setting a mixer parameter based on the time scale

#

I presume audio sources are reading that parameter to set their speed parameter

#

Completely separately, it's computing a fixedDeltaTime value based on the current timescale

rocky canyon
#
        void FixedUpdate() {
            // Set the fixed update rate based on time scale
            Time.fixedDeltaTime = Time.timeScale * initialFixedTime;
            fixedTimeFactor = 0.01f / initialFixedTime;
            inverseFixedTimeFactor = 1.0f / fixedTimeFactor;
        }```
#

this part eh?

#

lol. math

swift crag
#

Yes. I dunno what fixedTimeFactor and inverseFixedTimeFactor are used for

#

But that's what the first line is doing.

rocky canyon
#

time.. and math..

#

codes trying to softlock me

dusty silo
brazen canyon
swift crag
#

Each time you call StartCoroutine, you're giving your MonoBehaviour an enumerator

#

By default, the enumerator gets resumed once every frame

#

so you had like 100 RespawnBrick enumerators all running

#

when an enumerator being run as as coroutine yields WaitForSeconds, Unity..waits for that many seconds!

#

then it resumes the enumerator again

#

and in this case, it calls SpawnBricks

rocky canyon
# swift crag right there https://discord.com/channels/489222168727519232/497874004401586176/1...

In simpler terms, this script ensures that when you want time to go faster or slower in your game, it doesn't just affect how things look or sound but also how the physics and other calculations happen. It keeps everything in sync, making sure that when time speeds up, everything speeds up, and when time slows down, everything slows down. This can be useful for creating slow-motion or fast-motion effects in your game. I had chatgpt ELI5 lol..

#

that might actually be fine to mesh w/ my prototype i already have..

#

the only thing i do is pause Time w/ time Time.timeScale

#

currently thats the only thing i do

swift crag
#

well, it's not that it makes physics run slower or faster as the timescale changes

#

that already happens

#

it keeps the number of physics updates per real-world second constant

rocky canyon
#

okay. i think i understand it now.

#

i usually stay away from time.. but this seems to be a dependency

swift crag
#

that's how coroutines work: your method does some work, then hits a yield and takes a break until Unity resumes it later

rocky canyon
#

okay I did a sample run.. the TimeMaster script doesn't negatively affect my existing code 👍 thats a good thing.

#

soo from what ive gathered from you and other research this basically is just a supplementary system.. that basically does what unity already does..

#

just a bit more

swift crag
#

By default, the number of physics updates is consistent per in-game second

devout flower
#

Hi, i don't have a particular problem but i'm just curious

#

I notice that you're emphasizing "in-game"

#

Is there a difference between ingame second and real-life second?

swift crag
#

Right.

#

Time.time measures how much time has passed when you take the timescale into account

devout flower
#

Ohhh

#

Interesting

swift crag
#

Time.unscaledTime ignores that.

#

It, along with Time.unscaledDeltaTime, are useful for things like UI that shouldn't depend on the timescale

#

(well, in-world UI should probably care about the timescale!)

devout flower
#

So when you change the time scale, let's just say from 1 to 0.5, then the number of physics update will be halved?

swift crag
#

The number that happen per real-world second, yeah

devout flower
#

Ah okok

#

That's useful to know for future projects

swift crag
#

Assuming the player isn't providing any inputs, this means that changing the timescale shouldn't change the outcome of physics

devout flower
#

Ah i see

swift crag
#

It won't run more simulation steps with a smaller timestep for each one

#

And, conversely, if you crank up the timescale, you don't get fewer, longer physics timesteps

devout flower
#

Before, I thought it would just magically know to make the physics simulation run at the same speed, but do less things

swift crag
#

when I set my game's time scale to like 50, I get dozens of FixedUpdate calls per second

devout flower
#

Wow

swift crag
swift crag
#

so, by definition, we must run fewer physics updates per real-world second when the timescale is less than 1

devout flower
#

I see i see

devout flower
#

Wait imma be back in 3 min

swift crag
#

It does, yes. Hence Time.unscaledDeltaTime for when you don't want to factor in the timescale

devout flower
#

Oh i see

#

So if I was moving an object by adding to its position (times Time.deltaTime), I shouldn't multiply by Time.timeScale as well?

swift crag
#

Yeah, don't factor in Time.timescale

#

I guess you could do Time.unscaledDeltaTime * Time.timescale, but that'd be a bit silly :p

charred heart
#

Hi, I'm trying to run a coroutine from a non-monobehavior class. The problem is that coroutine only triggers once, no matter how many times I call it. This line yield return StartCoroutine(_currentAction); only run once.

private Action _callback;
public void SetGameEvent(IEnumerator currentAction, Action callback)
{
    _currentAction = currentAction;
    _callback = callback;
}

public void StartEvent()
{
    if (_currentAction != null)
    {
        StartCoroutine(StartEventCoroutine());
    }
}

private IEnumerator StartEventCoroutine()
{
    yield return StartCoroutine(_currentAction);  /// this 
    _callback?.Invoke();
}```
swift crag
#

_currentAction is an enumerator

#

once it's done, it's done

polar acorn
#

You'd need to make a new IEnumerator each time

swift crag
#

StartCoroutine(_currentAction) will see that you gave it a coroutine that's exhausted and immediately throw it out

polar acorn
#

It's a bit complicated, but you could take in a function that returns IEnumerator and then invoke it

swift crag
#
StartCoroutine(enumeratorSource());
polar acorn
#

So, instead of taking IEnumerator and passing it SomeFunction(), you take a Func<IEnumerator> and pass it SomeFunction

swift crag
#

I wish it was System.Proc (for Procedure)

#

in Ye Olde Lingo, a procedure doesn't return something, and a function does

#
public void Whatever() {
  IEnumerator coroutineInstance = CoroutineMethod();
  System.Func<IEnumerator> coroutineMaker = CoroutineMethod;
  IEnumerator anotherInstance = coroutineMaker();
}

public IEnumerator CoroutineMethod() {
  ...
}
#

there's the distinction

novel void
#

Unity won't open/go to Vs Code when clicking console log messages or errors, but it DOES when clicking warnings only. I checked the external tools path and reinstalled Vs Code. What am I doing wrong?

charred heart
olive lintel
#

hey guys, is there an easy way to expose all of these variables in a collapsable panel in the editor for my monobehaviour? this just looks absolutely awful and is a constant headache

summer stump
slender nymph
#

there are a few ways, either using a custom editor for that class, shoving all of that into a serialized class and have a variable of that class on the MB instead, or use a 3rd party asset like Odin or Naughty Attributes that include Foldout attributes

olive lintel
olive lintel
#

ok I think I'll try make a custom inspector then

summer stump
olive lintel
#

oh ok

#

thank you

swift crag
#

Worry about stuff that you do many times

#

GetComponent in Start on something that there's only one copy of is completely fine

#

GetComponent in Update in something you've got 500 copies of is...less so

lost anvil
#

would a simple distance check be good enough to check whether an AI Agent has reached its destination?

#

only asking because ive seen people say you need to do some random complicated stuff to be accurate

swift crag
#

well, that's pretty vague

#

what would this "complicated stuff" be?

lost anvil
#

its probably not complicated but its this,

#

its not complicated now i look at it properly haha

swift crag
#

you know, this is something I've needed to figure out myself. i have really inconsistent logic for "are we there yet?" in my game

#

I just call it once I'm within the stopping distance

lost anvil
#

lol fair enough, thats what i was planning

charred heart
lost anvil
#

maybe hes still in that 1 unit range of the distance check and its spamming? idk

swift crag
#

Log each time that you set a new destination

hidden sleet
#

If I have a component on a game object that implements an interface, can I use getComponent with that interface passed in to get it? Or does it have to reference the actual class name?

swift crag
#

or maybe just use Debug.DrawLine to draw a line to the destination

hidden sleet
#

Ah!

swift crag
#

Any type that the component can be assigned to will work

hidden sleet
#

that could be huge for what I'm facing right now

#

basically rewriting everything I've done from the ground up it's such a mess

swift crag
buoyant rune
#

I want to set the startgame function to this button but it aint appearing

swift crag
#

You need to drag in an actual object in the scene

buoyant rune
#

wdym

swift crag
#

MonoScript is how Unity represents the actual script asset -- the .cs file

#

Have you added the mainmenu component to an object in your scene?

buoyant rune
#

yes to the main camera

swift crag
#

Drag the main camera object in, then

buoyant rune
#

bruh , thanks 😂

hexed dune
#

Hey I'm having some trouble with a script I wrote to slowly pan the character from any y rotation to a certain one. I set up some Debug.Log statements and the console says that it called the function without error, yet the function did not print that it executed. Any advice would be great. Thanks!

viewControls.SlowTurn();
Debug.Log("Called slow turn");
public IEnumerator SlowTurn()
    {
        Debug.Log("Slow turn executing...");
        Quaternion targetRotation = Quaternion.Euler(0, 308.55f, 0);

        Debug.Log("Target rotation: " + targetRotation);
        while (Quaternion.Angle(transform.rotation, targetRotation) > 0.01f)
        {
            float step = turnSpeed * Time.deltaTime;
            transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, step);

            yield return null;
        }

        Debug.Log("Slow turn completed.");
    }```
slender nymph
#

you aren't starting the coroutine correctly, use StartCoroutine to start it, calling the method normally just makes it run to the first yield

charred heart
hexed dune
#

Thank you. I will try that

swift crag
#

StartCoroutine does immediately call MoveNext on it

#

so it looks like it runs to the first yield

hexed dune
slender nymph
swift crag
slender nymph
#

huh, TIL. seems it's a common misconception about how methods that return IEnumerator work, but you're absolutely right it won't actually do anything until MoveNext is called
https://dotnetfiddle.net/ZS2dYB

swift crag
#

but, no, that wasn't the case

tender stag
#

im turning off gravity on my player

#

and how do i make him not be affected by other objects falling

#

like the y position

#

without freezing the y position

tender stag
#

pretty much i dont want other forces of other objects acting on my player

#

without making it kinematic

eternal needle
# tender stag without making it kinematic

You could try assigning to the velocity every fixed update to keep the value what you want it to be, except I believe objects will still move you slightly due to depenetration

slender nymph
cosmic dagger
#

Some irregular movement will occur if multiple objects keep hitting it . . .

tender stag
#

like just the bit of getting into it

#

and out

slender nymph
#

that isn't really an explanation of why you want to not freeze the Y axis

honest vault
feral oar
queen adder
#

This is a really simple shader question, though technically not a programming issue the other channels have not been helpful. So, this is textmeshpro appearance after changing the stencil settings to

Ref 1
Comp Greater
Pass Replace

then i added (second picture) if (c.a == 0) discard; in the pixel shader, however its pretty choppy, i think due to the anti aliasing being applied on per character basis? i dont know how to get good blending here. i've been trying for weeks but i think it's a simple solution.

slender nymph
queen adder
#

I think the problem is the stencil settings skipping any pixel which has already been set, but i think i have to have some sort of alpha threshold:(

slender nymph
thorn holly
#

how do I check what the current scene is?

cosmic dagger
thorn holly
#

sorry

cosmic dagger
#

Searching is always the first thing to do . . .

honest vault
#

even tho i have got exit time off

cosmic dagger
honest vault
lusty flax
#

will this have any effect on my game

slender nymph
#

you may end up with some issues where you think you are using one when you're really using the other in the code. so it's usually best to use a different name

cosmic dagger
lusty flax
#

(right now I am only using my charactercontroller)

cosmic dagger
#

A warning and an error are not the same thing . . .

lusty flax
#

because I'm getting this weird error and I don't know why (when trying to build)

honest vault
teal viper
lusty flax
#

the build fails

teal viper
lusty flax
#

but i dont know what these are

#

and before i ignored them because they did not affect the game

#

i fixed it

radiant frigate
#

okay so i have two enemies each one with a different movement script since i want to change it a bit, my problem is that if i write a public gameobject called player (so they know which element to move towards) on both of them it gives me an error, i´ve tried to do both of the gameobjects private but it still gives me the error

#

what am i missing?

#

okay i solutioned it

#

since i was literally doing copy paste for the base of the script i also replaced this so it had the same name as the other one

#

what a smart fella that i am (im not)

covert sinew
#
    public void MoveListEntry(List<Type> _list, Type _type, int _oldIndex, int _newIndex)
    {
        Type _listEntry = _list[_oldIndex];

        _list.RemoveAt(_oldIndex);

        _list.Insert(_newIndex, _listEntry);
    }

Will this work for what I'm trying to use it for? (Moving an entry from a list provided from one index to another)

queen adder
#

below is a regular TMP text added to the scene on a screen space canvas, above is the same exact tmp text but rendered to render texture and shown in a raw image, why so different?

#

why is there a saturated blue on the text in the render texture, when its supposed to be plain white

radiant frigate
#

can i use floats and ints to validate a while loop?

radiant frigate
#

true

summer stump
#

And remove the float

radiant frigate
#

i wrote float cuz "patata" doesnt exist

#

i just was testing if i could use it

summer stump
#

Not inside the while condition

#

But yeah, of course you can use floats and ints for conditions

#

Same as an if statement or any conditional

radiant frigate
#

okay and this is more a math question than coding i think but i have a form of calculating the angle towards the game object that i want it to follow

#

and i want to make the enemy stop once it reaches x amount of distance

#

since im not calculating the distance but rather the angle i need to calculate the distance

#

but i forgot how to do that :/

summer stump
#

This is 2d I guess, right?

radiant frigate
#

yep

#

so vector2.Distance and then i write this: (player.transform.position.x - transform.position.x, player.transform.position.y - transform.position.y)

summer stump
radiant frigate
#

makes sense

#

distance is a 1 variable thing right?

#

not x and y

#

only the distance

#

as for example
distance = p
p = 15.6

summer stump
radiant frigate
#

exactly what i needed

#

noice

#

ty!

covert sinew
native seal
#

right now im creating all my data in a static class with static readonly dictionaries, is this a fine way to do it?
for example, all the tiers for each stat along with its weight, etc that can roll on an item

radiant frigate
native seal
#

not new

#

Vector2.Distance is a function that returns a float

summer stump
radiant frigate
#

and then i write again player.transform.position - transform.position right?

native seal
#

just remove "new"

summer stump
covert sinew
#

I'm not sure what I'm doing wrong here. it's asking for a List and a Type, and I tried two different ways to provide it, but it's throwing errors for both. I'm not sure what it wants here.

wide vault
#

How do I improve my code architecture

radiant frigate
#

if not it gives me an error

native seal
summer stump
eternal falconBOT
slender nymph
teal viper
radiant frigate
summer stump
#

Oh, missed that minus sign

covert sinew
slender nymph
radiant frigate
#

OH

radiant frigate
native seal
#

then just swap the indicies?

radiant frigate
#

kewk

#

no i just need to remove the minus sign

wide vault
radiant frigate
#

and then it compares the distance between transform.position and player.transform.position

summer stump
# wide vault Why

Because don't send screenshots of code 🤷‍♂️
That is the standard here
Your screenshot was awful lol

radiant frigate
#

or atleast i think so

native seal
radiant frigate
#

yeah it was the minus sign

#

kewk

feral oar
native seal
radiant frigate
#

yep

#

thats why i wrote it again

native seal
#

sorry, didnt see that you had the minus

radiant frigate
#

cuz my dumb ahh forgot the minus

feral oar
#

i’m assuming your question was how to make it more readable

summer stump
radiant frigate
native seal
#

gdl.space is super good

radiant frigate
#

i used it once and it worked pretty well

feral oar
#

i think my personal fav is paste.ofcode

radiant frigate
#

ig all would have worked since it was like 30 lines of code

#

but still

feral oar
#

i like being able to select the language

summer stump
feral oar
#

oh word? i think i just started with gdl.space and then did paste.ofcode. i must have missed it on the first one

#

i think i also favored the second because i could edit it after creating a link. i remember being unable (or just missing how) with the first one

wide vault
feral oar
#

its not the practice here even if it were

native seal
feral oar
#

its disruptive just sending screenies

summer stump
#

Can barely read any of it

wide vault
#

👍

#

I'll send what bot said

feral oar
#

i love the three people reacting no that haven’t even mentioned anything

radiant frigate
#

i have no clue if its better but lets make it 4

#

xD

feral oar
#

i’ll make it five

radiant frigate
#

idk what i did but my game explodes whenever i start it

#

i think i messed up big time

#

kewk

feral oar
#

do it return any error messages?

radiant frigate
#

no it just freezes

#

whenever i enter play mode it freezes

slender nymph
#

i'd guess infinite loop

radiant frigate
feral oar
#

i agree. i’ve only ran into that issue when i messed up a loop somewhere

slender nymph
#

yep, infinite loop because you never change the value of distance

#

but also why is that a loop

radiant frigate
#

oh so i have to write the formula inside the loop

feral oar
#

you need to update distance for it to stop looping. but also why have it as a loop? would an if statement not suffice?

radiant frigate
#

i guess so

frosty hound
#

Just put it in your update function, there's rarely a usecase for while loops during runtime.

summer stump
frosty hound
#

Unless you're generating something. But for gameplay logic like this, your update function is yourloop.

feral oar
radiant frigate
#

an if works

summer stump
radiant frigate
#

ohi wanted to paste a gif :((

summer stump
#

Please do not do that

radiant frigate
#

alrighty!

#

srry

feral oar
#

maybe you could try looking up when a while loop would be a good tool. then you’ll have an idea of how to experiment with it

radiant frigate
summer stump
radiant frigate
#

yeah i have one

#

for instantiating enemies

honest vault
#

whys the car pink lol

frosty hound
#

Beacuse you're using a shader that isn't compatible with your chosen pipeline.

#

Or you're using a shader that has an error in it.

honest vault
#

how do i change that shader

frosty hound
#

Also, not a coding question.

honest vault
frosty hound
#

But you'd do well watching a basic tutorial on how materials in Unity work.

honest vault
#

done

honest vault
frosty hound
#

I can't imagine a world where something basic like that isn't covered in some video, yeah

#

Given that beginner tutorial series are the majority of what make up Youtube/Unity videos

wide vault
#

I feel like most of coding is functions, variables and class, if Statements and loops. I feel like I can create my entire program with these but I see people using events, lambda, return keyword, switch Statements functions and a couple of other concepts. When do you need these other concepts?

carmine turret
#

So, Im using a distance joint for my grappling hook, whats the best way to figure out what direction the player is traveling in for when I break the grapple? (2d btw)

teal viper
#

Which is programming all about.

swift crag
#

I guess you could completely replace it with the out keyword

teal viper
swift crag
#

C# allows you to treat functions like any other object (hence delegate types)

#

this enables higher-order programming, where you compose functions together to get more complex behavior

teal viper
swift crag
#

by "switch statement functions" do you mean something like this?

#
public float GetSomething => mode switch {
  Mode.Off => 0f,
  Mode.On => 1f,
  Mode.Broken => -1f
};
#

because that's a switch expression

wide vault
summer stump
#

I mean, events are super powerful and important. They can be used all the time

slender nymph
swift crag
#
public float Constant => 1f;
#

a get-only property that returns 1

wide vault
slender nymph
#

only the low quality beginner stuff

summer stump
swift crag
#

it's a nice way to write methods and properties that fit into a single expresison

#
public override bool CanEnterState => base.CanEnterState && CanEnterWithTarget(candidateTarget);
#
public override bool CanEnterState => base.CanEnterState && Vector3.Distance(interactor.InteractPoint.position, interactable.TargetTransform.position) <= range;

on the ragged edge of "line too long"

wide vault
#

Jumping from that beginner level to more advanced I find difficult

outer light
#

hi

summer stump
outer light
#

AETHONOSITY

summer stump
#

Practice, and wanting it

outer light
#

HI

summer stump
#

Hi

outer light
#

😄

#

anyone have a simple game idea

slender nymph
wide vault
outer light
#

no

outer light
bitter bramble
covert sinew
#

My inventory system doesn't have set slots, but creates and destroys them as needed, so it needed something more complex than what you provided.

queen adder
#

where is the navigation tab in unity so i can bake like the walkable areas?

teal viper
small mantle
#

Why can't you just add a variable? This doesn't work: cs void Update() { cooldownClock + Time.deltaTime; }
But this works? cs void Update() { cooldownClock = cooldownClock + Time.deltaTime; }
Can someone explain why this is the case, please?

summer stump
small mantle
summer stump
#

Yes

small mantle
#

It gives an error.

summer stump
covert sinew
summer stump
small mantle
summer stump
#

But just adding them, the compiler wouldn't know what to set the result to.
Assignments use =

#

Think it through, and that will explain why you can't

#
void Update() {
        cooldownClock += Time.deltaTime;
    }
small mantle
summer stump
small mantle
summer stump
#

I thought =+ was a syntax error. Interesting

#

All I was saying is that THIS makes no sense, because there is no = sign

void Update() {
        cooldownClock + Time.deltaTime;
    }
#

So the parser isn't trying to assign something

small mantle
#

Okay, thank you for the help!

summer stump
#

You COULD make a language that does it, or perhaps overload the + operator, but it is just not default in c#
That is just an arbtrary choice by microsoft

radiant frigate
#

the way of calling another script was creating a public class inside the script i wanted to call the other with right?

radiant frigate
#

lemme try to show it

summer stump
#

You do NOT need to have the classes in the same file to call them

#

In fact, they should NOT be in the same file

faint osprey
#

Im making the camera shake on my virtual camera when the player moves right or left for a bit with this coroutine ```private IEnumerator CameraShake(string direction)
{
if(direction == "Right")
{
while(true)
{
Debug.Log("woking");
VC.m_Lens.Dutch += 1;
yield return new WaitForSeconds(0.01f);

            if(VC.m_Lens.Dutch == 10)
            {
                break;
            }
        }

        while(true)
        {
            VC.m_Lens.Dutch -= 1;
            yield return new WaitForSeconds(0.01f);

            if (VC.m_Lens.Dutch == 0)
            {
                break;
            }
        }
    }

    if(direction == "Left")
    {
        while (true)
        {
            VC.m_Lens.Dutch -= 1;
            yield return new WaitForSeconds(0.01f);

            if (VC.m_Lens.Dutch == -10)
            {
                break;
            }
        }

        while (true)
        {
            VC.m_Lens.Dutch += 1;
            yield return new WaitForSeconds(0.01f);

            if (VC.m_Lens.Dutch == 0)
            {
                break;
            }
        }
    }
}```

the problem is because its a coroutine if i move right or left too quickly the while loops dont run properly because the "dutch value" is reaching the set point for it to break. how would i go about fixing this

radiant frigate
#

okay wait lemme reword it

covert sinew
radiant frigate
#

how can i call a function inside script b while im inside script a

covert sinew
#

It's my personal preference to overexplain my code in comments, since I have a habit of forgetting how programming works, and how I did things, and what the hell my code is doing.

teal viper
summer stump
radiant frigate
radiant frigate
#

ty ill check that out

covert sinew
# teal viper I don't need excruciating details. Just an overview to know what I'm gonna read ...

It's an Inventory System which uses Lists of Inventory Objects, spawning and deleting inventory slots as needed to hold everything in it, rather than having discrete slots

Today, I completed the following functions:

Add Items
Add Items to Specific Slots
Remove Items (of type)
Remove Items from specific Slots (of optional required type)
Move Items (the most complex piece, which can handle stack splitting and merging and all that jazz)

teal viper
teal viper
faint osprey
teal viper
#

Ah, you shared it previously. Didn't notice.

teal viper
faint osprey
teal viper
# covert sinew It's up above there.

It looks fine aside from maybe I wouldn't make it an SO. Also, what you call an override is actually an overload. Method override is when you override a method from a base class.

covert sinew
native seal
#

also SO's work well for an inventory, im doing the same thing

covert sinew
teal viper
native seal
#

you still need to define specific slots, I don't understand how that works out

teal viper
covert sinew
# teal viper You can save plain classes as easily. You don't need structs. And you can have a...

It's been over a year since I last worked on my save and load system, but it nearly broke me, man. Saving and loading an inventory, from everything I researched on the matter, was a terrifying tarpit of insanely complex data structures, that had to be convverted to and from one another in ways I simply am not a good enough coder to understand.

Using SO's is absolutely easier than trying to save and load Classes directly. Like, I'd say at least 50% easier.

covert sinew
teal viper
covert sinew
covert sinew
#

I just directly serialize/deserialize the SO

teal viper
covert sinew
#

No they aren't.

teal viper
#

You don't need a plugin for it.

#

Yes they are

native seal
#

dlich hes talking about directly saving the SO to json

#

it wont work

teal viper
#

If they weren't, you wouldn't be able to create instances of it in the editor.

covert sinew
#

Last time I worked on it, SO's were explicitlly not fully compatable with saving to JSON, yeah

native seal
#

I believe im making a game very similar to him and have solved this issue myself

native seal
#

the only reason I use SO's for inventories is to be able to easily plug it in to anything

#

instead of holding a reference singleton or whatever

covert sinew
teal viper
#

You probably misunderstood something about serialization.

native seal
#

dlich you are misunderstanding him i believe, you cannot directly serialize an SO to Json

covert sinew
#

nine months ago, I had to install a specific plugin to Serialize SO to JsON

native seal
#

you would have to serialize the data in it and then rebuild it

covert sinew
#

They were NOT serializable to JSON.

radiant frigate
#

what does an instance of an object mean?

native seal
covert sinew
native seal
#

thats why I made my own save system

covert sinew
#

Yeah. I took the other angle, and just used a plugin that MAKES them serializable to json

teal viper
strong moth
#

Is this an excessive amount of assembly definintions or nah

teal viper
teal viper
strong moth
#

no problems

#

but some of these asmdefs are for a single script

teal viper
native seal
#

nothing was saved

radiant frigate
#

i think i am refering to something

#

or am i doing it the other way

radiant frigate
#

and i should reference from the other script around?

native seal
teal viper
teal viper
radiant frigate
#

the line 40 (the first image)

teal viper
#

What line throws?

native seal
teal viper
native seal
teal viper
rich adder
radiant frigate
#

thats all it does

native seal
radiant frigate
#

i want to check if the bool shooting in the other script is false or true

teal viper
# radiant frigate

That doesn't answer my question. What are the reference type object on that line?

rich adder
#

why are you serializing the SO anyway ?

radiant frigate
#

srry im not english native so i dont know exactly what you mean by reference type

teal viper
rich adder
#

generally they are not meant for mutable data so not sure why you'd serialize that instead of a mutable poco on the SO itself @native seal

teal viper
radiant frigate
#

alright

cosmic dagger
native seal
#

the reason I use an SO for the inventory is just ease of use

#

being able to plug it into anything

rich adder
#

Imo You should not be using it for mutable data

native seal
#

it works very well

#

ive heard that many times and I don't really see why it matters

teal viper
glossy compass
#

does anyone have a good free tutorial series or course on learning C# for unity?

eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

glossy compass
# rich adder !learn

yeah but that focuses on overall? is there one that focuses primarly on just programming?

native seal
radiant frigate
cosmic dagger
glossy compass
rich adder
radiant frigate
teal viper
glossy compass
cosmic dagger
radiant frigate
#

so answering your question im not doing any reference

#

right?

#

and thats the problem

teal viper
# radiant frigate right?

Then you wouldn't get the error.
Go through all the identifiers(variables) on that line write down their types.

radiant frigate
#

identifiers ?

#

ohh

#

its just a bool

teal viper
#

Names of variables

radiant frigate
#

and its value type

teal viper
#

Look again.

rich adder
cosmic dagger
teal viper
radiant frigate
cosmic dagger
#

Bingo . . .

radiant frigate
#

and a class is a reference type?

native seal
#

c# generally abstracts all the stack/heap stuff

teal viper
radiant frigate
#

okay let me read the error now

teal viper
radiant frigate
#

object reference not set to an instance of an object

#

im kinda clueless now

rich adder
#

you don't have an instance in your declared variabe

teal viper
radiant frigate
#

nope

rich adder
#

so you cannot use something thats missing/doesnt exist

teal viper
native seal
#

imagine your program recieving a blank blueprint with nothing built yet

#

making an instance of an object "builds" that blueprint

#

a class definition is just a blueprint

radiant frigate
teal viper
radiant frigate
#

nope

teal viper
#

Well, then you probably should go over it first. It's crucial to understand to be able to work with C# and many other languages.

radiant frigate
#

i know so little (type of variables, how to mess a bit with objects components, loops, switch and i think if counts as a loop but basically thats all)

native seal
#

digital post your full code in gdl.space

radiant frigate
#

omw

rich adder
teal viper
#

I'd recommend learning the mentioned things before proceeding.

teal viper
radiant frigate
native seal
radiant frigate
native seal
#

then they can reference the solution and figure out what went wrong

teal viper
#

It's one way to learn one specific thing and have a broken understanding of the whole thing.

radiant frigate
#

b4 yesterday i had no clue how to use loops or switchs

rich adder
native seal
#

digital do you understand the concept of classes

#

also im not "spoon-feeding" the answer, I want to see what was going wrong

radiant frigate
#

a class is like the script?

native seal
#

class in a general sense

#

a script can have multiple classes in it

rich adder
cosmic dagger
radiant frigate
#

a reference type ?

teal viper
#

It happens to be a reference type, yes.

native seal
#

for example, a Vector3 is a type

rich adder
#

its all explained in the link I've sent

native seal
#

i doubt he's going to understand that if he doesn't understand basic loops

radiant frigate
#

i dont know how to read all that

rich adder
cosmic dagger
radiant frigate
#

i understand that i can somewhat ignore all the system. and whatever remains takes part of either reference/value type

radiant frigate
rich adder
#

dont worry about that now

native seal
#

imagine that value types typically hold very basic data (including primitive types such as character, int, etc), reference types typically hold more complex data such as your class

cosmic dagger
rich adder
native seal
#

"typically"

#

but yes

radiant frigate
karmic escarp
#

is there a way to reference objects without having them be included as a reference in a script or be part of a trigger? trying to put together a sort of tile lighting system

native seal
#

in c#, when you pass a "value" type into a function, anything done to it will not change the variable outside the scope of that function, this is not true for reference types since you are passing the same "pointer" that points to the reference type

cosmic dagger
rich adder
radiant frigate
rich adder
radiant frigate
karmic escarp
native seal
rich adder
native seal
teal viper
#

They still don't understand the concept of types and instances I think. They won't be able to understand that explanation.

cosmic dagger
native seal
#

compared to myFunction(myClass class)

#

the "address" of your class is passed into the function

#

the function can then go and modify it directly

#

while an int, a value type, is just copied over

radiant frigate
#

but i dont want to modify something from outside the function i just want to check if the bool is true or not

#

maybe im mixing things up

native seal
#

im explaining the general difference between value types and reference types

radiant frigate
#

yeah true

#

kewk

native seal
#

when your program asks for "multiShotEnemyShooting.shooting" it looks for the address and cant find anything

cosmic dagger
teal viper
native seal
radiant frigate
native seal
#

a value type can never have a null refereence because the value is the thing itself

#

not a pointer to something

#

since your script is a monobehavior, you need to populate "public MultiShotEnemyShootingScript multiShotEnemyShooting;" on your gameobject

teal viper
teal viper
#

I'd suggest googling Object oriented programming and understand that concept first.

native seal
#

when you declare public MultiShotEnemyShootingScript multiShotEnemyShooting at the top of your script, you are promising to give it a built "object" that follows the blueprint of your type MultiShotEnemyShootingScript

cosmic dagger
native seal
#

if you don't fulfill that promise, you will get that error

#

either drag that script into that slot in the inspector, or get the component in void Start

#

by using GetComponent

#

assuming your other script is also a monobehavior

radiant frigate
native seal
#

what do you mean localize?

radiant frigate
#

lemme show you (my keyboard doenst have the > and the other way around symbols so i cant write the exact thing here)

#

rb2dEnemy = GetComponent<Rigidbody2D>();

#

smth like this

native seal
#

yes

radiant frigate
#

but instead of rigidbody

#

script

native seal
#

yes, assuming your script is a monobehavior that is also on the same gameobject

radiant frigate
#

yep

native seal
#

you did the same thing when getting the player

#

player = GameObject.FindGameObjectWithTag("Player");

#

it also gets a reference to the player gameobject

radiant frigate
native seal
#

no, not necessarily, it depends on how you made your class

radiant frigate
#

more than create a gameobject creating a variable that is a gameobject

native seal
#

and what functions it serves

radiant frigate
#

what is the difference between monobehaviour and whatever else types there are?

native seal
#

monobehavior is a class that unity has made that your class can inherit from

#

research more into object oriented programming to understand inheritance

teal viper
#

If you answer the next question, you would be able to solve your issue easily:
What is multiShotEnemyShooting and does it exist on line 40?

native seal
#

in simple terms, inheriting monohevaior allows you to place the script onto a gameobject and use the premade functions Start and Update

radiant frigate
#

i think

teal viper
radiant frigate
#

yep

#

i could have done it earlier

teal viper
#

Check the tutorial again and see where they assign it.

radiant frigate
#

i just forgot completely

#

kewk

native seal
#

if multiShotEnemyShooting wasn't a monobehavior, you would create a new one by using the "new" keyword

radiant frigate
teal viper
radiant frigate
#

nope im writting on my own

native seal
#

however, your class needs a constructor so that the program knows how to fill in the variables in your class

#

if you were to use "new"

radiant frigate
#

messing with things here and there and trying to get problems so i can learn

rich adder
#

make a game inside C# console application, You'll be a c# chad in no time

radiant frigate
#

not the best way of learning but each day i assign myself something new to learn and to try and give an use to it

teal viper
# radiant frigate nope im writting on my own

Ok well, I really suggest you go and learn the basics, starting with OOP. Because you're risking being ignored by people here in the future. At least by people that support proper learning methods.

native seal
#

i dont believe telling a beginner read the documentation is the best solution

teal viper
rich adder
native seal
#

yes, but when he doesn't understand loops, i don't think it would help

teal viper
rich adder
radiant frigate
#

docs are straight up confusing since sometimes you get no context of things and use fancy words that with my current level i cant understand

native seal
#

sure

rich adder
native seal
#

be VERY warey of unity tutorials please

rich adder
#

the docs has a list of all the keywords used in c#

radiant frigate
#

its not just the words

radiant frigate
native seal
#

cautious

radiant frigate
#

i dont watch them

cosmic dagger
radiant frigate
#

i watch tutorials of c#

native seal
rich adder
#

The microsoft site isn't just "docs"

radiant frigate
rich adder
#

they are learning lessons

native seal
#

ah i see, my bad

#

i didnt realize what you linked

rich adder
#

it explains everything

native seal
#

yes very good

rich adder
#

they have videos too

radiant frigate
#

those types of videos

#

i dont like unity tutorials

#

since they just give you the solution and usually dont explain anything at all

rich adder
#

learning c# through unity is more diffcult

native seal
#

that isn't even the problem

#

unity tutorials give very bad architecture advice, such as making every field public

#

i recommend not doing that

#

a field should default to private and only be public if theres a very specific reason for it to be public

radiant frigate
#

i tend to write public if i want it to be changeable from other places or private if i only want to mess up with it from inside the script

cosmic dagger
native seal
native seal
#

since you will be able to put restrictions on it and whatever other logic you want associated with changing that variable

radiant frigate
#

so making everything private and whenever i want to change a variable make a public function that manipulates it specifically?

native seal
#

yes

#

if your class is a monobehavior, you can add [SerializeField] before your variable to allow it to still be changed in the inspector

#

it is very useful

radiant frigate
#

yeah i have that on all

#

even tho they are public

native seal
#

they should be [SerializeField] private instead

radiant frigate
#

i usually write public and once i know i dont want to use them in other place change it to private

native seal
#

do it the other way around

#

private and only public for a specific reason

radiant frigate
#

always private unless i want it to be public

#

aight

native seal
#

90% of my variables are private

radiant frigate
#

that will take out possible problems from the equation right?

cosmic dagger
native seal
#

yes ^

#

if your project is small you wont have many problems

radiant frigate
#

i had a deja vu of this

native seal
#

but when you scale things, you will have problems

radiant frigate
native seal
#

if 20 things are changing your public variable

radiant frigate
#

didnt think about it but it makes sense

native seal
#

yes, since you can add whatever other logic in that function to restrict those other 20 things trying to change it

#

for example, not allowing it to go below 0

#

or something like that

radiant frigate
#

yeah

#

the same thing happend 3 days ago

#

i spend like 2 hours trying to understand something that i already knew

#

but since im a dumb ahh i forgot smth and just messed up

native seal
#

we all start somewhere

radiant frigate
#

this should be it right?

native seal
#

yes, make sure that class is added as a component on your gameobject

radiant frigate
#

it is

native seal
#

similar to rigidbody, which is just another class that unity has already made

radiant frigate
#

because i forgot to add it

rich adder
radiant frigate
#

but i added it and it kept displaying so i came here asking if someone knew what was happening

native seal
#

either one is fine really, but since unity gives you the ability to drag and drop it cleans up code

radiant frigate
native seal
#

prefabs are completely different

radiant frigate
#

yep they are

native seal
#

nothing to do with that

rich adder
#

and yes Prefabs cannot reference scene objects

radiant frigate
#

yep

#

had that problem with the "bullets"

#

since they were a prefab

rich adder
#

Why do your buellts have a reference to scene objects..

#

thats poor design

radiant frigate
#

the enemies*

rich adder
#

why ?

radiant frigate
#

for following the player

native seal
#

for prefabs you generally get the references at start

static cedar
#

Real.

native seal
#

if its a gameobject in your scene

rich adder
#

no for prefabs you pass the dependency via whoever instantiates it

native seal
#

that works too

radiant frigate
#

i have this written in the enemy prefab

rich adder
#

Everytime you spawn an enemy you're doing a Find

#

instead of getting the same reference from the thing that spawns it

radiant frigate
#

hmmm i get what you are saying but idk how to execute that

cosmic dagger
# radiant frigate even tho they are public

Having [SerializeField] on a public variable is redundant. [SerializeField] allows a private field to appear in the inspector. If your field is public, by default, it'll appear from the inspector . . .

radiant frigate
radiant frigate
#

so im just left with the fields and messing around to find the number i want

cosmic dagger
rich adder
# radiant frigate didnt know you could do that

the object in the scene that spawns holds the reference to say the player, then once its stored on awake once every time you Instantiate you can pass player via a Method like "Init()" inside enemy that gets that reference

radiant frigate
radiant frigate
#

i guess i wont be needing a video

rich adder
#

passing objects/data through methods should be one of the first basic concepts you should learn

#

you'll probably be doing it A LOT

radiant frigate
#

yeah not just probably but nearly 90 % of my scripts have the walmart version of that

#

kewk

rich adder
#

it looks intimidating at first but it gets simpler with time , just keep doing it and eventually "it sticks"

radiant frigate
#

sure will

cosmic dagger
radiant frigate
#

XD

#

no need to explain

#

i will learn it myself

#

but first i wanna finish with the new type of enemy

rich adder
radiant frigate
#

BHAHHAAHHAHAHAAHAHAH

#

srry im from spain

#

we dont have target nor walmart

rich adder
#

You guys have walmart but not target?

#

oh

radiant frigate
#

nope but walmart is famous asf

#

and also a lot of memes happen inside there

rich adder
#

amazing lol

radiant frigate
#

omg im dumb

#

BHHAHAHAHAHAHA

#

target version

#

makes complete sense

#

since my problem has to do with targetting a gameobject i got confused asf

#

KEWK

#

this made my day

#

anyway imma go eat havent eaten in like 30 hours or so

#

ty for the help!

cosmic dagger
radiant frigate
#

i know about target but my mind just ignored it 🤣

timid badger
#

Hello! I'm remaking breakout in unity and I needed to save my highscore so when I restart the game, it saves the highscore. With what I have currently, the score and highscore count up at the same rate but I'm not really able to get it to save.

#

this is what I have and I know it's wrong but I'm not quite sure how to make it work either because I've tried all kinds of youtube tutorials

#

but my score is counting up in another script which is throwing me off

teal viper
#

It would be better to assign the string in the field initializer or serialized field and use that variable everywhere else.

#

In order to avoid human errors.

timid badger
#

Yeah.. what I'm doing is for an assignment and my teacher isn't expecting a serialized field. I just wanted for the highscore to save when I exit playmode. I reset my scorecount when i run out of lives so that I do manage to keep my highscore when I restart in the same play session

#

I just don't quite understand how I can save my highscore using the playerPrefs because that is what I saw in a lot of youtube vids about how to save highscores

teal viper
#

And my suggestion is:

private string highscoreKey = "HighScore";
//When using player prefs:
PlayerPrefs.GetInt(highscoreKey);
teal viper
# timid badger

What string are you using when getting and setting the value in player prefs? Is it the same string..?

timid badger
#

it probably was, i just removed the strings and it works the same as it did before. i think i was referencing from another project but I ended up changing my values to static ints so that means I don't need the strings right?

teal viper
#

Share the script properly, so that I can copy paste it.
!code

eternal falconBOT
timid badger
#
public class UIManager : MonoBehaviour
{
    public TMP_Text scoreText;
    public TMP_Text livesText;
    public TMP_Text highScoreText;
    public static int scoreCount;
    public static int highScoreCount;


    public Ball playerData;



    public void Start()
    {
        if (PlayerPrefs.HasKey("HighScore"))
        {
            highScoreCount = PlayerPrefs.GetInt("HighScore");
        }
    }

    public void Update()
    {
        if (scoreCount > highScoreCount)
        {
            highScoreCount = scoreCount;
            PlayerPrefs.SetInt("Highscore", highScoreCount);
        }

        scoreText.text = "Score: " + scoreCount;
        livesText.text = "Lives: " + playerData.lives.ToString();
        highScoreText.text = "Highscore: " + highScoreCount;

    }

}
teal viper
#

I'd prefer if you shared it as Large Code Blocks, since I can't copy specific parts on mobile like that...

timid badger
#

oh crap sorry! give me a sec.. thx for helping me

teal viper
#

Nevermind, I did myself.

#

Does the string parameter here:

PlayerPrefs.HasKey("HighScore")

Equal to the string parameter here?

PlayerPrefs.SetInt("Highscore", highScoreCount);
```@timid badger
radiant sail
#

anybody know how i can get similar gun interpolation to this when looking around
ive searched up what type of easing it is (Elastic out ease)
but i cant figure out how to implement it into my code and everthing i try dosent work so i end up just resetting it back to this

public GameObject gunPos;
public Vector3 TargetRot;
TargetRot.x = Mathf.Lerp(TargetRot.x, gunPos.transform.localRotation.x -Input.GetAxis("Mouse Y"), 5 * Time.deltaTime);
TargetRot.y = Mathf.Lerp(TargetRot.y, gunPos.transform.localRotation.y + Input.GetAxis("Mouse X"), 5 * Time.deltaTime);
gunPos.transform.localRotation = Quaternion.Euler(TargetRot);```
#

i remember in my old game i accidentaly recreated it by like doubling the rotation on a second object but i dont remember how i did it

timid badger
desert flume
#

I wanna spawn a prefab in a random place (ive alr done that)

#

but i want to make it so if the random place is already occupied by a certain object with a certain tag

#

then it would choose another random place

#

how would I get a BoxCollider2D for the random place

timid badger
desert flume
#

i mean, it really isnt possible since that place is a coordinate

#

not an area

#

overlap point nvm

keen dew
#

Do you see any difference between "HighScore" and "Highscore"?

timid badger
keen dew
#

wtf

timid badger
#
   public void Start()
   {
       if (PlayerPrefs.HasKey("HighScore"))
       {
          
           highScoreCount = PlayerPrefs.GetInt("HiScore");
       }
   }
keen dew
#

No, the problem is that they're different. They must be the same obviously.

timid badger
keen dew
#

Yes, but not when you save the value

gaunt ice
#

consider using private static readonly string as your key not some string hardcoded into

timid badger
#

love you all

#

i can sleep tonight now

teal viper
timid badger
teal viper
radiant frigate
#

i cant convert a Vector3 into a quaternion, how can i make it rotate ? here is my aproach and it didnt work

eternal needle
radiant frigate
#

what is an eulerAngles?

#

nvm imma check a video explaining it since it seems a dense topic

radiant frigate
#

im not learning allat

#

xD

#

i´ve seen 3 videos of euler angles and one on quaternions and i dont understand a thing

teal viper
#

You don't need to learn quaternions. You just need to know that they're different and shouldn't be messed with manually.

radiant frigate
visual hedge
#

Okay onay

#

Not sure what was wrong with that though

timber tide
#

usually you can just use lookat with projectiles because you're probably aiming at some target anyway

radiant frigate
#

nope im making it spread in a clocksystem

#

each "2 hours direction " i want to shoot a bullet

teal viper
radiant frigate
#

i just want to rotate the z axis

timber tide
#

try that one

radiant frigate
#

but i want to rotate the z axis

timber tide
teal viper
radiant frigate
#

yeah srry

teal viper
#

What are you trying to do actually?

radiant frigate
#

i want to rotate him based on the z axis

teal viper
#

We say "rotate around a x/y/z" axis"

timber tide
#

AngleAxis rotates it around the axis you provide it so experiment with it

teal viper
#

Imagine an axis as a line going through your object. You rotate it around that line

radiant frigate
#

thats why i want to rotate around the z axis

teal viper
#

Now the question is, is it the local z or the world z?

radiant frigate
#

so each bullet has his own direction

#

world z

#

oh no

#

the local z

teal viper
#

There's a Transform.RotateAround method that can rotate the object around any point/axis.

radiant frigate
#

im going to investigate about that then

#

ty!

radiant frigate
#

since the only axis that im using is the z

visual hedge
radiant frigate
#

it says i cant use "eulerAngles" for that

#

then i get the problem i had at the start

#

that was my first approach

#

but it tells me that i cant transform a vector3 into a quaternion

visual hedge
#

Should the bullet rotate or just spawn at desired angle?

radiant frigate
#

spawn at a desired angle

visual hedge
#

Then what's the problem with (bullet, transform.position, Quaternion.Euler(0, 0, zRotation); ?

teal viper
teal viper
radiant frigate
#

it gives me an error but its traduced poorly to spanish

#

Non-invocable member 'name' cannot be used like a method.

visual hedge
#

Is zRotation variable a float?

radiant frigate
#

yep

teal viper
radiant frigate
visual hedge
#

Euler needs some using unity.System; ?

radiant frigate
#

i dont think so

teal viper
visual hedge
radiant frigate
teal viper
visual hedge
#

Nah, not error. The code

teal viper
# radiant frigate

What they mean here is that you can assign a value to transform.eulerAngles.

radiant frigate
#

so i should think of transform.eulerAngles as another variable?

#

and modify it outside ?

teal viper
#

Variable or property, yes.

#

You can check the documentation for it and see that it's not a method.

visual hedge
#

Cause pretty sure
'''cs
Instantiate(bullet, transform.position, Quaternion.Euler(0, 0, zRotation);
'''
should work

#

Damn

radiant frigate
#

if i remove the parentheses it tells me that i cant convert a vector3 into a quaternion

#

i readed the compile error

visual hedge
#

Ofc you cant.
Your zRotation should be
private float zRotation = 45f;

teal viper
radiant frigate
visual hedge
#

Then do it. I don't believe it gives error

teal viper
#

Check the Instantiate docs. The third parameter should be a quaternion