#💻┃code-beginner

1 messages · Page 445 of 1

ionic zephyr
#

Take for example Pokémon and the way the player interacts with PCs, Pokémon Nurses...

frosty hound
#

I mean, is that what you're making though? A 2D tile based game?

frosty hound
#

Then really the player should just be "examining" the tile in front of them to see if there's anything on it, and handling the results. You don't necessarily need to do zones or anything.

#

But again, depends on your game. If you want an NPC to have a (!) above their head when you're near them, that would be a trigger zone, vs another way to detect the player is actually interacting with them

#

It's not a one size fits all solution, you need to clearly define how you want interactions to work in your game.

ionic zephyr
#

the ones you need to press a key

hazy fiber
#

when collision boundaries for 2 moving objects controlled by the player are set (where both objects cannot bypass these boundaries)
how can i let a third object bypass the same boundaries?

ionic zephyr
rocky canyon
ionic zephyr
#

that should be placed on the player, right?

frosty hound
#

Yes, the player is reponsible for deciding that they've checked for something in front of them

rocky canyon
#

if its raycast u should raycast from the player.. trigger and stuff could be on the interactable object.. but still makes more sense for the player

ionic zephyr
#

what is the most accurate method?

#

I usually use boxcollider2D

rocky canyon
#

i cant say for 2d.. osteel might know

frosty hound
#

You could overlap with any shape. If you want to use that, just make sure it's smaller than the size of a tile, so you're not overlapping two interactions.

#

To be clear, overlap here means using the OverlapBox / OverlapCircle functions and doing it in code. Not actually using a physical collider.

ionic zephyr
frosty hound
#

That question doesn't make sense

#

What are you worried about?

ionic zephyr
frosty hound
#

Both will work, there is no better

#

However, if you just have an actual object that is moving with the player, you will have to manage the triggers

#

If you check with code (overlap box or circle), you can control when you actually care to check, such as once the player finishes moving to the next tile.

ionic zephyr
willow scroll
frosty hound
ionic zephyr
ionic zephyr
fickle stump
#

Actually i need help again... A statemanager is too advanced for me sadly ._.

#

can someone help me, but dumb it down very very much <-<

raw token
fickle stump
#

exactly

willow scroll
raw token
#

Excellent 👌. How do you handle the click events?

fickle stump
#

when you click a marker, the content of that marker should be loaded, all other markers disabled.

fickle stump
fickle stump
willow scroll
#

What is that you're struggling with here?

fickle stump
#

Where do i start

willow scroll
#

By making them UnityEngine.UI.Buttons?

fickle stump
#

So, I'm struggling with the context. How do i make them buttons? What does the => mean, whats a listener ._.

willow scroll
#

Do you know what UI Buttons are in Unity?

#

Add a Button component to them

fickle stump
willow scroll
#

Then why are you asking how to make them buttons?

fickle stump
#

i just realised how you meant it

#

i thought there's a way to code them as buttons

#

but i know what UI Buttons are

#

as long as u mean these

willow scroll
#

There is a way to code them as buttons, but Unity already provides a built-in one

#

There is no graphic

#

Attach an image too

fickle stump
#

if I'm adding an image, doesnt it cover everything else? doesnt it make sense to not have them as buttons

#

i mean to not have them have images

willow scroll
#

And you don't have it separated by those images?

fickle stump
#

oaky so

willow scroll
#

This... is bad

rocky canyon
fickle stump
#

this is a bit complexe to explain

rocky canyon
#

and make it transparent

#

(invisible button over ur main image)

willow scroll
#

Well, you should first consider making this whole photo a UI Image

fickle stump
# willow scroll This... is bad

the image you see is a brochure with AR Elements, you're palcing the AR elements on that brochure so the image has to be loaded

fickle stump
#

tehcnically?

fickle stump
#

AR_ImageTarget

raw token
#

Can we just see a screenshot of a marker object's inspector? 😅

raw token
# fickle stump AR_ImageTarget

So you can still do what sashok was describing. The only difference is where your marker object script handles a "click" you'll have it invoke a custom event.

public event Action<MarkerScript> OnClick;

public void OnMouseButtonUp() {
  OnClick?.Invoke(this);
}

(or similar)

Then the manager can subscribe to this event

private void OnEnable() {
  foreach (MarkerScript marker in Markers) {
    marker.OnClick += HandleMarkerClicked
  }
}

private void OnDisable() {
  foreach (MarkerScript marker in Markers) {
    marker.OnClick -= HandleMarkerClicked
  }
}

void HandleMarkerClicked(MarkerScript marker) {
  // ...
}

You can also do all of this without events at all - give each marker a reference to the manager and have them call the method on the manager directly when "clicked". But the event pattern is a little cleaner, and events are a great tool to have in your toolbox

hybrid geyser
#

is there any teachers for coding

#

because im only a newbie

frosty hound
#

You can hire someone online for that, but no, this server isn't a place for finding someone to tutor you.

#

There are lots of beginner resources online for that.

hybrid geyser
#

ok sorry for the misunderstanding

hazy fiber
summer stump
raw token
rocky canyon
#

has this ever been solved.. I have a rigidbody that moves w/ offset from camera.. (camera is attached to CC)

#

no matter what combination of interpolation or changing around update loops and stuff i can't get all of the jitter out

#

its better but not perfect 😢

ionic zephyr
#

how can I keep objects static while still wanting them to be detected with overlapCircle??

slender nymph
#

they only need a collider for that

slender nymph
rocky canyon
#

overlap detects colliders not rigidbodies

rocky canyon
#

which is child of my CC

#

w/ physics forces.. 1 sec

ionic zephyr
#

what? then I dont know why it doesnt detect it without a Rigidbody

rocky canyon
#
                // Apply lift force to counteract gravity
                Vector3 lift = direction * liftForce * Time.deltaTime;
                pickedObject.linearVelocity = new Vector3(pickedObject.linearVelocity.x, lift.y, pickedObject.linearVelocity.z);

                // Clamp the y position to ensure it does not exceed maxHeight
                Vector3 clampedPosition = pickedObject.position;
                clampedPosition.y = Mathf.Clamp(clampedPosition.y, 0, maxHeight);
                pickedObject.position = clampedPosition;

                // Update the target position
                targetPosition = followPosition;
            }```
ionic zephyr
rocky canyon
#

imma try late update

ionic zephyr
slender nymph
# ionic zephyr
  1. !code 👇
  2. prefer TryGetComponent over two separate GetComponent calls just for one of them to be a null check
  3. a rigidbody does not make it any more likely to be found using a physics query, the query will find colliders that don't have a rigidbody justfine
eternal falconBOT
rocky canyon
#

i cant really tell a difference.. it might be a little better

ionic zephyr
rocky canyon
#

1 sec, i'll try fixedupdate now lol..

slender nymph
rocky canyon
ionic zephyr
#

this tryes to get a component of interaction

slender nymph
#

yes that was the only part of the code we could actually confirm the validity of

ionic zephyr
#

and then start a method which is in that component of other gameobject

#

which uses a UnityEvent

slender nymph
#

show 👏 the 👏 code 👏

rocky canyon
#

i give up, fixedupdate looks jittery too

#

guess i'll just not use a lift mechanic on my CC.. i'll instead reserve it for my Kinematic boi

ionic zephyr
#

one method gets to the other

#

the unity event is assigned in the editor

slender nymph
#

have you actually done anything to find out what was hit? because you aren't filtering any colliders out of the OverlapCircle which means if the overlapcircle finds literally anything else first then it has failed to find the Interactable object.
so i'd bet that it's not that it isn't working without a rigidbody, i'd bet that the rigidbody is just making it a higher priority so it isn't finding other objects first. you likely just need a layermask to ensure you are only detecting interactable objects with that query

ionic zephyr
#

Okay, lets try that

slender nymph
#

you're also doing literally nothing at all to ensure you are only calling TryGetComponent when anything was detected, so if nothing is detected you'll be receiving NullReferenceExceptions, and if you are not then the issue is 1000% what i said before

rocky canyon
#

whoop whoop! hell ya

#

just needed some fine-tuning of the forces

#

MUCH higher forces than i expected

#

and hella dampening to accompany it

#

and i changed the tracking to use RB.MovePos in fixedupdate @slender nymph so thanks for that too

raw token
rocky canyon
#

and using fixedupdate/lateupdate

rocky canyon
slender nymph
rocky canyon
#

but it looked rough.. so i figured it was the logic.. but no it was just the values..

raw token
rocky canyon
#

i'll probably need to keep all my pickupable objects around the same mass to keep it consistent

raw token
rocky canyon
#

phew, that was actually on my bucket list 🤣

raw token
#

another one bites the dust

rocky canyon
#

who's next 😈

bold plover
#

Is it bad practice to use a static rather than constructor or does it depend on the scope of what you're trying to do?

wintry quarry
cosmic dagger
#

@bold plover can you clarify?

#

you mean to call a static method (to create an instance) instead of that type's constructor?

terse laurel
#

Hello I am new and would like to create a VR app with hands that are detect through the camera for a project. Can you tell me how I could do and/or the steps to follow.Thanks

bold plover
#

Of course! Error CS0120. Trying to make it so that movement values in the main player script correlate with movement state. Wondering if it is better to declare that variable as static or define that object as part of a constructor argument.

#

Hoping that makes a bit more sense.

cosmic dagger
bold plover
#

Alright. I wasn't certain if it was worth it as there are two listed solutions. I'm just not sure if one is "better" than the other.

slender nymph
ancient rampart
#

How do I log positions? And detect if an object has gone past a certain position?

ancient rampart
#

Just debug and transform.position?

wintry quarry
#

Debug.Log($"My position is {transform.position}");

ancient rampart
#

Ahh ok

wintry quarry
cosmic dagger
#

log the value(s) you want to track. that's up to you . . .

ancient rampart
#

Figured, just hadn’t done much with the position information in code, that was the main part I was wondering about, but if it’s just transform.position that’s pretty easy

wintry quarry
#

transform.position is the position of the object, yes

ancient rampart
#

Also meant moreso like

#

Logging it to a variable, or something I can check for another object

wintry quarry
#

the beauty of programming is everything is data

#

and you can do anything you want with it

ancient rampart
#

Like if object A is past object Bs Y position then do this

bold plover
wintry quarry
#

if (a < b) etc

bold plover
#

Been spending the last two days just reading about constructors and trying to get all the details under my belt.

ancient rampart
wintry quarry
#

in this example a and b are numerical values

ancient rampart
#

To compare 2 objects

wintry quarry
#

you don't compare objects

bold plover
#

At least I hope I understand said point as you intended, haha.

wintry quarry
ancient rampart
#

Cuz I need their individual transforms to compare

#

Yeah I have to reference them somehow

wintry quarry
#

you need references to the objects to get their positions, if that's what you're asking

mint remnant
#

is there a way to initialize a sprite to a source from code?
public Sprite sprite = new Sprite

polar acorn
wintry quarry
mint remnant
#

I guess so, when I drag an image in there it just shows a sprite

wintry quarry
#

What else are you expecting it to show

polar acorn
mint remnant
#

I was hoping to initialize it from code as it's in an array of them

#

to avoid having to drag alot

wintry quarry
polar acorn
wintry quarry
mint remnant
#

they are subelements of other arrays, so can't just drag a bunch like that

wintry quarry
#

then sure, just populate an array in code. You certainly wouldn't be doing that in a field initializer though

#

ever heard of a for loop?

glad rune
#

hi this script is for a 3s countdown. in game it shows 3,1 and not 3,2,1 as it should i also tried it with higher countdowns and it skips for 2 numbers there too like for 6 : 6,4,2 ``` cs
public class ReviveScreen : MonoBehaviour
{
public GameLogic logic;
public Text CountdownText;
public int Countdown;

public void StartCountdown()
{
    StartCoroutine(CountdownS());
}
IEnumerator CountdownS()
{
    while (Countdown > 0)
    {
        CountdownText.text = Countdown.ToString();
        yield return new WaitForSeconds(1f);
        Countdown--;
    }
    yield return new WaitForSeconds(1f);
    logic.CountdownFin();
}

}

polar acorn
languid spire
#

Also if you really want 3s use WaitForSecondsRealTime

glad rune
glad rune
#

but no other references

#

the whole script?

polar acorn
#

Sure. !code

eternal falconBOT
glad rune
#
cs

    public void RevContinue()
    {
        pipeGen.SetActive(false);
        GameOverScreen.SetActive(false);
        revScreen.SetActive(true);
        BackMusic.UnPause();
        revive.StartCountdown();

    }
}
#

message was too lng

wintry quarry
polar acorn
wintry quarry
glad rune
#

also

#

i debuglogged the countdown it showed what its supposed to show on screen 3,2,1,0

wintry quarry
#

where did you put the log

#

and when did it print

#

look at the timing of when it prints. Is it printing two numbers at once, then waiting 1s, then printing two numbers again?

polar acorn
#

It's pretty clear you're calling the coroutine twice. That's why I asked for the code of where you're calling it

wintry quarry
glad rune
#

yeah it goes two numbers at a time

wintry quarry
#

ok so

#

case closed

#

stop running RevContinue twice

twin bolt
#

OKay locking y works, but my object tends to rotate in the environment i have, and it wont rotate back.

#

I should probably just get rid of object rotation all together.

#

The objects will be big .

devout flower
#

!ide

eternal falconBOT
devout flower
#

since the vscode editor extension in unity isn't supported anymore, can i just use the vs editor extension, even though i use vscode

raw token
languid spire
slender nymph
#

the configuration guide linked by the bot even specifies you use the Visual Studio Editor Package rather than the legacy Visual Studio Code Editor package

crisp token
#

do i need to press regenerate project files tok eep visual studio code from defaulting back to code cmd every time i reopen unity?

slender nymph
#

if that happens every time you restart unity, it typically means that unity was unable to write that setting to the registry for whatever reason. launch the editor as administrator, change the setting, then launch it without admin privs again and it should stick

rocky canyon
#

it does indeed work, ive used this exact solution before

twin bolt
rocky canyon
#

mine do too if i force them too far.. i havent figured out a solution to that yet

#

probably a max distance from the anchor point

rocky canyon
#

oh wait... it is just you ;D

twin bolt
twin bolt
twin bolt
rocky canyon
#

no, i use dynamic.

#

and turn the gravity off

twin bolt
ionic zephyr
#

How could I program that teh damage that the players deals to a tree is bigger with an axe than with a shovel for example

rocky canyon
twin bolt
rocky canyon
#

then every weapon/tool would just have a damage amount to use

ionic zephyr
rocky canyon
#

not sure how its set up.. but u could use 1 tool script that has a damage variable u can change.. and u can assign that to all ur tools

#

just changing that damage amount

ionic zephyr
rocky canyon
#

could use an enum for ur tools

    float CalculateDamage(ToolType toolType)
    {
        switch (toolType)
        {
            case ToolType.Axe:
                return axeDamageAmount;
            case ToolType.Shovel:
                return shovelDamageAmount;
            default:
                return baseDamage;
        }
    }```
#
 public void TakeDamage(ToolType toolType)
    {
        float finalDamage = CalculateDamage(toolType);
        Health -= finalDamage;
    }
``` and im not sure what u mean by u dont want everything to be damaged.. u'd only have scripts on the things u want damaged..
#

the enum would look like

public enum ToolType
{
    Axe,
    Shovel,
    etc,
}```
ionic zephyr
#

Okay, that should be it

#

thanks!

rocky canyon
#

np, theres dozen other ways to do it. but thats what came to mind first.. since ur talkin about multiple tools

ionic zephyr
rocky canyon
#

hmm, actually id have to think about it..
thats actually a bit more complicated than originally thought

#

multiple tools and multiple structures.. 🤔

ionic zephyr
#

the clearest reference is minecraft

rocky canyon
#

interfaces come to mind.. IDamageable.. (all it knows is that it can be damaged) and every thing u inherit from it could just have a Damage() function you call..

#

you'd still need different components.. but the logic would all be the same.. so u'd just have to check which tool is being used

#

public class Tree : MonoBehaviour, IDamageable
public class Wall : MonoBeahviour, IDamageable
etc

crisp token
#

wait does I stand for interface

rocky canyon
#

"Interface"

crisp token
#

like the I in Ienumerator stands for interface?

rocky canyon
#

hmm, lol idk

crisp token
#

ah, finally i get what it means

lost hamlet
#

Interface naming goes like I<PascalCaseClassName>

#

I wish Unity respected the full convention

#

especially on fields and properties

thorny basalt
rocky canyon
#

Ienumerable?

#

ahh thats camel case..

rocky canyon
lost hamlet
#

unity uses camelCase for fields no matter what

crisp token
#

camel case vs PascalCase ?

lost hamlet
#

While the convention is PascalCase for public fields and properties

rocky canyon
#

camelCase PascalCase

lost hamlet
#

You do see that clash when you use anything not Unity specific

crisp token
#

i see

lost hamlet
#

i.e a library or something in System

rocky canyon
#

naming conventions vary so much

#

from person to person too

languid spire
lost hamlet
#

I mean IDEs can see the difference

#

Doesn't bother me either

ancient island
#

I want to add an external outline but setting tmpro.outlineWidth gives me what's in the second image

thorny basalt
ivory bobcat
#

Consistency would be preferable

summer stump
lost hamlet
#

Honestly all the libs i've used till now that aren't made for Unity follow the convention

#

Tho i haven't used a ton

summer stump
#

To be clear, I meant Unity libraries
Like internally, unity is not consistent

rocky canyon
#

if my ide didn't handle references so well, id probably bea little more critical about my naming

#

but its all over the place at times

lost hamlet
summer stump
#

It's mostly because they acquire things and just mash them in

lost hamlet
#

They call it Javascript but it isn't, the interpretter of that thing was even made in Boo, which apparently was another .NET language they supported before

rocky canyon
#

ages ago

#

never got a chance to try out Boo.. lol always wanted to since I heard tha name 😄

summer stump
#

Who called it Javascript?
Laugh at them

lost hamlet
rocky canyon
#

ooh boi

lost hamlet
#

Python like synthax

#

to an extent

rocky canyon
#
if i > 0:
    print "i is greater than 0."
    if i < 10:
        print "i is less than 10."
        if i > 5:
            print "i is greater than 5."

// Output: i is greater than 0.
//         i is less than 10.```
lost hamlet
rocky canyon
#

noice

lost hamlet
#

I hate it lol

rocky canyon
#

same, along w/ python

lost hamlet
#

Only reason i hate python is the indentation being relevant to the code

#

that and snake_case

#

And it breaking all the time

summer stump
#

Woah woah woah....

Rust uses snake_case

lost hamlet
#

Like it's the only language that can work on my machine a moment then break the next without me doing anything

#

I legit made a thing for a class and saved it on github

#

2 days later i run it and it doesn't work anymore

#

Or that one time it broke during class

#

where i double checked it working 2 minutes ago

eternal needle
#

Youd be surprised how many people say that, only to realize it was always their fault

#

It either:
-Was always bugged and you never noticed
-or you changed something and didnt notice. Meaning you need version control

rocky canyon
#

computers never be doing what u tell it to do.. just stubborn

languid spire
#

you know what they say, 'You can NEVER run the same program twice'

lost hamlet
#

Someone should make a self altering program

#

that would be fun

rocky canyon
#

#skynet

languid spire
tawdry ember
#

How do I put my code in here for people to read?

languid spire
#

!code

eternal falconBOT
tawdry ember
#
void SetMovementSpeed()
    {
        if(Input.GetKey(runKey))
        {
            walkSpeed = Mathf.Lerp(movementSpeed, runSpeed, Time.deltaTime * runBuildUpSpeed);
        }
        else
        {
            walkSpeed = Mathf.Lerp(movementSpeed, walkSpeed, Time.deltaTime * runBuildUpSpeed);
        }
    }
#

Can someone tell me why when I let go of shift, my character doesnt slow down to the walk speed?

#

It starts as the walking speed, when i hit shift it goes up but dont go back down

languid spire
#

because you have already changed walkspeed to runspeed

tawdry ember
#

Right but the else should change it back when i let go of teh button

languid spire
#

how? where would it get the original valie of walkspeed from?

thorny basalt
tawdry ember
#

How do I do that?

thorny basalt
#

Or float or whatever walkspeed is

tawdry ember
#

movementSpeed and walkSpeed is at 6, runSpeed is 10

#

Thats not the entire script

languid spire
#

it's simple dont use walkspeed here
walkSpeed =

thorny basalt
#

It will be both more readable and easier to debug.

tawdry ember
#

So just only have one float as the slower movement speed?

languid spire
#

also, that is not how to use Lerp

tawdry ember
#

How should I use it then?

languid spire
#

lerp takes a t value between 0 and 1, see pinned messages for correct use

crisp token
#

can I make a private inner jump class and then a separate public jump class?

languid spire
#

yes

#

inner class would be accessedf as outer.inner

modest dust
thorny basalt
#

Depending on what you are doing exactly

iron olive
#

where can i put a lot of code? like a website like pastebin for coe

eternal falconBOT
thorny basalt
#

!code

iron olive
#

ty

#

Problem:

https://gdl.space/erifegufuc.bash

The issue is in in the top of the paste.

Feel free to ask me more and also if it's a bad thing if I'm pasting all my scripts.

deft grail
polar acorn
deft grail
#

post each script separately as well

iron olive
#

okie dokie

deft grail
iron olive
#

alright

#

the reason why is because they use classes from other scripts. the scripts i will be providing might not be of any use, but im not sure what the problem totally is so im just including everything that is needed for the main script to function

iron olive
#

line numbers accurate

polar acorn
#

What is with this obsession with containing the entire message in a single bin

deft grail
iron olive
#

ok sorry

deft grail
#

bro you literally pass null

#

how can it not error

iron olive
#

holy fuck

#

why tf did i put that there

deft grail
iron olive
#

yes

deft grail
#

hence the null?

deft grail
# iron olive yes

just make another method for unequiping and pass the slot or whatever you need

#

instead of giving it null

iron olive
#

ok let me try that

deft grail
#

since you have an if statement for if its null

#

just dont error it and make it actually unequip, or make another method for simpleness

iron olive
#

my unity crashed 😭

crisp token
#

are dynamic methods automatically checked in c#?

deft grail
# iron olive ill just make another method

also just for future.
the error was for line 70, line 70 says you pass null
simple error simple solution
not sure if you actually did read the error and stuff but who knows 🤷‍♂️

iron olive
#

when i double clicked it

#

it just brought me to

#
        {
            Debug.LogError("ItemSO passed to EquipItem is null.");
            return;
        }```
#

so i thought the item wasnt actually functioning

modest dust
#

You can click the error message and read the detailed log below for the full stack trace

deft grail
deft grail
#

most null errors are easy to solve

iron olive
crisp token
#

does c# have something similar to javadoc comments?

deft grail
half egret
#

Javadoc comments automatically generate documentation based on format, not sure if that's what he wants

crisp token
#

yeah thats what I want

#

is it bad practice to use dynamic methods? Anything I should be doing in terms of exception handling or something?

half egret
#

There's no in built solution that generates something based off the XMLDocs it seems

crisp token
half egret
#

Was curious myself, no problem.

spiral glen
#

anyone know if this is changable in unity, I want to add a fading out object.
I saw a 'clear' static property although I don't want it to be instantly changed but faded.

rocky canyon
#

its alpha

#

.a usually

spiral glen
#

color.a

slender arrow
#

Hello, I just started Unity and even though I wrote the same code as the man in the video, my codes gave an error and I couldn't figure out exactly why.

spiral glen
#

I'll give it a try

deft grail
rocky canyon
#

OnFoot Onfoot onFoot

slender arrow
deft grail
#

where did you make it

slender arrow
#

I don't know exactly either

deft grail
#

unless your not supposed to, maybe remove the s?
whats the video showing

slender arrow
#

I was following the steps of the guy in this video and I encountered this error

raw token
#

I would imagine it's supposed to be an input action map

deft grail
#

apart from 1 upper case instead of lower case in OnFoot

deft grail
slender arrow
spiral glen
#
        while(color.a > 0){
            timer += Time.deltaTime;
            if (fadeTimer <= timer){
                Debug.Log("yuck");
                color.a -= .1f;
                timer = 0;
            }
        }
        if (color.a <= 0){
            Destroy(gameObject);
        }
    }```
anyone know why this script is instantly removing the platform instead of fading it out
(the fadetimer is a float and set to .25f)
deft grail
modest dust
#

because it's not a Coroutine

spiral glen
#

I'll try using a coroutine

modest dust
#

it loops until it's done, all at once

crisp token
#

is C# object keyword "Object" or "object"

rich adder
#

object

crisp token
#

ty

thorny basalt
#

Stop calling GameObjects “objects” in confuses me 😭

spiral glen
rich adder
#

kinda

#

everything in c# is an object essentially

half egret
#

You need to wait for the end of the frame while looping

rich adder
#

you are in a OOP(object oriented programming) language

spiral glen
#

oh

rich adder
#

without coroutine you would have to take out the while loop and only use time.deltaTime / timer

thorny basalt
#

Which is different from c# object iirc

rich adder
thorny basalt
#

Yes

#

Correct

alpine dew
#

Does anyone know how I could return the text property of a TMP component as a string array to be iterated over?

rich adder
#

not specific to GameObject though i meant

#

you make a class, thats an object (a blueprint to one actually)

thorny basalt
#

Yeah. Language for objects is kinda confusing since some beginners since I see some call GameObjects objects.

deft grail
rich adder
alpine dew
#

let me just show you my code maybe it'll explain itself better

#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class TextScroll : MonoBehaviour
{
    private string[] text;
    private float textSpeed = 0.01f;

    private TextMeshProUGUI textTMP;
    private int index = 0;

    void OnEnable()
    {
        textTMP = GetComponent<TextMeshProUGUI>();
        text = textTMP.text;
        textSpeed = GlobalVariables.textSpeed;
        ActivateText();
    }

    public void ActivateText()
    {
        StartCoroutine(AnimateText());
    }

    IEnumerator AnimateText()
    {
        for (int i = 0; i < text[index].Length + 1; i++)
        {
            textTMP.text = text[index].Substring(0, i);
            yield return new WaitForSeconds(textSpeed);
        }
    }
}
#

The intention is the script gets the TMP component of the GameObject, it loads up the text (I need it to be as an array type though I guess somehow), and it then iterates over the text for each character until the coroutine is done

#

but this current setup returns a null object reference

rich adder
#

are you doing some type of typewriter effect or whatever

alpine dew
#

text = textTMP.text; it says it cannot implicitly convert from a string to a string array string[]

alpine dew
rocky canyon
#

text is an array

#

how u gonna set a string to an array

polar acorn
rich adder
polar acorn
#

What are you trying to set text to? Which strings?

rich adder
#

its array of chars technically

#

but immutable

alpine dew
rich adder
#

if you want to iterate over the chars just iterate over the string, its already an array

polar acorn
thorny basalt
#

But why did you make it an array?

deft grail
thorny basalt
#

Oh wait misread sorry. 😅

alpine dew
#

that's just how the concept was set up by someone else and so it seemed like it needed to be an array to be iterated over by its index but I guess it being a string in general would allow that wouldn't it

#

I'll try some things

deft grail
rich adder
alpine dew
#

There was an attempt

rocky canyon
alpine dew
#

It's saying there's no substring method because it's per character

rocky canyon
#

substrings are easy to use

#

thats how my text writer wrks

modest dust
#

I believe you can also just use the property maxVisibleCharacters instead

spiral glen
#
    [SerializeField] float fadeTimer = .25f;
    void Start(){
        color = GetComponent<SpriteRenderer>().color;
    }
    void OnTriggerEnter2D(Collider2D coll){
        if (coll.name == "Player"){
            StartCoroutine(Fade());
        }
    }

    IEnumerator Fade(){
        color.a = color.a - 0.1f;
        yield return new WaitForSeconds(fadeTimer);
    }```
I'm kinda lost in why this script isn't doing anything (I'm trying to make an object fade out if a player touches it)
deft grail
modest dust
rich adder
#

the manual literally has example for fading..

spiral glen
#

oh damn

rocky canyon
#

not sure why i never realized that Neat!

rich adder
# rocky canyon 🤯

the difference is they are Immutable so you cannot replace chars by index
reason why new strings needs to be made when modified

rocky canyon
#

ahh gotcha gotcha makes sense..

eternal needle
# rocky canyon

I think tmpro has a max visible characters field you can use instead of this also

rocky canyon
#

i see caesar also mentioned that.. ❤️

eternal needle
#

Oh my bad, I didnt see that

rocky canyon
#

me neither..

#

but im changin it aorund right now..

#

im all about TMP functionallity

alpine dew
#

Alright so I reworked it slightly and well it does work but it seems like the coroutine only iterates about 14 times and then just stops before the end of the text's length

#

actually it varies

rocky canyon
#

how??

alpine dew
#

I have no idea

eternal falconBOT
alpine dew
rocky canyon
#

if u use the same string each time, im not sure how it would ever vary lol the loop is the same

alpine dew
#

I'll show you the in-game result of what I mean

#

it only runs for so long and depending on the textspeed it stops early

polar acorn
#

And show what it logs

alpine dew
#

Will do

#

For some reason it just works as intended now after I decided to log it

#

before it would stop before the end of the string

#

now it finishes

#

no change

#

I think it just hates me ngl

#

but thank you guys

#

for the solutions but also the patience

jaunty bay
#

i want to make a drop down list for a dictionary, how do i achieve that?

#

what project

frosty hound
#

@floral vale There's no collab/job postings here. Use Unity Discussions.

jaunty bay
#

i want to have a Door object, and also a button in the inspector to set it's spawn location. how can i achieve that?

dusty ember
#

How do i get a variable from another skript. I looked so much online and can't find a solution

slender nymph
alpine dew
#

might be a little bit hacky because obviously scene names can change but that is one way to do it

jaunty bay
jaunty bay
rocky canyon
#

the gameObject part is redundant

alpine dew
#

basically I made a series of empty GameObjects and loaded up references to each in a script in every scene, and that script then switches based on an integer, and the integer determines which gameobject to transform the playercapsule to** **

#

depending on how you want to do it you can set the spawn position either as a value the function returns or maybe store it globally

timid quartz
#

is there a way to find out where the input axis is coming from? I have no peripherals plugged in beyond keyboard/mouse/headphones and for some reason my input axis is reporting .17 on the vertical scale.

#

ah, restarted unity, it fixed it.... never mind thank you

jaunty bay
jaunty bay
thorny basalt
jaunty bay
thorny basalt
#

You should have a class that extend dictionary for serialization.

#

Or buy odin inspector if you don’t want to write your own.

thorny basalt
#

If not you can make a list

eternal needle
#

but there are other better implementations online out there

thorny basalt
#
[System.Serializable]
private struct DoorSpawnLocation
{
public Vector3 spawnLocation;
public Door spawnedDoor;
}
[SerializeFeild]
private List<DoorSpawnLocation> doorSpawns = new();
#

@jaunty bay if you are not doing lookup values just do this.

timid quartz
#

for some reason my movement code is snapping me to 0,0,0 - I have tried setting movement speed to 1 in the actual function and its still being funky.

    {
        // if we are holding a movement button, we want to move in that direction
        MovementSpeed = 1f;
        
        float horizontal = Input.GetAxis("Horizontal");
        float vertical = Input.GetAxis("Vertical");

        Vector3 location = transform.position + new Vector3(horizontal, 0f, vertical);

        rigidBody.MovePosition(location * MovementSpeed * Time.deltaTime);
    }```
#

both my horizontal and vertical axis are correctly 0 when this happens, too, I made sure of it

#

so with 0 it should just be moving me to my current location

#

instead I snap to 0,0,0

modest dust
#

You're constantly multiplying your whole position by delta time

timid quartz
#

OH!!!

modest dust
#

If anything, you should be only multiplying the position change

timid quartz
#

you're a genius and totally right

#

thank you

thorny basalt
#

Double check your math before doing stuff

#

Desmos is a cool tool for that

timid quartz
#

I refuse to use third party tools for anything!

#

(but seriously thank you, obvious in retrospect for sure!!)

modest dust
#

Does discord count as a third party tool? 😛

#

If it helps, use it

thorny basalt
#

Especially as an indie developer.

#

Plus, Desmos is a website. You aren’t installing anything into unity

late burrow
#

how i convert valuecollection to list/array

rich adder
void thicket
#

But think about a way you don’t need to do that

cedar bone
#

Does anyone have a good tutorial for adding bullet holes to walls when I use my gun?

late burrow
#

i wanted convert it to json

cedar bone
late burrow
#

but then i realized arrays dont work at all

slender nymph
cedar bone
#

what about particles?

#

cause im feelng like decals might not work in some scenarios (i.e. on players)

#

I want at least a particle where I am shooting

slender nymph
#

well last time i checked a player is not a "wall" which is what you had actually asked about. but yes, you can use particles for blood effects and the like to show you've hit a player. none of this is really code related though

cedar bone
#

also one more thing, how would I go about adding trails to my hitscan gun?

cedar bone
#

it doesn't show a lot of thing

#

like how they got the material for the hitscan

rich adder
eternal falconBOT
#

:teacher: Unity Learn ↗

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

rocky canyon
rich adder
#

read. experiment. learn

#

repeat

rocky canyon
#

not all tutorials are going to cover every single step

cedar bone
#

mb

#

aight thanks ig

rocky canyon
#

"trail material unity"

#

its all there btw.. if he doesn't change the material its using the default material

cedar bone
rocky canyon
#

ah yea ur right

rich adder
#

prob its some type of emissive material

rocky canyon
#

looks like its something like this

#

learn a bit about gimp/image editors so u can make things urself

#

it helps out alot when u cant find things u want

copper orbit
#

if i want to use one material for when damaged and another material for on death, do I have to essentially have two spriterenderers for each situation and set them active/inactive?

rocky canyon
#

or u could swap out the sprite in the renderer..

copper orbit
#

youre right, just found out how to swap the material. thanks

stoic oracle
#

I'm having an issue with the way transform.TransformPoint() is working. If I pass it a vector that I have confirmed is (-.9, 0, -.9) then it should return a Vector3 that is in the world location of a point that is (-.9, 0, -.9) in the local transform space. However, that's not what I'm getting.

Here is my code:


        Debug.Log("Vertices[0] * .9f = " + Vertices[0] * .9f);
        Debug.Log(transform.TransformPoint(Vertices[0] * .9f);

If I take the outputs of those logs, create two empties, one at (-.9, 0, -.9) in local space, and the other at the point output by transform.TransformPoint((-.9, 0, -.9)) They are not in the same place. I have confirmed that transform is referring to the correct object. What am I missing here?

surreal pecan
#

I need help guys

#

This is my code and its providing this error

#

does anyone knows how to fix it

summer stump
#

Remove system.numerics at the top

surreal pecan
#

ok

surreal pecan
thorny basalt
thorny basalt
summer stump
thorny basalt
#

Okay. Why?

summer stump
#

It is easily recognized, and common

#

What do you call it?

raw token
#

steve

summer stump
#

That is actually better.

#

I'll take it

thorny basalt
# summer stump Why not? Why ask? Why care?
  1. You don’t want to use it due to it a non descriptive variable name.
  2. I don’t know where it game from, and I am curious.
  3. I don’t. Beginners fall under bad practices all the time and critiquing them can be discouraging. However it is such a weird pattern that I much know.
thorny basalt
summer stump
summer stump
#

Rigidbody is one word. I would definitely find that odd

#

But yeah rigidbody is fine 🤷‍♂️

#

I normally use full words for almost everything. But.... i mean this is a rigidbody. It is like shortening camera to cam. You know what it is

thorny basalt
stoic oracle
# thorny basalt What is it outputting instead?

The results are close, but a few tenths of a unit apart. It seems dependent on the orientation of the parent of the transform object. I think I'll have to do some more testing. I just wanted to make sure I wasn't misunderstanding what it was SUPPOSED to be doing.

thorny basalt
#

Float math isn’t 100% precise.

stoic oracle
#

You mean it's going to be off by like .3? That seems like absurd margin for error.

thorny basalt
stoic oracle
#

No, tenths. Yeah idk. I think I can figure it out tomorrow. But geez it had me stumped tonight.

thorny basalt
#

I have a feeling it is some other force at play then the transformPoint method. Good luck though

cedar bone
slender nymph
#

what did your google search reveal the answer to be?

cedar bone
slender nymph
#

it seems to be that you didn't bother actually verifying then

rich adder
#

huh no idea unity had a similair component in birp. always used a zbuffer shader thing

#

TIL

cedar bone
slender nymph
#

that entirely depends on your needs

topaz mortar
#

I actually found a hilarious video that perfectly demonstrates why you shouldn't use Chat GPT for coding 🤣
Should be added to the FAQ or something: https://www.youtube.com/watch?v=rSCNW1OCk_M

Anarchy Chess Post: http://bit.ly/3jLT4JZ

➡️ ️Get My Chess Courses: https://www.chessly.com/
➡️ Get my best-selling chess book: https://geni.us/gothamchess

➡️ My book in the UK and Europe: https://bit.ly/3qFqSf7
➡️ Mein Buch auf Deutsch: https://bit.ly/45fKt3R
➡️ Mi libro en Español: https://bit.ly/3Y5xaRx
➡️ Mon livre en français: https://bi...

▶ Play video
gusty scaffold
#

i have a parent object instantiating a child object

#

but i got this error
Assets/Permutor/ManagePermutor.cs(68,20): error CS1061: 'GameObject' does not contain a definition for 'Init' and no accessible extension method 'Init' accepting a first argument of type 'GameObject' could be found (are you missing a using directive or an assembly reference?)

slender nymph
#

you've already been instructed on how to resolve that error. show what you tried

#

also notice that the examples on that page do not use GameObject variables for either the prefab nor the instantiated instance

gusty scaffold
#

ah it just says var instance

#

no type

rich adder
#

the type you picked for prefab passing in instantiate is what matters

gusty scaffold
#
public class ManagePermutor : MonoBehaviour
{
    public PermutorHandle handlePrefab;
...
    PermutorHandle handle = Instantiate(handlePrefab, Vector3.zero, Quaternion.identity);
    handle.transform.SetParent(empty.transform, false);
    handle.Initialise();
}

other file...


public class PermutorHandle : MonoBehaviour
{
    public void Initialise() {

    }
}

i got

UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)```
rich adder
#

not sure thats from that code is it?

gusty scaffold
#

maybe not

slender nymph
#

well that isn't a compile error, so maybe provide literally any info about what caused the error

gusty scaffold
#

let me clear the logs

#

oh my god it worked

#

ok i gotta add parameters now

#

to Initialise()

rich adder
gusty scaffold
#

ye i was hasty posting that error

#

sorry

#

wow ok so you drag the prefab to the inspector, but it actually grabs the class defined in the prefab's script

rich adder
#

yes

cedar bone
#

how would I turn on/off the emmission of a particle?

gusty scaffold
#

that makes a lot of sense now because i was like how tf do you see other classes

cedar bone
reef patio
#

something is wrong with this nav mesh terrain, it has 4 problems, can someone help me?

teal viper
reef patio
#

What to do about it?

mint remnant
#

if (Input.GetKeyDown(KeyCode.Tilde))
Am I missing something here? Doesn't seem to work when I press the key next to the "1"

slender nymph
mint remnant
#

ok that worked, tried holding shift too but tilde still didn't respond

slender nymph
#

do you have Use Physical Keys enabled in the input manager settings?

mint remnant
#

seems so yes

slender nymph
mint remnant
#

haha thanks, what an obscure thing to happen

deep yew
solid mango
#

@deep yew my friend it wont work , because it must be "OnCollisionEnter" not "OncollisionEnter"

thorny hamlet
#

Am I doing something wrong guy because my GameManager doesn't change to the gear icon

upper tide
#

Is it acceptable to use underscores in clas names?

#

I was wondering if ICommand and Command_Undo would be better than UndoCommand in terms of readability

keen dew
solid mango
#

and "ICommand" is prefered in interface not in normal classes

keen dew
thorny hamlet
errant solar
#

cannot convert UnityEngine.Quaternion to UnityEngine.Vector3

#

is there a way to fix this?

solid mango
#

@errant solar i think you need to go watch and understand more about rotations in unity , and not just take my answer and move on

errant solar
solid mango
solid mango
errant solar
#

arabic?

solid mango
#

yes

errant solar
solid mango
errant solar
#

ايش w دي؟

solid mango
#

so its simple for us to change angles in X Y Z without the W

fierce geode
#

This is gonna sound stupid, but is there a way to make sure that any scene that is loaded; automatically loads a script even if its not there?

#

Like say I had a game manager script, that needs to be in every scene; is there a way to tell Unity to automatically load a specific script with a scene?

rocky canyon
#

what is TABLE_ ?

#

u mean a prefix of "TABLE_"

#

interestn

#

ive never done anything like that but im sure its possible w/ someting other than a tryget

#

u could get all and loop thru checking the name w/ strings

#

u should use interfaces intsed

#
   if(hit.collider.transform.TryGetComponent(out IInteractable interactable))
            {
                cachedInteractable = hit.collider.gameObject;
                if(Input.GetKeyDown(interactKey))
                {
                    interactable.Interact();
                }
            }```
#

yessir

#

soo things like my Pickup scripts are found w/ that interface

#

and everything interactable just has an Interact function we call

#

regardless if its a pickup, a switch, or w/e else

#

yes, thats what u can do w/ interfaces.. u havee 1 basic interactable interface or w/e

#

and u can inherit it from different classes (these can be different functionallity for different things)

#

or u could go the ez route and use a Tag

#

Table object or something.. and tag all ur things w/ Table..and u could check for that tag w/ the hit info

#

a switch statement would be a bit cleaner.. but yea interfaces sound like a better solution for what ur talkin about

#

thanks..

#

good luck.. come back if u run into any issues 👍

raw robin
#

Hi, Im trying to create a grid with some simple pixel art, but as you can see the lines touching is always 2 pixel wide while the side lines are 1 pixel, how should I go about fixing this and have some consistent boarder lines?

deep yew
#

Any idea on why this thing is giving me an error?

languid spire
#

also FindObjectOfType does NOT return an array so there will be no Length property

deep yew
languid spire
rocky canyon
#

its own script

languid spire
#

it's an (incomplete) namespace declaration

#

for some one who just reccommended someone else to google the docs, you seem to do very little of that yourself

#

do you know what

using UnityEngine;

in your code actually means?

rocky canyon
#

its really not important.. its someones custom namespace..

#

like here.. my IInteractable is wrapped in my SPWN namespace.. if i remove the using statement i cant access it

#

i could very well not put it in a namespace tho

vast vessel
#

hey guys.
im trying to remove ALL triangles inside of a collision mesh, that have a normal similar to a normal vector returned by a raycast hit, in runtime.
is there a way for me to do that?

rocky canyon
#
  • raycast to get normal
  • access mesh data
  • calculate normals of each triangle in mesh
  • compare normals
  • remove triangles
  • update mesh
#

now as for the nitty gritty of that process, no clue

vast vessel
rocky canyon
#

after u remove triangles u have to recalculate / rebuild the mesh

#

you shouldn't be directly modifying the triangles either..

#

need to create a new list of triangles and then iterate thru that afterwards to rebuild it

#

but ive never done this.. soo this is just speculation

vast vessel
#

alr ill try, thanks 👍

twilit iris
#

can you check the line of code that cause the program error in unity?

rocky canyon
#

double click the error and it should open up to the line that causes it

#

theres also (character number, line number) at the end usually

twilit iris
#

I can't double click it T_T

rocky canyon
#

looks like some sort of unity error/bug

#

id just clear it out and go on my day

#

the top one is tho

twilit iris
#

Yes the top one can be double clicked

#

thanks for tip~~

dry sparrow
#

im trying to make my character move but i couldn't

languid spire
eternal falconBOT
rocky canyon
#

share:

  • your code
  • your setup (inspector windows of character controller, rigidbody, etc)
languid spire
rocky canyon
#

!ide configure ur IDE

eternal falconBOT
rocky canyon
#

see anything wrong here?

dry sparrow
rocky canyon
#

ur IDE should have it underlined in red

dry sparrow
#

how can i make it do that?

rocky canyon
#

the bot message directly above us.. ^

#

click the link to the software ur using and follow the instructions (carefully)

languid spire
rocky canyon
#

its Rigidbody2D

twilit iris
#

How to spawn object dynamicly?

languid spire
twilit iris
#

Basicly I tried to make Highscore in a list and I want to spawn Text mesh pro dynamicly

#

in a canvas

dry sparrow
rocky canyon
#

nope, thats all the errors u didn't see before..

twilit iris
#

but I still stuck in trying to get my textmeshpro in my gameobject

languid spire
twilit iris
#

my code looked like this

languid spire
rocky canyon
# dry sparrow some how i followed it and it got even worse yesterday it was just fine did i me...
using UnityEngine;

public class Movement : MonoBehaviour
{
    public float speed;
    private float Move;

    private Rigidbody2D rb;
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    void Update()
    {
        Move = Input.GetAxis("Horizontal");
        rb.velocity = new Vector2(Move * speed, rb.velocity.y);
    }
}``` the only time im going to do this.. this is the valid code for what ur trying to do.. look over it and compare it to urs.. 
you are missing a `{` for the beginning of the class, its `Rigidbody2D` not `2d`, its `Input` not `input` and ur missing a ending `}` for the class
barren vapor
#

ah you already got it

hexed terrace
#

this is a code channel, that is not a code issue. Delete and ask in #🌐┃web

#

(after first contacting the publisher of the asset)

cloud ferry
#

Hi.
I tried to play some videos with VideoPlayer on RawImage.
I wrote code to load a VideoClip from Adressable and assign it to VideoPlayer.Clip, but the error output just says "Cannot read file". What is the cause? Sorry for this amateur question.

hexed terrace
#

The question isn't amateur, how you asked the question is though

#

You need to provide information on what you're doing for others to be able to help

cloud ferry
#

I wanted to use this code to overwrite the VideoPlayer source, but the editor error output just said "Cannot read file", so I don't know what is wrong.I would like to know what is causing this error.

languid spire
uncut shoal
#

How to get a bounding box that equals an orthographic camera space

#

or see if a bounding box is visible in screen space

languid spire
uncut shoal
#

I'm trying to get a 2D bounding box kinda

#

I'm programming a renderer for my world, so I want to be able to know if a chunk is in the screen before rendering

uncut shoal
#

Thanks!

pseudo swan
#

Help me!! I am spawning NPCs from a prefab, and I want them to follow a path of waypoints. If I put the script onto the prefab, then I can't assign it the waypoints which are GameObjects in my scene. If I put the script onto an empty GameObject in the scene (and call it NPCmanager) then I don't know how to dynamically assign it to the spawned NPCs. Any suggestions?

#

If you have a link to a tutorial or any advice, I'd love it!

languid spire
#

typo\

pseudo swan
#

Gotcha, so the behavior script (to follow waypoints) sits on the prefab. How do you assign the waypoints then?

languid spire
pseudo swan
#

They are game objects.

#

I can make them transforms or something.

languid spire
#

that is not what I asked

pseudo swan
#

It would be good if I could see them in the scene, but no mesh renderer so they are invis in the game.

#

What did you ask? Sorry, I'm a bit of a noob.

languid spire
pseudo swan
#

Do you want me to paste the script?

languid spire
#

!code

eternal falconBOT
pseudo swan
#

It's small. I can post it here, am opening the project right now. ChatGPT helped me make the script, but not exactly how you described. It doesn't sit on the NPC.

#

To clarify, I'm using a 3rd party asset called Ultimate Spawner 2.0 by Trivial Interactive to spawn the NPCs. The spawner has some extra features, such as events you can use. I've tried using an event called On Spawned (transform) to run a method that's supposed to assign the waypoints to the spawned NPC. The method is on an empty object called WaypointAssigner in my scene, to which I can add the waypoints since it's in the scene with them. But this is not working for me.

#

Let me post the scripts here:

#
using UnityEngine.Events;

public class WaypointAssigner : MonoBehaviour
{
    public Transform[] waypoints; // Array of waypoint transforms

    public void AssignWaypointsToObject(Object spawnedObject)
    {
        GameObject myCube = spawnedObject as GameObject;
        if (myCube != null)
        {
            AssignWaypointsToCube(myCube);
        }
        else
        {
            Debug.LogError("Assigned object is not a GameObject");
        }
    }

    private void AssignWaypointsToCube(GameObject myCube)
    {
        AdventurerRoutine adventurerRoutine = myCube.GetComponent<AdventurerRoutine>();
        if (adventurerRoutine != null)
        {
            adventurerRoutine.waypoints = waypoints;
        }
    }
}
#

I didn't format that right, sorry.

#

Currently I'm just using a cube to represent the NPCs, calling it myCube.

languid spire
#

that looks fine, show the code for AdventurerRoutine

pseudo swan
#
using UnityEngine;

public class AdventurerRoutine : MonoBehaviour
{
    public Transform[] waypoints; // Array of waypoint transforms
    public float speed = 1.0f; // Speed of movement

    private int currentWaypointIndex = 0;

    void Start()
    {
        // Check if there are any waypoints to go to
        if (waypoints.Length > 0)
        {
            StartCoroutine(MoveToWaypoints());
        }
    }

    System.Collections.IEnumerator MoveToWaypoints()
    {
        while (currentWaypointIndex < waypoints.Length)
        {
            Vector3 targetPosition = waypoints[currentWaypointIndex].position;
            while (Vector3.Distance(transform.position, targetPosition) > 0.1f)
            {
                transform.position = Vector3.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);
                yield return null;
            }

            currentWaypointIndex++;
        }

        gameObject.SetActive(false); // Disable the GameObject when all waypoints are reached
    }
}
#

This is a screnshot of my Infinite Spawn Controller, and you see the On Item Spawned (Transform) event.

#

I cannot assign a game object dynamically there, I don't know how.

languid spire
#

Dont see anything horibly wrong with that as long as your spawnObject (myCube) has the AdventurerRoutine script attached to it

pseudo swan
#

myCube has the Adventurer Routine script.

#

I think the problem is in the Infinite Spawn Controller, you see there is None (Game Object) there.

languid spire
#

you have not assigned myCube here

pseudo swan
#

But how? The cube is just a prefab until it spawns.

#

It doesn't exist in my scene.

#

Do I drag the prefab there from the Project window?

languid spire
#

looks like you are using the asset incorrectly becaue there is no spawning going on there

pseudo swan
#

I see. By the way, I don't have to use the spawner asset if it's simpler a different way.

#

And the cube does spawn in my scene, it just doesn't do anything.

languid spire
#

this should be
GameObject myCube = Instantiate(spawnedObject) as GameObject;
then no asset required

pseudo swan
#

It just sits there.

#

Where should that line be?

languid spire
#

then you can put the prefab in the event

languid spire
pseudo swan
#

Which script, WaypointAssigner?

#

Sorry, I'm being stupid.

languid spire
#

read your own code
GameObject myCube = spawnedObject as GameObject;

pseudo swan
#

I see it, it's in WaypointAssigner.

#
using UnityEngine;
using UnityEngine.Events;

public class WaypointAssigner : MonoBehaviour
{
    public Transform[] waypoints; // Array of waypoint transforms

    public void AssignWaypointsToObject(Object spawnedObject)
    {
        GameObject myCube = Instantiate(spawnedObject) as GameObject;
        if (myCube != null)
        {
            AssignWaypointsToCube(myCube);
        }
        else
        {
            Debug.LogError("Assigned object is not a GameObject");
        }
    }

    private void AssignWaypointsToCube(GameObject myCube)
    {
        AdventurerRoutine adventurerRoutine = myCube.GetComponent<AdventurerRoutine>();
        if (adventurerRoutine != null)
        {
            adventurerRoutine.waypoints = waypoints;
        }
    }
}
#

Like this, right? And no other changes needed?

languid spire
#

only assign the prefab in the inspector

#

and, of course, actually add some waypoints to the list

pseudo swan
#

Well, no errors, but the cube still just sits there. I have the waypoints assigned to WaypointAssigner:

#

Ohhh

#

It moves! It moves!!!

#

OMG I almost had an anneurism.

#

Thank you so much, Steve!

#

May I bother you with another question?

languid spire
#

Sure, bear in mind this whole thing is much more complicated by you using an asset to do basic stuff

pseudo swan
#

In my game, the NPCs don't have physics. They don't have navigation etc. They just move from one point to another, in a linear fashion. (Or at least they should.) When the cube in this case follows the waypoints, it seems to interpolate or make a curve.

#

Is it possibe to tell it to go in a linear way, straight to the waypoint?

#

I can capture a video if that helps.

#

(Yes, I should do this basic stuff myself, but I thought the asset would make it simpler as I'm a noob. I should just learn to code better.)

languid spire
#

this code
transform.position = Vector3.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);
says move from A to B
so I dont see where a curve is coming from although you might want to look at Vector3.Lerp

pseudo swan
#

Sorry about the messy scene, just showing you the cube going through the floor.

#

But don't worry about it, I will figure this one out on my own/

#

Thank you for your help, you have no idea how helpful that was for me.

formal sable
#

There is a problem, I press the space bar and the panel is removed, I do not understand what it is... I didn't put anything anywhere. Can you help me please?

languid spire
#

that looks fine. you should look at the scene view with your waypoints selected

pseudo swan
#

Haha, the pivot of the cube is in the center of it, that's why it's going into the floor. Simple problem, sorry to have bothered you. Again, thanks for all the help!!

#

I will learn how to code better.

languid spire
fickle stump
#

!code

eternal falconBOT
twilit iris
#

Why every guide want to find object by tag instead of by name?

wintry quarry
#

but, neither of those are recommended in general

twilit iris
#

By faster is the processing?

wintry quarry
#

there is no other meaning of faster

twilit iris
wintry quarry
#

otherwise some mix of opportunistic assignment and the singleton pattern or other dependency injection.

fickle stump
#

hey, I'm trying to change images of my imagecontainer (a panel that holds 5 images) by clicking on buttons. But the only way that it works is after I've clicked 5x on the next or the previous button, all images get loaded at once ._. can somebody help me '^'
https://gdl.space/vofepobaje.cpp

twilit iris
#

What is Direct references? like resources.load?

wintry quarry
#

you wrote = when you should have written ==

wintry quarry
#

direct reference is assignment in the inspector

languid spire
fickle stump
#

AND THAT TOOK ME 45 MINS TO FIND

fickle plume
#

@fickle stump Don't spam off-topic images

twilit iris
#

is direct reference making public attribute and drag and drop asset?

fickle stump
#

sorry didnt know that thats spaming nowayMonkaS

twilit iris
#

Ahhh...

fickle stump
#

@wintry quarry I've tried your fix, but somehow the the index only changes after beeing clicked 5 times..

#

it gets triggered at once after 5 clicks

wintry quarry
#

you're only calling SetImage in that if statement

#

why

#

shouldn't you be calling it no matter what?

#

some simple debugging will get you these answers in the future

fickle stump
#

i see.. thanks

#

coding is very hard for me unfortunately

languid spire
twilit iris
#

How do you change attribute inside prefab? Do you just make a new class with constructor to change certain attribute?

#

I want to generate text with certain font but different text everytime

languid spire
polar acorn
wintry quarry
quiet pilot
#

(idk if this counts as really beginner coding so sorry if this is the wrong channel)
Does anyone know why my AddExplosionForce() is applying way too much vertical force and not enough horizontal force?

#

(also hi everyone)

wintry quarry
quiet pilot
#

The problem is I don't think it is

#

oh that's kinda cool it blocks "uh"

wintry quarry
#

Sounds like you should start debugging

quiet pilot
#

yeah

#

I keep forgetting not to say uh 😭

#

The point that the explosion is from should be right in front of the player

languid spire
wintry quarry
quiet pilot
#

and the upwards modifier is very low

wintry quarry
quiet pilot
#

I can try to give context

#

lemme try this first

#

Although I do apply the explosion force through an external method

#

like the method is in a script on a different object

#

By the way, the explosion force sends the player extremely high up even if it's in the negatives (down to -1)

wintry quarry
quiet pilot
#

Yeah

twilit iris
wintry quarry
#

and just set up anchors/etc in the prefab

#

Instantiate(prefab, container)

twilit iris
#

I successfully make it as a child of a canvas

#

but somehow the position still wrong .-.

wintry quarry
#

again, proper anchoring etc

#

you are giving vague answers here so it's not clear what the "correct" position would be

quiet pilot
#

like this

twilit iris
#

Uhh how do I set the anchor by script again?

quiet pilot
#

oh sorry

#

I don't know that

twilit iris
#
        for (int i = 0; i < HighScoreList.Count; i++)
        {
            var temp = Instantiate(Font, new Vector3(50, 160 - i * 100, 0), transform.rotation, GameObject.Find("CanvasHighScore").transform);
            temp.GetComponent<TextMeshProUGUI>().text = "Score : "+HighScoreList[i].ToString();
            temp.GetComponent<TextMeshProUGUI>().anchor
        }```