#๐Ÿ’ปโ”ƒcode-beginner

1 messages ยท Page 217 of 1

leaden dove
#

im not gonna leave becuase someone said something i dont like

#

sorry

north kiln
#

Please move on from the argument and just ask the full question

leaden dove
#

it doesnt matter anymore

summer stump
#

I linked collab links for them, and it made them upset i guess.
Was just trying to help ๐Ÿคทโ€โ™‚๏ธ

north kiln
#

Missed that part, great

#

I'm a little confused, because I don't believe you will get a normal at 45deg unless there's a mesh collider with a chamfer.
I'm also unsure what this code would do in Update, surely if it worked the cube would rotate at a million km/h because it would repeat the logic every frame?

heady wyvern
gaunt ice
#

does your raycast always hit object?

rich adder
#

if your game is gonna be 3D / 2.5

summer stump
north kiln
#

Still just checking the tag and not the collider or hit

#

And randomly passing 512 as a layermask?

lusty girder
grand sigil
#

I want to know what is the index of a gameobject is through a script. Specifically i want to put a GetIndex process in the script where the gameobject i want to know its index is placed. How do i do this?

north kiln
grand sigil
#

Like, i instantiate(from a different script) a bunch of gameobjects and i want each of them to be assinged a number based on their index.

north kiln
lusty girder
grand sigil
heady wyvern
grand sigil
#

Ngl, havnt thought of that and that is much simpler

#

Thanks

rich adder
heady wyvern
#

so remove .tag correct?

rich adder
#

the first one yes

#

but just wrap the whole Raycast in if() but honestly still think you should use 3D colliders for a 2.5D game unless your player never moves around 3D world

#

2D colliders will be awkward

heady wyvern
#

wait

rocky canyon
#

more like this

heady wyvern
#

so delete that raycast line and replace with that

rocky canyon
#

if(raycast..

  • if hit
heady wyvern
#

ok

rocky canyon
#

you can use ur raycast you have now

heady wyvern
north kiln
rocky canyon
#

ohh with 2d u cant.. as long as it 3d ya

north kiln
summer stump
# heady wyvern so remove .tag correct?

Yes. Whatever you have to written at the end of the dot chain is the thing you are checking. You want to check the collider, so nothing should come after it except the !=

rocky canyon
#

u declare the hit

#

and then just the raycast..

rich adder
rocky canyon
#

u cant shove a declaration in there

rocky canyon
rich adder
#

vertx has mentioned there is a implicit cast to bool for null check for it

rocky canyon
#

neat.. i didnt know that.. but like someone said earlier.. if its 2.5D its probablybest to use 3d raycasts

lusty girder
rich adder
#

agreed, unless its a fixed camera scenario 2D colliders will be diffcult even with sprites

rocky canyon
#

i use sprites but big primative colliders around them

rocky canyon
#

chunky colliders like this.. and use 3d raycasts

rich adder
#

thicc boy

rocky canyon
#

its working well so far

#

i suggest that other guy do something similar.. instead of the 2d fiasco.. but maybe it fits his needs idk

rich adder
#

navmesh agents with sprites thinksmart

heady wyvern
rich adder
# heady wyvern

what makes you think you declare something inside an if statement ? UnityChanThink

#

instead of guessing maybe you should follow a basic unity course in !learn

eternal falconBOT
#

:teacher: Unity Learn โ†—

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

heady wyvern
#

ty

rocky canyon
# heady wyvern

no.. declare the variable outside no iff needed.. and then ur physics2d.raycasy line. becomes an if statement below it

#
RaycastHit2D hit;

if (Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero, Mathf.Infinity, 512))
{```
#

then.. in if the raycast hits something u can check thie hit

rich adder
#

layer 512 they wont get very far

rocky canyon
#

lol idk what that is..

heady wyvern
#

its to the Clickable Layer

rocky canyon
#

but also i noticed his hit isn't in the raycast..

heady wyvern
#

under my target

rich adder
#

use layermasks

rich adder
heady wyvern
#

Debuglog and it was showing 512

slender nymph
rocky canyon
#

ya, im getting mixed signals.. i gotta check myself.. b/c i came back to the issue and someone said there was one that returns the bool..

heady wyvern
#

i followed this one guide but

rocky canyon
#

so thats true.. and it doesn't have the hit.. u have to do that extra?

slender nymph
rocky canyon
teal viper
#

512 should be layer 10

gaunt ice
#

1<<9

rich adder
rocky canyon
#

thats pretty smart tho..

#

to debug the layer

rich adder
#

magic numbers

rocky canyon
#

i wouldnt have thought of that

teal viper
north kiln
heady wyvern
#

In this tutorial series you will learn how to create an RPG game in UNITY. The scripting language used in this series is C#.

You can get the project files by following this link(This includes all assets like commented C# scripts and sprites, sounds etc.):
https://www.inscopestudios.com/rpg

I will explain everything I'm doing in details so that...

โ–ถ Play video
#

6:15 is where that 512

north kiln
#

lol

rich adder
#

bad tutorial

north kiln
#

I hate that

heady wyvern
#

ill have to watch watch nav sent for beginners

rich adder
#

als you copied wrong

rocky canyon
#

yup i thought that too.. made a full circle.. his code was pretty much fine at first..

#

just need to check for the collider before doing tag comparisons

rich adder
heady wyvern
#

ty for the help. everyone lol def gonna start watching those

grand sigil
#

if i use Random.Range which will pseudorandom pick a number from 0 to 8, should i make the maxvalue 8 or 9? Since im seeing a lot of examples where the max value isnt chosen. Just want to confirm this

#

minvalue would be 0

#

and i will be using System.Random

grand sigil
#

So the max wont be chosen? Im not too familiar with those terms

rich adder
#

Oh the System not unity

grand sigil
#

whats the difference between them?

rich adder
#

I think its still max exclusive

grand sigil
#

thats what i noticed, both docs on the system and unityengine are the same

rich adder
#

Unity one also includes things like color or rotation

#

etc

grand sigil
#

but max exclusive means that the value will be excluded from the possible int it can choose?

rich adder
#

yea

grand sigil
#

ic

rich adder
#

so if you want max 10 you put 11

grand sigil
rich adder
#

yea

heady wyvern
#

@rich adder

#

do i just go in order

summer stump
# heady wyvern

For the first two or three. Then only if you want to do VR and AR

#

Of course haha

small mantle
#

I am making a game that will have many different GameObjects with different values. Just like games with many characters I want to make a system for stats that all will use. Such as having variables for weak, average, strong, and very strong when applying values for Character Stats. I want to know if there is a way to make a list of variables with custom names that will be able to be set in for Floats in the inspector

#

Instead of the numbers, I would like a drop down list to appear that I can pick from. The item from the list I choose from will be a float variable.

vast sparrow
#

how do i wright the () other kind of these

summer stump
frosty hound
#

() {} [] <>

Take your pick

summer stump
#

{} <>

#

Too slow

vast sparrow
#

{} these

summer stump
vast sparrow
summer stump
#

Just gotta... look for them ๐Ÿคทโ€โ™‚๏ธ

small mantle
#

Is it possible to make a drop down list for Serialized floats in the inspector?

timber tide
#

such as a list of floats?

#

or like enums that represent a value of floats?

slow reef
#
using UnityEngine;
using UnityEngine.SceneManagement;

public class scenechange : MonoBehaviour
{
    public float launchForce = 10f;
    public float destructionDelay = 2f;

    private void OnCollisionEnter(Collision collision)
    {
        // Call the ChangeScene method after the specified delay
        Invoke("ChangeScene", destructionDelay);
    }

    // Method to change the scene
    void ChangeScene()
    {
        // Load the scene with index 1 after the delay
        SceneManager.LoadScene(1);
    }
}
#

is there anything wrong with this code

#

what this does is

#

its in a gameobject

#

and whe you touch it

#

you get flung into the sky

#

you do in fact get flung

frosty hound
#

Can you type your entire thought out before hitting enter?

slow reef
#

but it doesnt change the scene

slow reef
frosty hound
#

Yes and it's silly

#

First of all, you can just call a function with ChangeScene(). (I just noticed there's a delay, so what you have is fine)

summer stump
#

Do you have a scene with index 1?

slow reef
frosty hound
#

Secondly, put a Debug.Log inside of your OnCollisionEnter to see if it's actually calling that function

small mantle
summer stump
#

Nm, forgot how invoke works lol

timber tide
# small mantle For floats

if you're trying to represent a field with a value using the inspector from a selection then use enums and resolve it at start (or onvalidate for SOs)

slow reef
#

Let me try using a coroutine.

frosty hound
#

You can use Invoke. Or you can change your ChangeScene function into a coroutine and add a delay.

summer stump
#

Because the launched into the air part is happening elsewhere. It doesn't prove this code is running

slow reef
summer stump
slow reef
#

I added a debug log in the OnCollisionEnter right before it Invokes the procedure. I also added on inside the procedure itself. The one outside outputted, but the one inside didn't.

summer stump
#

Ok nice. Sounds good

summer stump
bright zodiac
bright zodiac
#

or even better, use a popupfield and wrap the float in your own class

slow reef
#

The object is never destroyed at all, actually.

#
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;

public class scenechange : MonoBehaviour
{
    public float launchForce = 10f;

    private void OnCollisionEnter(Collision collision)
    {
        Debug.Log("collided");
        // Call the ChangeScene method after the specified delay
        StartCoroutine(ChangeScene());
    }

    // Method to change the scene
    IEnumerator ChangeScene()
    {
        Debug.Log("right b4");
        // Load the scene with index 1 after the delay
        yield return new WaitForSeconds(2f);
        SceneManager.LoadScene(1);
        Debug.Log("should've loaded scene");
    }
}

I converted it into a coroutine, but the code is back to not changing the scene again :/. It outputs "collided" and "right b4," but doesn't output "should've loaded scene."

#

It only works if the procedure is directly called, and doesn't if it's either called through an Invoke function or is converted to a coroutine.

night mural
summer stump
night mural
#

well it sounds like they are expecting to see the restuls of Debug.Log("should've loaded scene"); but aren't

summer stump
#

It happens at the end of the frame, which is after the debug, if you meant that

summer stump
night mural
#

It outputs "collided" and "right b4," but doesn't output "should've loaded scene."
is what i'm addressing...but yeah if the scene also doesn't load then that's probably more important to figure out

summer stump
night mural
#

oh you're right and the message is actually misleading ๐Ÿ˜„

summer stump
#

Ahh, I see what you mean now.
Yeah, it wouldn't log it in the new scene for sure

night mural
#

When using SceneManager.LoadScene, the scene loads in the next frame, that is it does not load immediately. This semi-asynchronous behavior can cause frame stuttering and can be confusing because load does not complete immediately.

summer stump
#

Oh it's the next frame! Good to know. Thanks

night mural
#

^ from the docs so i guess it's probably that and the solutoin is to use the Async one

#

yeah i didn't know any of this cause i've always just used the async one

slow reef
night mural
slow reef
night mural
small mantle
#

On my Player there are many Children. These children are basically their own character as they have their own components. However, only one is active depending on which which the Player decided to shape into. Now I want to know if there is a way I can refer to the current child that is active. This is what my scene view looks like:

small mantle
lusty flax
#

i have a little if statement to create coyote time and jump buffering for a platformer, but it makes it so if you double tap jump really fast, then you can do a sort of double jump boost to go higher. I do not want this to happen. How can I fix this? would it be by adding a very slight (0.2s) jump cooldown, or is there a better solution?

if (timeSinceGrounded < 0.2f && timeSinceJump < 0.2f && !isJumping)

summer stump
lusty flax
#

when you jump

#

it only resets once you touch the ground again

summer stump
lusty flax
lusty flax
summer stump
#

It SHOULD be correctly stopping double jumping. Nothing seems like an issue here. Hmmm

Have you tried GetKeyDown instead of GetKey?

lusty flax
#

getkeydown only works on the first frame input

#

i want to allow buffering so i don't like using getkeydown for this

#

i found the issue

#
{
    if (isJumping)
    {
        Debug.Log("grounded");
    }
    isJumping = false;
    timeSinceGrounded = 0;
    if (abilityCharges < 1)
    {
        abilityCharges = 1;
    }
}```

I added this `Debug.Log();` line to check if the game was somehow detecting that the character is still on the ground after the 1st input
#

it is...

#

huh

slow reef
night mural
slow reef
#

Alright, thanks!

lament birch
lusty flax
lament birch
#

sorry I meant FixedUpdate not LateUpdate lol

lusty flax
#

time variables are multiplied by time.deltaTime

slow reef
# night mural yes, though if you read the docs you may find there's slightly more to it than t...
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;

public class scenechange : MonoBehaviour
{
    public float launchForce = 10f;

    private void OnCollisionEnter(Collision collision)
    {
        Debug.Log("collided");
        // Call the ChangeScene method after the specified delay
        StartCoroutine(ChangeScene());
    }

    // Method to change the scene
    IEnumerator ChangeScene()
    {
        Debug.Log("right b4");
        // Load the scene with index 1 after the delay
        yield return new WaitForSeconds(2f);
        AsyncOperation asyncLoad = SceneManager.LoadSceneAsync("lvl2");
        Debug.Log("should've loaded scene");
        while (!asyncLoad.isDone)
        {
            yield return null;
        }
        SceneManager.SetActiveScene(SceneManager.GetSceneByName("lvl2"));
    }
}

I feel I am doing something wrong...

night mural
#

so does LoadScene, come to think of it

#

oh no it has a default

#

don't mind me

lament birch
# lusty flax isGrounded used OverlapBox (2d) and this all runs in Update

then I think I see why it still detects the ground
it's a combination of two things:
you might get 2 or more Update frames before the rigid body actually moves (as it's updated in FixedUpdate which runs independent of the regular update cycle), so even with a pixel perfect ground detection you might still be detected as being on ground in the next frame(s) as the character hasn't moved yet
in addition, an overlap box check, depending on where the bottom edge of that check is relative to the character's bottom edge, might take a bit of an offset until it doesn't overlap the ground anymore
a quick fix might be to only allow jumping if your y velocity is <= 0

night mural
#

if you're still having issues, try hooking your code up to a button or something instead of triggering it from a collision to isolate some of this

slow reef
night mural
slow reef
#

rahhhh still not workingmf!!!

night mural
#

or you haven't actually gone anywhere

slow reef
#

i did tho

#
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;

public class scenechange : MonoBehaviour
{
    public float launchForce = 10f;

    private void OnCollisionEnter(Collision collision)
    {
        Debug.Log("collided");
        // Call the ChangeScene method after the specified delay
        StartCoroutine(ChangeScene());
    }

    // Method to change the scene
    IEnumerator ChangeScene()
    {
        Debug.Log("right b4");
        // Load the scene with index 1 after the delay
        yield return new WaitForSeconds(2f);
        AsyncOperation asyncLoad = SceneManager.LoadSceneAsync("lvl2");
        Debug.Log("should've loaded scene");
        while (!asyncLoad.isDone)
        {
            yield return null;
        }
        SceneManager.LoadScene("lvl2");
    }
}
#

or is the last line useless

night mural
#

well that's doing both which is definitely not right

#

you don't need the last line

slow reef
#

nothing happens either way

slow reef
#

ight

night mural
#

you see the logs? just once for each? make sure that your coroutine is definitely being started and just the one time

#

put a log after that while (where you had the extra LoadScene) too, you should be seeing that now

#

if you aren't i would imagine you'd have an error

#

basically copy the docs exactly (but with your scene) and make sure that works, then adapt it to your use case

slow reef
#

i tried changing it from collision to just the defautl void Start() and it worked

#

so something fishy is goin on

night mural
#

Yeah something about calling it from the collision doesn't work, though offhand i'm not sure what. I would noramlly guess that it's being triggered repeatedly, but with OnCollisionEnter it shouldn't be (and your logs would show that clearly)

slow reef
#

my friend says it might be because i have a while loop w/ no waits

night mural
#

nah they are wrong -- you just said yourself that it works when you start it in start

slow reef
#

alright

night mural
#

the while will yield each frame that the scene is still loading

slow reef
#

idea: collision enables a separate script which uses void start()

night mural
#

nah you don't need to get that complicated

#

have a boolean that you set on collision and check that in update

slow reef
#

genius

night mural
#

see if that helps

#

it's possible that you can't trigger scene changes from a physics event, though i'm not sure why that would be and i can't find anything saying it

slow reef
#
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;

public class scenechange : MonoBehaviour
{
    public float launchForce = 10f;
    private bool isActivated = false;

    void Update()
    {
        if (isActivated == true)
        {
            Debug.Log("Starting scene change process...");
            // Start the coroutine to change the scene after a delay
            StartCoroutine(ChangeScene());
        }
    }

    private void OnCollisionEnter(Collision collision)
    {
        isActivated = true;
    }

    IEnumerator ChangeScene()
    {
        Debug.Log("Waiting for 2 seconds before loading the scene...");
        // Wait for 2 seconds before loading the scene
        yield return new WaitForSeconds(2f);

        // Load the scene asynchronously
        AsyncOperation asyncLoad = SceneManager.LoadSceneAsync("lvl2");

        // Wait until the scene is fully loaded
        while (!asyncLoad.isDone)
        {
            // Output the progress of the scene loading
            Debug.Log("Loading progress: " + (asyncLoad.progress * 100) + "%");
            yield return null;
        }

        // Scene loading is complete
        Debug.Log("Scene loaded successfully!");
    }
}

didn't work ๐Ÿ˜”

night mural
#

can you post the log output?

slow reef
night mural
#

umm set it to false too

#

when you consume it

#

999+ logs?

slow reef
#

ignore the first 3

night mural
#

um did you do anything to your timeScale?

sour fulcrum
#

I know in a lot of cases parents and contraints work well for this but if i have a moving platform and my player is on the moving platform it's possible to adjust the position correctly via doing some position math in fixedupdate on the elevator right? could someone refresh my memory on that

slow reef
night mural
#

does it work without the 2 second delay?

slow reef
#

i dont think so, let me try

#

let me also try turning the object into a trigger

night mural
#

well you know that part is working since the collision is being triggered/the coroutine started at least from the logs

slow reef
#

yeah but idrk my friend is telling me to try random things

night mural
#

you should try specific things with specific goals in mind instead ๐Ÿ˜‰

slow reef
#

yeah hes just a bit

night mural
#

for instance isolating precisly where your code stops running (before the wait? after?)

slow reef
#

no!!!

cosmic dagger
sour fulcrum
#

would that just be having like a cached position that i set in update and get in fixedupdate thats added on?

#

or is fixedupdate after the movement happened

#

trying to figure out what exactly i would be wanting to add

night mural
# slow reef alright

it seems like the coroutine starts, but none of the while loop actually runs, which i guess takes us back to where we started (the simplest explanation for that would be if this object were destroyed in the next frame, preventing the rest of the coroutine from ever running)

another explanation could be that your timeScale is set to 0 so time isn't progressing and your coroutines aren't ticking...not sure what else

sour fulcrum
#

i guess the difference between last frame and this

cosmic dagger
cosmic dagger
sour fulcrum
#

ya ok that makes sense

slow reef
#

yo i think its workinf

#

one sec

sour fulcrum
#

i guess best place to grab last frame would be lateupdate then? im assuming update works too but

cosmic dagger
#

Use LateUpdate bc that's after the movement has occurred . . .

sour fulcrum
#

every . is a bullet going straight through my heart ๐Ÿ˜ญ

night mural
#

don't take it personally, they always do that catpat

cosmic dagger
sour fulcrum
#

im getting pretty pog in c# and a lot of unity quirks but my kinda math/physics knowledge is really rough

#

no high school education so fundamentals in that regard can trip me up

slow reef
#

it worked

#

apparently i had to just change it to a trigger :PPP

lusty girder
#

Does a capsulecast 'hit' indeed hit against objects in the capsulecast's way? I'm moving objects directly into the "line of fire" of a capsule cast, and have print("Hit something"); inside the If(Physics.CapsuleCast) code, but it never seems to register a hit...

languid spire
fierce shuttle
radiant sail
#

how can i make the 0's just not affect the rotation instead of setting the rotation to 0
basically only rotate on the x & z axis and just ignore the y axis in this example :)
Quaternion targetRotation = Quaternion.Euler(1, 0, 1);

modest dust
#

Just replace that 0 with whatever y rotation you have right now

radiant sail
#

OH ๐Ÿ’€ im so dumb tyyy

languid spire
radiant sail
languid spire
#

lol

radiant sail
#

lemme try smth differed

#

yea it dosent work
basically i have a object that i want to rotate only on the x and z and that object is parented to an object that will handle the y axis rotation and since thats the way im handling it, the value of the transform.rotation.y alwase = 0 which means its the exact same result as just putting 0

radiant sail
#

tysm i didnt even know that was a thing

naive lion
#

can confirmโ€ฆ why did i never use these

mossy sphinx
#

!code

eternal falconBOT
radiant sail
# modest dust Then use local rotation?

that didnt fix my issue but i found out what DID fix the issue, basically instead of making the parent only control the y axis while the child controls the x & z i just reverted my code to before i tried fixing this and just made the parent controll all the movement and not only did this fix my one small issue, its also fixed like 90% of every other issue i had...
thanks for trying to help me with my whacky ass code tho, i appreciate it :)

twilit cliff
#

I'm a newbie to programming, in the screenshot attached, the method is used to spawn objects randomly inside multiple squares precisely.

Can anyone help me elaborate the calculation made inside the method that I'm not able to understand a bit how exactly it works

timber comet
ancient halo
#

Hey there. so I am experimenting with multithreading in unity and have this script to simulate a wave but I cannot get past the error:
UnityException: get_transform can only be called from the main thread.

Like I am so confused...

Code: https://sourceb.in/zGbRcr7kcD

gaunt ice
#

use ijobparallel for transform

vast vessel
#

not code related but i cant find anywhere else to post this.
is there a way to bring the changes from your latest commit in github desktop, to uncommited changes so you can discard some of them?

twilit cliff
twilit cliff
verbal dome
#

So using rotation.y doesn't make sense

north scroll
#

hai, I need help putting on an fbx file of a model into my game, but it seems I cant simply drag it to the player's sprite or add it as a new component, how do I go about doing this ?

vast vessel
verbal dome
#

It will add a MeshFilter and MeshRenderer for you

#

Sprite doesn't work here, as it's a mesh not a sprite

acoustic crow
#

wie kann ich ein code hier rein schicken

#

how i can send a code here

languid spire
#

!code

eternal falconBOT
timber comet
timber comet
#

May be wrong tho

twilit cliff
north scroll
timber comet
acoustic crow
#

@languid spire i dont understand the message !code from unity dyno bot what must i do now

eternal falconBOT
north scroll
#

also, i just dragged over the fbx to the player and like pinned it in front of the capsule ive been using as the player, and it seems to work. But still curious on ur way to do this

#

i had to adjust it tho to be overlapping with the capsule

verbal dome
#

Yeah dragging the FBX itself works too, if it's the only mesh in it (I think)

north scroll
languid spire
verbal dome
north scroll
#

oh sry

verbal dome
#

So yeah you can drag the correct mesh from there if you want

#

This is a code channel btw.

north scroll
#

oh, sry, which channel would I go on? Also, it seems the first thing I tried included the colors and stuff, so ill just stick to that, ty !

languid spire
#

that counts as a large block'

acoustic crow
#

okey wait

languid spire
#

doesn't matter.
you decrement currentAmmo twice for every shot
you check input in FixedUpdate which will be inaccurate

bold nova
#

I have a simple animation on a player charachter in my 2d game, during that animation i try to call an animation event method that detaches one of its children. For some reason that child object occurs in random positions after detaching. The problem is not in colliding with other objects (i tryed to debug.log any collision) and not in animation (child object jumps even if i just call detach method as a regular method, not as animation event) and it's not about velocity (i tryed to set it to 0, but it had no effect) So, why it can be happening?

verbal dome
final kestrel
#

I want to enable the footsteps after waiting for 1 seconds to prevent spamming the auidoclip. It starts after one seconds when I move but It does not stop when player has no movement. https://hatebin.com/mbcmpncfow What am I doing wrong here?

#

Stopping works when I log but the coroutine does not stop.

verbal dome
final kestrel
#

yes you are right. Where do I set it to false? I am confused.

verbal dome
#

Probably at the end of the coroutine and also when you call StopCoroutine

final kestrel
#

Did those but it still does not stop when there is no movement.

verbal dome
#

I'm also not 100% sure if caching the IEnumerator in footstepCoroutine works or not. I usually just do StartCoroutine(MyCoroutine())

verbal dome
rare basin
#

footstepCoroutine = PlayFootstep();

#

pretty sure that wont work as you expect

#

footstepCoroutine = StartCoroutine(PlayFootstep());

final kestrel
verbal dome
#

No, that doesn't magically happen

final kestrel
rare basin
#

not a good idea

verbal dome
#

Unless it's in an if statement

final kestrel
#

it is in an if statement.

verbal dome
#

You need to manually stop/disable the audiosource when you want it to stop

final kestrel
#

hm I do that in the second if in update maybe

#

after stopping the coroutine

#

Okay it works now. Wow

verbal dome
#

Show your updated code just to be sure

final kestrel
#

Here it is.

verbal dome
#

Pretty sure you have to change `the second condition in this: if (!_player.isMoving && isFootstepCoroutineRunning)

#

What if the coroutine stops? Then you can't stop the audio

#

if(!_player.isMoving && footstepSource.enabled) would make more sense

#

For stopping the audio, I mean

#

Maybe make a 3rd if-statement

#
if(!_player.isMoving && footstepSource.enabled)
{
  footstepSource.enabled = false;
}```
final kestrel
#

Like how does it stop if I keep moving?

#

I thought stopping the coroutine would stop playing the sound. That was my mistake as you said. Gotta be more careful T-T.

#

Thanks for the answers

rare basin
#

the coroutine is not your audiosource

#

stopping it wont stop the audiosource

fringe plover
#

Sup, i use Handled.Vibrate(); to make vibration on phones, but its too long, is there any other way to do it?

noble summit
#

how hard is it to learn saving 1 - 10

fringe plover
#

what saving?

noble summit
#

saving system in game

#

saving data

rare basin
fringe plover
rare basin
#

Saving Data in Unity, A complete guide to PlayerPrefs, every function covered, the easy way!

Links to all content (twitter, Instagram, shop, discord etc)
https://linktr.ee/DestinedLinks

Any comments or questions welcome. Enjoy the video!
0:00 Introduction
1:37 Setting up tutorial in Unity
5:26 Saving Strings
10:30 Saving Floats and Ints
15:50 ...

โ–ถ Play video
#

PlayerPrefs.SetInt("saveKey", intValue);

fringe plover
#

Player prefs are ez to hack u know...

noble summit
#

how would you regain your save data

rare basin
noble summit
fringe plover
#

same

noble summit
#

like how would you get it and enter it to regain your save

fringe plover
#

Player prefs are saved on PC

rare basin
#

SetInt/GetInt (save/load)

noble summit
#

but how do you do that in the game itself

rare basin
#

GetInt()?

#

what do you mean

#

int loadedValue = PlayerPrefs.GetInt("yourSavedKey");

fringe plover
#

maybe make player able to save its own custom data?

noble summit
#

nevermind ill figure it out once i get home

final kestrel
rare basin
#

not how long to vibrate

#

this is usually tied to the phone OS and nothing you can do about it

fringe plover
#

oh ok..

brazen canyon
#

But this problem appears ?
These "strings" are different ?

languid spire
#

WriteAllText

#

just read the docs please

brazen canyon
zinc osprey
#

Hi, can you make code run every frame without using Update()?

languid spire
zinc osprey
#

Ok thx. I wanted to avoid this because checking a bool every frame seems like a waste of resources, but I realized I'll be destroying that object very soon anyway so it won't be a problem. Out of curiosity if that object were to stay in the scene forever, how big of an issue is that?

burnt vapor
languid spire
#

if checking a single bool every frame is the worst of your problems you are doing very well indeed

burnt vapor
rare basin
#

and nested loops

#

in nested loops

#

etc ๐Ÿ˜„

burnt vapor
#

.NET is very performant, and polishing performance could be done later. Even then you are better off benchmarking code to figure out what actually needs to be improved

#

If you really want to improve performance, you could try and lift the work of the garbage collector. There are method and features that allow you to manipulate memory better, but this is a very advanced topic.

languid spire
zinc osprey
#

It's for inventory, on canvas so it works, but thanks.

zinc osprey
burnt vapor
#

if you spawn those things often you could also look at object pooling. It's a simple yet efficient way to improve the performance of your game.

pine umbra
#

Hi everyone, is there more effective way to get access to method from other (non-static) class than inherit from it?

low path
#

What do you mean get access to a method from it?

#

Like call it? If you mean just being able to call it, the โ€œbestโ€ approach is highly dependent on situation.

grim raft
#

Hi, why do the wheels seem "laggy" when I focus on the car? When I'm not focusing the car they work fine.
(I'm updating their position in the Update function using raycasts)

worthy merlin
#

Hello, I am wanting to grab a variable known as playerScore and read it in that file in an if statement. Unlike other languages where you can just import them. I am unsure of how I can properly import this variable into another script to use in my update function.

Been googling for 3 days and nothing i've found has been working so far

fading rapids
#

does anyone know why this is ending up behind the canvas when i start the game

low path
#

The Unity way of doing this is to add a serializable reference in the class that wants to access the variable and then to assign to that reference the object whose variable you want. Then you use a method like getvalue() or a public get property to get the value of the variable.

wintry quarry
#

To show images in the UI use the Image component

fading rapids
low path
#

Please provide more info about what exactly you are trying to do.

fading rapids
#

i got it

dapper zenith
#

Is there a less messy way to create a Back Up copy of a script so Unity doesnt get confused with the duplicates and i dont have to always go in a change the class name inside VS as well?

wintry quarry
wintry quarry
#

Are you using version control? Learn to use version control

foggy magnet
dapper zenith
teal drift
#

I have a player with some basic movement and animations, and I changed to the "new" input system because I thought it would scale better, and just to test it I tried doing the same thing as before, but if I reset the animation when the direction vector is (0, 0) it will always trigger and my animation will not appear, and even if I put it at the start and let the other 4 if conditions override it they only last a single frame, and I'd like for a hypothetical OnMoveEnd function, so I can disable it when the key that is being held down gets released

foggy magnet
teal drift
low path
#

Honestly using git for source backup and version control for a solo project is really easy and youโ€™ll never go back once you figure out the two or three commands you need.

wintry quarry
#

You need to set up your Animator for this stuff and use StateMachineBehaviour for the transition notifications

teal drift
#

could you tell me what to set it to

pine umbra
# low path Please provide more info about what exactly you are trying to do.

Well, for example when I have script which generates new room like in rogue-like and it uses method from class which contains all data about sample rooms (what doesn't allows to make it static). Do I have any other ways to get access to this method other than inherit from it? In that case I have to attach all gameObjects which my parent-class does but it is totally unnecessary

teal drift
low path
#

Inheriting from it in this case is a bad idea.

wintry quarry
#

Why are you trying to pick a function from PlayerInput

#

You'd put your own script there and a function from your script

#

I have no idea which event this is for though

pine umbra
teal drift
#

I thought there was a built in thing for it and I was looking for so long

#

all my functions were private

#

thank you

pine umbra
#

or i have to reference to a obj

low path
#

I think you should do a c# tutorial in isolation from Unity to get some of the fundamentals.

pine umbra
#

mkay, maybe I should.. Anyway thx

hallow iris
#

can any one give me some suggestions on level desing

#

and a level that can be parkor able

#

for 2d

low path
#

Not a code question and also highly dependent on your game design.

worthy merlin
buoyant knot
# hallow iris for 2d

btw the mario maker community will have extremely deep knowledge when it comes to answering your question

worthy merlin
#

ouch

buoyant knot
#

the most common pattern will be:
public float score {get; private set;}

#

the point is to keep the setter protected by restricting its access

#

but allow more classes to read the value

worthy merlin
#

But would the method be correct? playerscore.get()?

buoyant knot
#

you donโ€™t need to call it like that

worthy merlin
#

oh?

teal drift
buoyant knot
#

you can do
float myVariable = score + 4;

#

you do not need to explicitly call .get, as it it a property

#

you can also do:
score++;

#

which calls the setter and getter, each

#

get and set are keywords. they do not need to be written like methods, if that makes sense

low path
buoyant knot
#

also
public float score {get; set;} = 5;
is kind of pointless, because that might as well be made a non-serialized field.

#

youโ€™d only do that when you want to actually add code

#

like

private int _score = 5;
public int Score {
get { return _score; }
set {
   if (_score == value) return;
   _score = value;
   OnScoreChanged?.Invoke();
} ```
#

in this case, Iโ€™m actually doing stuff whenever score gets set. So it has a backing field (_score), and I can do stuff whenever it gets set

#

eg Score++;
this will set _score to one higher than the current value, and then invoke OnScoreChanged

#

@worthy merlin understand?

hallow iris
worthy merlin
# buoyant knot <@398889539059318786> understand?

I hope so lmao.
So I have it setup with that now in my LogicScript however in my PipeMoveScript the playerScore is not recognized within my update.

    void Update()
    {
        if (playerScore >= nextAssignment)
        {
            moveSpeed *= speedPercentIncrease;
            nextAssignment += 1;
        }
buoyant knot
#

is playerScore defined in LogicScript?

hallow iris
#

I am working on a game with like a confined vertical platforms and you need to parkore to get to the top it is my first game I am working on it Is just to learn unity but I still want to make it something playable

vagrant gale
#

Hi guys, I have a Resource folder with a couple hundred of prefabs. I want to loop through all of them and change the materials GPU instancing to "true". How do I access the actual material files for each of the game objects?

rare basin
#

t: Material in proect

#

select all, set gpu instancing to true

vagrant gale
rare basin
#

you cannot tell which material belong to the object and which not

vagrant gale
#

could i not load the prefab and check the renderers material list for this?

#

the problem i have is that the material on the renderer is only an instance

spring kayak
#

Hello, any ideas on how a katana attack can be implemented on unity? i thought about making a script on the enemy object and it reduced its hp oncollision with an object weapon

strong wren
spring kayak
#

how would you do that? i mean lets say we use the oncollisionenter method, then what?

strong wren
#

Get health component of whatever it hit and do its thing.

zinc osprey
#

Hello, can someone explain why this debug is giving me this error?

timber comet
zinc osprey
timber comet
#

Put it with the other using stuff

#

And you should be good

zinc osprey
#

ye it works

#

thx โค๏ธ

timber comet
#

Np

swift crag
#

yeah, there are a bunch of namespaces that Image can come from

short agate
#

Hi, I don't even know if this is where you ask this type of question. I have this problem, I've been learning for about 4 days just how to make games, I'm following a tutorial, but my character looks like this when I jump on the wall, so the bug appears and the player manages to get around it and jumps off the walls. I've already reviewed everything and I don't know what else to do...

swift crag
#

I do not understand what the problem is.

#

"but my character looks like this"

#

is this a visual problem? a gameplay problem?

shell sorrel
#

like a visual thing, or is this gettin stuck on colliders you dont think it should be?

rocky canyon
#

classic velcro wall?

short agate
#

Both, it visually looks like this sometimes if you just jump on the wall, and it also affects the game, since if the player wants to "cheat" he can keep jumping on the walls....

rocky canyon
#

yup, velcro wall

empty dust
#

pretty sure he addresses that in the vids no?

rocky canyon
#

on ur colliders/rigidbody you can use a low friction Physics material

#

and it'll slide right off

short agate
#

No, I think it must be the collider. tilemap collider 2d. but I don't know what to do. He gets shaking sometimes too, when you press him against the wall

rocky canyon
#

? is it a rigidbody playr?

#

how u moving it?

swift crag
#

okay, so the problem is that you're getting "stuck" on walls

rocky canyon
#

it shouldnt be shaking at all

empty dust
#

let me check my unity i was follwing the same tutorial lol

#

with the deadpan german guy right?

short agate
#

As I don't speak English, I'm translating, maybe they're not extending it hahah, I'll send a video

empty dust
#

lol okay that maybe it

#

maybe screenshot how you've set the terrain up too

short agate
worthy merlin
#

Srry for the delayed response. in School rn

shell sorrel
short agate
#

portugues brazil

empty dust
#

have you placed the terrain and background on seperate layers?

shell sorrel
# short agate

you are not moving your player using the rigidbody but its transform directly, that is the root of all these issues

short agate
#

I'm following the tutorial hahah

#

he had no problems with his

#

So to solve it I would have to change how the character moves? I thought there was something wrong with the collider jkkk

low path
buoyant knot
low path
#

you should also move the "getcomponent<enemyManager>" to outside the loop, at least assuming there is only one manager

buoyant knot
#

if you just write playerScore, it will check its own class for that variable, but wonโ€™t find it because thatโ€™s not where you put it

amber spruce
#

why doesnt this work

Spectating.activeSelf.Equals(true);

i debugged it and after that is done it still is false

swift crag
#

did you actually check the value of activeSelf

#

oh, I think I see what you're thinking here...

amber spruce
#
Spectating.activeSelf.Equals(true);
Debug.Log("Spectating is: " + Spectating.activeSelf);

yep

swift crag
#

that just checks if activeSelf equals true

#

it doesn't mean "set it to be equal to true"

amber spruce
#

oh it doesnt

swift crag
#

yes. Equals is defined for every single kind of C# object

#

it's used to test if two objects are considered equal

amber spruce
#

k thanks

swift crag
#

activeSelf is read-only

amber spruce
#

i fixed it

swift crag
#

just use SetActive to change the active state of a game object

shut spade
#

when does it happen?

queen adder
# shut spade when does it happen?

Seemingly randomly. When I add a component, when saving a prefab, when switching to another software tab, at any moment in any scene, etc..

#

Sometimes happen many times in a row, sometimes doesn't happen for an entire day

shut spade
#

i think it could be a corrupted file, lack of memory or an script that might crash it idrk

swift crag
#

I'd delete the Library folder and let everything re-import

#

see if the editor behaves any better after that

#

it'll take a while to do that

#

the editor will forget a few things, like which scene you had open

queen adder
swift crag
#

no, probably not that long

#

especially for a small project

rich adder
queen adder
#

Oh ok that sounds ressuring haha

#

What if that doesn't work?

rich adder
#

well try that first, then come back ๐Ÿ™‚

queen adder
#

Sure

rich adder
#

you are using unity 2019?

queen adder
coarse shore
#

anyone got a good yt channel that teaches unity in different parts and explains it rlly clearly?

languid spire
eternal falconBOT
#

:teacher: Unity Learn โ†—

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

coarse shore
#

TYSM

#

ill watch both of them

rocky canyon
#

unity learn is more like txt / video / project type lessons

rich adder
#

structured course *

rocky canyon
#

there ya go ^ its that

languid spire
#

but Sebastian is definitely not for a rank beginner

rocky canyon
#

so you wont be watching unity learn.. more like engaging, reading, watching, doing

rocky canyon
#

but i agree as he does standalone projects they're pretty code heavy and he doesnt explain much

languid spire
rocky canyon
#

yes agree'd, some of his stuff he forgets to show bits of code that makes the entire system work.. so u sometimes have to go solo and figure out that missing piece ๐Ÿ˜…

coarse shore
#

imo, he's explaining things quite clearly, but that might be bc im already doing python at skl so some of the terms r linked

rocky canyon
#

yea ull be good using both

languid spire
#

everyone wants a magic 'Make my game' button

coarse shore
rocky canyon
#

awesome! lol

languid spire
#

nice try, doesn't exist either

coarse shore
#

btw is c# " or ' sensitive?

rocky canyon
#

oh and !ide not sure uve done this

eternal falconBOT
coarse shore
#

like does it matter which quotation we use for strings?

rocky canyon
#

but make sure ur stuff is configured correctly before u go hamm on the code

#

i think " is encouraged

languid spire
rocky canyon
#

c# is also case sensitive

#

very moody language imo

coarse shore
rocky canyon
#

but straight forward

coarse shore
rocky canyon
#

wtf is unity arc?

#

like you went on a unity learning spree for 4 days?

coarse shore
#

yes pretty much

summer stump
# coarse shore basically like python

Python and c# are significantly different in many ways. It's one of the more difficult language jumps.
But of course most programming concepts are the same. There are variables, loops, condition flow, etc

rich adder
rocky canyon
#

i made a bot with python and i had enough.. i much prefer c#

coarse shore
#

is it similar right?

summer stump
#

Yes

coarse shore
#

oh

#

alr

rich adder
#

aren't most langs case-sens lol

rocky canyon
#

i mean similar as in both are languages that can make stuff..

coarse shore
#

what does void mean?

summer stump
swift crag
#

void is a special type that means "nothing"

rocky canyon
#

well i mention that because 5/10 problems i see ppl with are just simple spelling errors

swift crag
#

you can't create a variable of type void

coarse shore
#

sebastian uses void to make a function, what does void do in that?

rocky canyon
#

if ur function u write doesn't need to return anything back then its void

swift crag
#

you don't use void to "make a function"

#

void is simply the return type of the function

rocky canyon
#

functions can return data back

#

but you'll learn that farther on

swift crag
#
public void Whatever(int parameter) { Debug.Log("The value of the parameter is: " + parameter); }
rich adder
swift crag
#

this declares a method (a function that is part of a class) named Whatever

#

it takes one int parameter..named parameter!

#

and it returns void, meaning it doesn't give you anything back

coarse shore
#

oh i see

swift crag
#

Every method declaration must have a return type

coarse shore
#

when would u need to use void?

swift crag
#

when your function doesn't return anything

rich adder
coarse shore
#

lol

rocky canyon
#
   int AddNumbers(int a, int b)
    {
        return a + b;
    }

    void SayHello(string name)
    {
        Debug.Log("Hello, " + name + "!");
    }```
#

void doesn't give anything back.. it only takes in the string and Displays it with "hello" attached

int is an integer of course.. so that function AddNumbers can take in two ints.. and return back one.. (in that case its just adding them)

#

and both of those are private

rich adder
rocky canyon
#

exactly

#

lmao

coarse shore
#

how would u call them, would u just do "int AddNumbers(1, 2)" ?

#

to call the first function

#

btw ik that u dont need to put 1 and 2

#

u can put any numbers

rocky canyon
#
using UnityEngine;

public class Example : MonoBehaviour
{
    void Start()
    {
        int result1 = AddNumbers(1, 2);
        Debug.Log("Result of AddNumbers: " + result1);
    }

    int AddNumbers(int a, int b)
    {
        return a + b;
    }
}```
#

anytime u needed those two ints added ud just call it like normal.. in that case we declared a new int called result1 and set it to be w/e that function returns

#

so result1 equals 3 when it runs

coarse shore
#

alr i understand

#

so to call it u js do AddNumbers(1, 2)

rocky canyon
#

;

coarse shore
#

oh yh

#

mb

rocky canyon
#

yea basically

coarse shore
#

alr ty

rocky canyon
#
    void Start()
    {
        int number1 = 1;
        int number2 = 2;

        int result1 = AddNumbers(number1, number2);
        string resultString = "Result of adding " + number1 + " and " + number2 + ": " + result1;

        Debug.Log(resultString);
    }
rich adder
fathom bramble
#

Hey all!

I uploaded my unity project to GitHub so I can work on it from multiple devices.

But this only worked if I used a .gitignore which ignored some of the larger directories in the project folder such as Library.

But if I clone my repository on my other device, will unity project still work? Will those folders auto generate from the editor?

Thank you!!

languid spire
#

yes

fathom bramble
#

Thanks! Was I right in assuming theyโ€™d autogen then?

languid spire
#

yes, you could have tried this in the time it's taken to ask this question

fathom bramble
#

I guess I could have tried cloning it into a new repos

#

Either way, thanks!

tepid cove
#

where can i find the link to setup vidual studio code so its not all blue?

eternal falconBOT
#
Visual Studio Code guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

https://on.unity.com/vscode

tepid cove
languid spire
fathom bramble
#

Either way, the assurance helps

hearty trout
#

Hey Ima have my first game be a turned based movement strategy game where you pilot your character to explore all 3 duegons or sum and then have them have keys and when key = 3 u can do the boss battle ig how does that sound instead of an rts to start ๐Ÿ’€ AKA a tactis engine game ig

languid spire
#

no cloud required

fathom bramble
#

Is unitys source control better than GitHubโ€™s? Never tried it

languid spire
#

imao, it's crap

#

stick to git

swift crag
#

I didn't enjoy using it when it was still branded as Plastic

fathom bramble
#

Fair enough ^^

swift crag
#

Lots of weird problems with the editor integration

#

I could not trust it to work correctly

languid spire
#

if you really want a good laugh (read cringe) install the Version Control package and then go and look at the source code

rich adder
#

Unity still trying to compensate for bad investment, kinda funny they are beating a dead horse at this point. No amount of "in my face" about VC in hub is gonna make use that trash

languid spire
#

it's rubbish, worse than that, it's dangerous rubbish because it lulls unsuspecting users into a false sense of security

rich adder
#

yeah exactly, the ones who come here and have a problem is usually unity's VC and not git, very rare you get git problems

languid spire
#

git is great, when you take the effort to learn it, in the wrong hands it too is dangerous as we see too often here

coarse shore
#

this might be a confusing question but can a class be inside of another class?

languid spire
#

yes

coarse shore
#

alr ty

#

i thought i was wrong to assume that ๐Ÿ’€

languid spire
#

not a problem. you just reference it as MyClass.OtherClass

coarse shore
#

would u call the class the same way u call a function?

rich adder
misty helm
#

I would say, you probably want to avoid it.

coarse shore
#

alr

#

lol

misty helm
#

I'm not sure where to ask this.
Does Unity Version Control have an equivalent to Github Issues?f
And Can I make a Project Public?

rich adder
#

here we go again..

#

we were just talking about this UnityChanLOL

rich adder
#

its not very intuitive system

#

your best bet is to ditch that mess and just stick to Github + git

misty helm
#

good to know. Thanks

summer stump
languid spire
#

pretty sure a UVC project cannot be public

coarse shore
final kestrel
#

Hey guys. I have a question. I have a footstep sound that is 2 seconds long. One step starts at 0 and the other at 1. Which leaves the last second empty. I have this code here that handles the audio source responsible. I used coroutine because I wanted to prevent w spamming and the sound. I put a delay to stopping time as well. The script works what I want it to but there is a problem. I want it to complete the footstep if its already started and not immediately stop after the delay. Do I need 2 footstep sounds or can I do anything in the script? https://hatebin.com/adejjjcfdp

polar acorn
languid spire
polar acorn
#

I think it's the f typo after the question mark, my brain just went "Yep it's a float" and stopped reading

languid spire
#

rofl

queen adder
rich adder
queen adder
rich adder
languid spire
rich adder
#

its worse going backwards

#

ie from newer to older

languid spire
#

Unity does not support project regression

rich adder
#

ya if you know what ur doing some stuff can be fixed, by manually messing with the manifest

languid spire
#

export/Import if you want to regress, it's the only sane way

swift crag
#

as long as you don't go back to a version that serializes your assets differently, you'll...probably be okay

#

wink

queen adder
#

Yeah I can try that, it's just strange the log doesn't say anything about the freezes

rich adder
rich adder
#

also did you try a new project to make sure it isnt your Unity version ?

ashen wind
#

I'm trying to get a ui object to follow the mouse, so I have this

    void Update()

        if (icon_dragging)
        {
            icon.rectTransform.position = Input.mousePosition;
            Debug.Log(icon.rectTransform.position);
        }
    }

and it's printing out the mouse position, but the ui object isn't moving at all

modest dust
# final kestrel Hey guys. I have a question. I have a footstep sound that is 2 seconds long. One...

So basically you have 2 footsteps in one audio file and want the currently playing footstep sound to complete when the movement stops?
Just have 2 separate audio clips and play them alternately.
Also I believe there is no need for any coroutines here or (de)activating the audio source all the time, just check the methods and properties available for AudioSource, you can change the clip and call PlayDelayed(delay_in_seconds):
https://docs.unity3d.com/ScriptReference/AudioSource.html

ashen wind
#

I feel like I'm missing something obvioous

rich adder
languid spire
ashen wind
#

I'm still not clear on the difference between anchoredposition and position though

#

and switching it to anchoredposition didn't seem to do it

final kestrel
ashen wind
summer stump
queen adder
final kestrel
#

I will write the whole thing using Audiosource methods then. And figure out how to play them succeedingly.

rich adder
#
[SerializeField] RectTransform rt;
    private void Update() {
        rt.position = Input.mousePosition;
    }```
ashen wind
#

yeah but that's a regular gameobject right? mine is a ui object parented under the canvas

#

does that make a difference?

rich adder
summer stump
#

Since it is using rect transform

rich adder
#

not relavent

ashen wind
#
        GameObject icon_obj = new GameObject("icon");
        RectTransform trans = icon_obj.AddComponent<RectTransform>();
        trans.transform.SetParent(transform);
        trans.localScale = Vector3.one;
        trans.anchoredPosition = new Vector2(0f, 0f); 
        //trans.sizeDelta = new Vector2(150, 200); // custom size
        icon = icon_obj.AddComponent<Image>();
        gameObject.AddComponent<BoxCollider2D>().size = trans.sizeDelta;
#

this is how I declare it

#

is something in here messing with the code or something? like the anchoredPosition or the parenting?

summer stump
rich adder
#

btw recttransform can just be casted from transform

#

RectTransform trans = (RectTransform)icon_obj.transform (assuming your object does have RectTransform)

ashen wind
summer stump
rich adder
#

also yeah just use a prefab it and instantiate

low path
#

at the very least, a prefab would let you play around with the settings until it behaves right

acoustic crow
queen adder
#

Yeah lol?

summer stump
#

No, not smart enough

But it may have to do with SaveCoinUpdate being empty
And CoinToString never being called

rich adder
#
 void SaveCoin()
    {

    }
    void SaveCoinStart()
    {
        
    }
    void SaveCoinUpdate()
    {
        
    }```
help my coins arent saving
queen adder
#

Also this should 100% be its own class

polar acorn
queen adder
#

Did u copy and paste the code?

rich adder
#

never noticed this built in functionality in github

molten saddle
#

can enyone help me?

molten saddle
#

hey

#

but i need help

queen adder
#

Just ask

rich adder
frigid sequoia
#

How could I store all the base materials of a object and replace all of them for another material for a while and them back to the original ones?

summer stump
swift crag
molten saddle
swift crag
#

the array you get is a copy; it won't change when you replace the materials

rich adder
neon fractal
#

Why does the beam go further than its range?

queen adder
#

Why did u copy the method so many times?

#

It says u defined the same method like 5 times

frigid sequoia
summer stump
#

Those line numbers!

molten saddle
#

just tell me how to fix it and ill be going

summer stump
swift crag
rich adder
molten saddle
#

oke

swift crag
#

The array the property returns isn't the array that Unity is using to store the materials. It's as new copy every time you get the .materials property.

#

So modifying its contents directly won't do anything

#
renderer.materials[3] = ...
languid spire
swift crag
#

this sets index 3 on the returned array

molten saddle
#

thanks

swift crag
rich adder
#

yes perhaps learning basics of c# before you try to Mod anything..

molten saddle
#

ok bye

#

dang it

summer stump
queen adder
#

Ur deriving from a interface

eternal needle
queen adder
#

Meaing you HAVE to define those methods that are in the interface

frigid sequoia
swift crag
#

And if you want to remember the original materials, store materials in a field before you do that

molten saddle
#

witch one

rich adder
swift crag
#

I presume this is some kind of gorilla tag mod

low path
# neon fractal Why does the beam go further than its range?

if i'm reading this corrrectly, i believe what you are doing is casting a circle 5 units from the origin of your guy, where the circle has a radius of castRadius. i think that what you want to do is cast it at a distance of 0, with your cast radius.

queen adder
#

I would hope so

summer stump
neon fractal
low path
ashen wind
#

but it still doesn't move

#

the debug says the values are changing

#

but the inspector doesn't

low path
#

did you show your object hierarchy?

rich adder
ashen wind
#

i'm getting a null reference exception now on icon.sprite = sprite;

#

even though icon is referenced in the prefab

#

Icon is an Image component

#

so it has a .sprite property

#

icon is null

#

that's the problem

#

but I can't see why it would be when I've given it a reference in the prefab and I'm spawning the prefab

rocky canyon
#

you have to spawn the box and then get its icon.. if i think im seeing this right.. you can use a reference of something inside the prefab.. i think ur referencing the prefab from the project window. and not the instance of hte prefab that u actuallly spawn in the game

#

is that right?

ashen wind
#

ok nvm the null reference exception was unrelated and i solved it

#

but the image still doesn't move

wind raptor
#

I have a ui button that calls a function on an event trigger. On the same gameobject as my button, I have a script with a boolean member. Is there a way to either call a different function based on that boolean member, or to call a function with that boolean member as a parameter, while keeping things mostly in the inspector?

rich adder
ashen wind
wind raptor
#

How can I access this parameter?

worthy merlin
#

Google didn't do a great job explaining this; Does a static Variable not get reset whenever I reload my scene?

#

I got a playerScore variable and despite the scene restarting it starts on 10 instead of 0

queen adder
wind raptor
eternal needle
queen adder
#

Show the script?

#

Does the DoThing() method have a bool parameter?

#

U cant access parameters from a method?

wind raptor
worthy merlin
queen adder
#

When the method is called do some internal logic instead of trying to change what parameter gets passed into it

#

Have a field on the class thats a bool and check it that way

wind raptor
#

Basically I'm trying to create a "latching" button. When clicked, it calls a function. When "unclicked", it calls a different function. My boolean parameter was just an attempt at a workaround.

queen adder
#

U shouldnt be trying to change method parameters via the inspector IMO

#

Oh u should look into the OnPointerDown and OnPointerUp

#

When the mouse is clicked and Released

rocky canyon
#

yea. lol thats weird.. thats more like a simple way.. if u want a button to passing in false or true.. or w/e u could just call different functions instead

wind raptor
#

Sorry, not unclicked. When clicked, one function, when clicked again, a different function.

#

So I'm tracking, on the button side, whether the button is latched. If latched, clicking it calls a different event

#

And unlatches it

queen adder
#

Yeah you should do internal logic on the methods themselves to check the current state

#

You can still use the UnityEvent for whatever method. That method just has to check whats going on

rocky canyon
#

if ur doing stuff like latching it and tracking it.. ur logic should know everything..

#

no need for that exposed bool..

queen adder
#

Yeah?

rocky canyon
#

thats for the inspector

queen adder
#

When its via the Inspector thats pretty much a constant parameter for the method

rocky canyon
#

like if ur wanting a quick button to do one thing or the other.. u can tick the bool (in the inspector) for different behaviours

#

but if ur using the same b utton to do many things.. ur logic should just keep up with that

queen adder
#

agreed

wind raptor
#

Yeah I don't actually like that workaround where I'm changing the boolean value getting sent as a parameter. My whole goal here is to keep everything decoupled and have a button with an extra state (whether it's latched or not) which changes the event called based on whether the button is latched, while making use of the unity event system

queen adder
#

Again

wind raptor
#

I know how I could do this with additional references, but I was hoping to have this latched button object which is just as simple as possible

queen adder
#

You dont need additional references

#

Just have a bool that checks if its latched or not and that method can have a simple if statement

#

That class just needs to be on the same Gameobject as the button

rocky canyon
#
 private bool isButtonPushed = false;

    // Method to handle button push logic
    public void ButtonPush()
    {
        if (isButtonPushed)
        {

        }
        else
        {

        }
    }

    public void ToggleButtonState()
    {
        // Toggle the button state
        isButtonPushed = !isButtonPushed;

        // Call the button push method
        ButtonPush();
    }
#

u call the same method each time.. and let ur logic do the handling, edit: you probably could call the ToggleButtonState() and that would handle latching or w/e

queen adder
#

in ur case horsepork

#

if (IsLatched)

#

Unless were missing something?

rocky canyon
#

no reason to have that variable exposed if ur just gonna pass in a variable to change it

#

thats all im sayin

wind raptor
#

Here's where I lose the convenience of Unity events though. For a normal button, I can just add the function call that happens when the button is clicked. Boom, easy. What I'm trying to accomplish is the same level of convenience using my latching button. And I'd like to keep the "latched" boolean on my button object, because I visually change the button based on whether its latched

queen adder
#

If im reading this correctly

#

U cant do that via the Inspector at runtime

wind raptor
#

That's what I'm becoming convinced of.

rocky canyon
#

lol, yea that tickbox is for the developer

wind raptor
#

Forget the tickbox

rocky canyon
#

not the code ๐Ÿ˜„

#

i cant forget it.. ur logic was all based off it

#

did u ever share ur code?

queen adder
#

It was pseudo code

rocky canyon
#

u want a controller script for the button

queen adder
#

he didnt even name the class

rocky canyon
#

this isnt how u should be thinking

#

u want the script thats controlling the button to know if its latched or not

#

and keep up with it

#

if something needs to know the buttons state it can ask the script

queen adder
#

Yeah thats why i said if im reading this correctly?

rocky canyon
#

not the button object

queen adder
#

Yeah it should be inversed

#

Its not bad to do something by code

frigid sequoia
#

When it shows (instance) it means that if I were to modify the material, it would only affect this instance right?

rocky canyon
#

yeap

#

most times you need to copy the material.. change it and then reset it

wind raptor
rocky canyon
#

changing stuff on materials gets iffy

queen adder
#

Theres a class that button derives from

rocky canyon
#

so have a reference to it

#

it would know ALL the states of thebuttons

queen adder
#

I cant remember the name but u can make ur own button with extra functionality if u insist on no references

frigid sequoia
# rocky canyon changing stuff on materials gets iffy

Yeah, I just wanted to swap the materials to something transparent while they do sorta of an spawn animation; but still not sure how to do the full thing though, so I have been trying different approach for the last few days

buoyant knot
#

modifying the material itself can be tricky because shaders are more complex. But swapping from one material to a different material (both of which are already made) should be fine

rich adder
#

netcode

rocky canyon
#

it'd be something like this.. the button script handles all the states the button can be in

wind raptor
#

This is becoming more of an intellectual exercise than practical at this point, but yeah a reference to the button may be necessary.

One last attempt at a workaround. Can I have a serialized field for a function call from a different object? So that I could drag in an object and specify the function, just like it is done for unity events?

queen adder
#

again theres a button class

#

UISelectable

rocky canyon
#

Button! i dont know anything about the Button class lol

wind raptor
rocky canyon
#

never had to use it.. not really modifying my buttons beyond making them interactable or not

queen adder
#

It has all the same stuff u need for a button

#

And u can add ur own stuff to it

rocky canyon
#

ya u can

#

you can use the UnityEvent system i believe

#

to invoke but idk about any of that

queen adder
#

Theres more classes to derive from then just The MonoBehaviour inside of unity

grim raft
#

Hi, I'm applying some forces to an object to make it move in the FixedUpdate, should I multiply the forces for Time.deltaTime? When should I do that?

buoyant knot
summer stump