#💻┃code-beginner

1 messages · Page 225 of 1

languid spire
#

how can I answer that when you didnt provide line numbers. but to get any further help here you must configure your ide first

grim pecan
#

i figured it out

#

i mispelled the smallest little tiniest word

#

i hate coding so much

languid spire
#

no you did not

rocky canyon
#

root parent is rotating the blip w/ the offset..
the blip itself is rotating towards the camera..
(2 rotations)

grim pecan
rocky canyon
#

if you hate coding, why u doing it? 🤔

lethal bolt
#

That was Confusing but now it rotates Automatically

languid spire
grim pecan
rocky canyon
#

ahh school..

lethal bolt
rocky canyon
#

it should be controlleable with the keys now..

#

altho its either gonna go one way or another..

#

need an else statment.. if ur not pushing w or s (rotation of 0) soo it doesnt keep rotating

ashen wind
#

I'm running into a weird bug with raycasting

#

I've got an inventory with a bunch of boxes that have boxcollider2Ds

#

and when I mouse down I want it to raycast and grab the box you're dragging the item from

#

and when I mouse up I want it to raycast and grab the box you're dragging the item to

#

the problem is, when I do the mouseup raycast it gets both boxes

rocky canyon
#

you'll probably need one of those raycasts to ignore the item itself

ashen wind
#

which should be impossible

rocky canyon
#

so it can raycast thru it and hit the box below it

#

layermasks 👍

ashen wind
#

oh

rocky canyon
#

well how would ur raycast hit the box itself then?

ashen wind
#

wait

rocky canyon
#

lol

ashen wind
#

i just realized what i'm doing wrong

rocky canyon
#

rubber duck moment

#

all u had to do is talk it out 😄

ashen wind
#

i'm dragging the icon of the axe

#

but the icon of the axe is the thing with the collider

#

not the box

#

so it's under the mouse when I release it

rocky canyon
#

mmhmm

#

so u ignore it completely w/ that 2nd raycast

#

or should

ashen wind
#

yeah let me try that

rocky canyon
#

or heres another idea...

#

disable the collider once u pick it up

#

😉

lethal bolt
#

Only the S works?

scarlet tiger
# lethal bolt Only the S works?

not sure what you are asking but you have two if blocks, that else is only a part of the second one. That indentation above with the {} does nothing fyi

#

but describe your issue more, what are you expecting to happen?

grim pecan
#

I clicked play on unity but didn't notice the error in the bottom right saying "The reference script (Unknown) on this Behaviour is missing" and now i cant do anything in unity, like its stuck on play but nothings moving and i cant click anything on it

lethal bolt
#

W for + and S for - but When i press S it goes +

scarlet tiger
#

you're setting the angular velocity to the same thing for both cases..

lethal bolt
#

Lol, but still it only Work with S

frigid sequoia
#

This should be more of an interface than a superclass rigth?

scarlet tiger
#

read the code line by line as if you are pressing W

frigid sequoia
#

Cause I am very confused about when I should use interface

short hazel
#

If GeneralPowerUpLogic itself is not meant to be attached to a GameObject, only one of its derived classes, then make it abstract.

#

Note that with an interface, you won't be able to declare all these serialized fields, and the OnTriggerEnter method.

frigid sequoia
short hazel
#

If you plan on having some implementation and shared members, like you have now (name, description, activation logic), then go for an abstract class.

queen adder
#

An abstract method is pretty much the same as a normal interface

grim pecan
#

i hate unity so so so so so so so os os os o so much

queen adder
#

Whats wrong?

grim pecan
#

it crashed and i thought i had saved it but no

#

i never saved it at all

#

i have to restart

#

write everything again

#

make all the prefabs again

queen adder
#

That's more so a you thing then unity.....make sure you save often

#

There's packages that will enable you to autosave

rich adder
queen adder
#

I will admit there's no reason unity is this old and doesn't have a autosave feature

short hazel
#

Code is saved from the code editor. After a crash, Unity will open a default empty scene, open the one you have saved by going through your Assets and well, opening it

grim pecan
queen adder
#

I believe they're saved into the project as soon as you drag them into the editor

rich adder
rich adder
#

but also, start using Version Control for you scripts

queen adder
#

I mean for scenes

rocky canyon
#

but working in ur scene is dynamic..

#

i would hate for my scene to save all the time

#

esp when im just testing stuff

queen adder
#

That's true

rich adder
#

pretty sure you can recover also a crashed scene if you don't open unity yet, there is a temp file

rocky canyon
#

they make assets that do it if u want

rich adder
rocky canyon
#

also true

rich adder
#

they're just lazy lol

native seal
#

when I try to place tiles using SetTileBlock it places empty tiles. Is that a limitation of the function since it has to be a square area?

sage folio
#

hey so with this 2D platformer movement script, https://hatebin.com/bjvuemtuyl, I'm following a tutorial so i'm not really entirely sure where to put this, but how/where in the code do i check for if the player is moving? (i'm connecting the inputs to an animator)

lost anvil
#

im trying to change the item i pick up's text to whatever i set it as but it is giving me this error been trying to fix it for ages this TMP stuff is shit

code - https://gdl.space/toxicoxayi.cs

languid spire
lost anvil
#

through a raycast

#

so when i look at the object it enables else it disables

languid spire
#

no, I mean with which line of code

lost anvil
#

line 34 - 43

languid spire
#

but what does the line read, show me

lost anvil
#

i sent the script

languid spire
#

I know, show me the line

lost anvil
languid spire
#

ok, so why do you do that and not
itemText = true or itemText=false ?

outer cobalt
#

even if i jump it goes back to walk when i dont want to play that right now

lost anvil
languid spire
#

I know what you want to fix, I'm trying to get you to understand what you are doing and doing wrong

lost anvil
languid spire
#

exactly so why try to set a string to it?

lost anvil
#

itemText = hit.collider.GetComponentInChildren<TextMeshProUGUI>().text;

how is is that a string?

#

i swear its the same thing as the variable

languid spire
#

enabled is a property of itemText which you can set to true or false.

languid spire
sage folio
lost anvil
#

ok how do i fix it

sage folio
#

hm, one sec lemme check something

languid spire
#

as I said, you use itemText.enabled because the enabled property can take a bool variable so maybe itemText has another property that can take a string variable

sage folio
#

it just seems like your walk animation is going on too long

languid spire
#

well have a look, that is what your ide and the documentation is for

fathom mist
#

It seems like there's already a conversation going on about walking animations haha I joined for help with that too

sage folio
#

on the arrow going back to idle?

lost anvil
outer cobalt
languid spire
lost anvil
#

cheers mate

languid spire
sage folio
#

could you show me the ramp too?

fathom mist
#

Is there a separate window for sprite animations? I understand how to code a character moving around and kind of how to put in a sprite to rotate buut I'm not sure how to get a proper walk cycle going

sage folio
outer cobalt
#

im trying sum out right now

fathom mist
#

Window might not be the best word for it

sage folio
sage folio
lost anvil
outer cobalt
#

im noticing too that if i move the isWalking stays true for a couple seconds too before returning to false

sage folio
languid spire
lost anvil
#

yeah cheers good help

sage folio
outer cobalt
sage folio
#

i get it man, i'm still having trouble with my script (its a little higher up here, i'm just sitting here waiting for a solution of some kind 🥲)

outer cobalt
#

if i cant figure it out ill take a look tomorrow, i dont wanna get frusterated at it 🙂

sage folio
#

if i'm being honest your code is a little confusing, i guess i don't usually put all of my animations into a function to use, because i usually just add the setbool straight into the checks themselves, but let me see if there is a problem with the timing of calling the functions

wintry quarry
#

you're checking if the x velocity is exactly 0

#

that's not going to happen immediately

sage folio
#

oh yeah!

#

that actually makes sense

outer cobalt
#

ah so i am thinking too uh, advanced lol

sage folio
#

yep

outer cobalt
#

so from where should i check it then? lol

#

sometimes i check everything and i dont think about the base and its frusterating at times hahahah

sage folio
#

if i'm being honest the script feels over complicated for what you are trying to do (although i fully understand and it still works fine), i would usually just call for if the player is touching a layer that i make for all ground objects/using collisions as i am right now for my project

#

if you have a groundcheck

#

you could look into considering putting the setbool there

outer cobalt
#

yessir a groundcheck and a wall one

#

but im building it this way so i can easily control it when it does get advancer

sage folio
#

ok so i have a better idea then

outer cobalt
#

hahaah i fixed it

sage folio
#

you did?

#

how?

outer cobalt
#

well now it only works to the right

sage folio
#

:|

outer cobalt
#

hahahaha uhhhhhhhh

sage folio
#

confusing

#

well i don't really know how to help then, you could instead of checkling for exactly 0 just check if under the max and above the minimum

swift crag
#

Choose some small value and test if you're at least that close to zero

#
if (Mathf.Abs(current) < threshold) { ... }
outer cobalt
#

fixed it but i did it differently and i dont know if that is gonna cause issues

#

i instead put the if (Mathf.Abs(rb.velocity.x) > 0) { isWalking = true; } else { isWalking = false; } into FixedUpdate

swift crag
#

This is testing if your velocity is not exactly zero

outer cobalt
#

the threshold should be a small value above 0?

swift crag
outer cobalt
#

ah yea i get it now

#

learned a lot actually trying to fix this instead of googling the problem

#

thank you guys

#

its fixed

swift crag
#

Equality comparisons to exact values are generally a bad idea

#

(and Mathf.Abs(x) > 0 is just x == 0)

#

It's often a bad idea because of floating-point error. 0.1 + 0.2 isn't exactly 0.3

#

It's also a bad idea here for less technical reasons: because it takes a while to get to exactly 0

outer cobalt
#

yea i noticed, it takes some time to reach the full 0 so thats why it plays the animation again because its still not 0

grim pecan
#

im following the create with code lesson 4.4 tutorial step 3 but this keeps saying its wrong but i cant figure out why

lost anvil
#

ive been trying different things for ages

swift crag
#

Fixing your attitude might.

lost anvil
#

you help then lad

grim pecan
#

spelt what wrong?

wintry quarry
#

Read the error

outer cobalt
wintry quarry
#

there's no such thing as "length" on an array

lost anvil
#

ok sound

outer cobalt
#

you're not gonna learn anything from begging others for help, try to figure it out yourself just like i did, you wont learn anything from it

lost anvil
#

🤣 thats what ive been doing for like an hour

#

i came here for help

grim pecan
wintry quarry
#

that looks different

grim pecan
#

thats the script from the video

wintry quarry
#

you wrote "length". They wrote"Length"

grim pecan
#

o m f g

wintry quarry
#

You can't do things your own way. You have to do it exactly right

timber comet
grim pecan
#

i didnt realise mine wasnt captilized

swift crag
#

there is no room for creative liberty here

frosty hound
eternal falconBOT
grim pecan
frosty hound
#

If you're planning to continue asking questions here, you're required to have it done.

grim pecan
#

and im gonna do it once i finish this

frosty hound
#

Good thing there's a bot message

timber comet
grim pecan
frosty hound
#

Well, then you won't ask any further questions here. See you when it's configured.

wintry quarry
summer stump
# lost anvil ok sound

I'm confused. The issue is that you want to reference the text component, but you are passing the text PROPERTY of the text component instead? Just don't use the property
Steve basically gave you the exact answer.

swift crag
#

sounds a lot more useful

outer cobalt
#

if it can save time do it

#

lol

#

dont delay it

lost anvil
#

mate ive got no idea what you mean

#

what does passing the text property mean

summer stump
grim pecan
#

i didnt know it would do stuff like that i thought it only color coded the words 💀

swift crag
#

now go set it up

summer stump
swift crag
lost anvil
#

no i dont because i dont understand it lol

swift crag
#

read the error message.

summer stump
lost anvil
#

what am i supposed to do then

swift crag
#

.text is a property that returns a string. Is a string a TextMeshProUGUI?

lost anvil
#

?? are you asking me lol

swift crag
#

Yes.

lost anvil
#

i dont kow

swift crag
#

I am asking you if string is the same thing as TextMeshProUGUI

summer stump
eternal falconBOT
#

:teacher: Unity Learn ↗

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

swift crag
#

If you answer "I don't know" to every single question that's asked of you, then nobody is going to want to help you

lost anvil
#

yeah nice one i understand

supple citrus
#

How would I set the Source Image sprite to a Jpg file I have in PersistentDataPath?

#

I cant figure out how to load the image as a sprite and not a texture

#

Or how to convert from one to the other

#

during runtime ^

polar acorn
sage folio
rich adder
whole idol
#

why does my ladder not work???

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;
public class Ladder : MonoBehaviour
{

    public Transform playerController;
    bool inside = false;
    public float speed = 3f;
    public FirstPersonController player;
    public AudioSource sound;





    void Start()
    {
        player = GetComponent<FirstPersonController>();
        inside = false;


    }



    void OnTriggerEnter(Collider col)
    {

        if (col.gameObject.tag == "Ladder")
        {
            Debug.Log("TouchingLadderTrue");
            player.enabled = false;
            inside = !inside;
        }


    }

    void OnTriggerExit(Collider col)
    {

        if (col.gameObject.tag == "Ladder")
        {
            Debug.Log("TouchingLadderFalse");
            player.enabled = true;
            inside = !inside;
        }


    }

    void Update()
    {
        if (inside == true && Input.GetKey("w"))
        {
            player.transform.position += Vector3.up /
            speed * Time.deltaTime;
        }

        if (inside == true && Input.GetKey("s"))
        {
            player.transform.position += Vector3.down /
            speed * Time.deltaTime;
        }

        if (inside == true && Input.GetKey("w"))
        {
            sound.enabled = true;
            sound.loop = true;
        }
        else
        {
            sound.enabled = false;
            sound.loop = false;
        }




    }


}

sage folio
rich adder
#

You can do it without the blend tree and just lay out all the clips on animator then make your own transitions, but its easier with the former, even for 2D.

sage folio
#

then i'll look into what that is, it sounds more practical

rich adder
#

I suggest if you are following a tutorial to finish it up, also look into how Animator works. You need reference to Animator to switch animations

sage folio
#

i might use a different tutorial, the one i am using feels less advanced and understandable than what i am trying to achieve

rich adder
rich adder
eternal falconBOT
#

:teacher: Unity Learn ↗

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

whole idol
short hazel
sage mirage
#

Hey, guys! I want to make a functionality for my timer. So, whenever the game is over to freeze the timer only and not the game itself. Is there a way to succeed that? I am currently using Game States for my Game Over and all of that states, so I have tried to use it inside my update timer but nothing changed?

#

I am using for timer Time.deltaTime.

wintry quarry
sage mirage
wintry quarry
#

i don't know what "game states" are

#

maybe?

#

It depends what that is

#

show some code

sage mirage
#

It is an enum I have

#

Where I have game over, pause etc

wintry quarry
#

ok

grizzled zealot
#

Is there a standard unity component for throttling events? Even if the event generator stuffs events in the queue, I want at most x per second to be delivered.

sage mirage
#

Wherever I want I am using it

wintry quarry
whole idol
wintry quarry
#

yes you're in play mode

short hazel
#

Yes you're in play mode

#

Indicated by the blue "Play" button

grizzled zealot
sage mirage
#

Handle Game States:

{
    switch (currentState)
    {
        case GameState.Playing:
            uiManager.InputForPauseMenuScreen();
            Time.timeScale = 1f;
            break;

        case GameState.Paused:
            uiManager.InputForPauseMenuScreen();
            Time.timeScale = 0f;
            break;

        case GameState.GameOver:
            GameOver();
            break;
    }

    if (currentState == GameState.Playing)
    {
        UpdateTimer();
    }
}```
My update timer:
```public void UpdateTimer()
{
    if (timerText != null)
    {
        time += Time.deltaTime;
        int minutes = Mathf.FloorToInt(time / 60);
        int seconds = Mathf.FloorToInt(time % 60);
        timerText.text = string.Format("{0:00}:{1:00}", minutes, seconds);
        timerText.text = "Timer: " + timerText.text;
        Debug.Log("Timer updates: " + timerText.text);
    }
}```
short hazel
# whole idol

Any changes made to the scene in this state will be reverted when play mode stops.

wintry quarry
whole idol
short hazel
#

Stop play mode, change the ladder's tag, save, and play again

grizzled zealot
# wintry quarry use a timer variable

I'm thinking of a pipe and filter arcthiecture as found in stream processing, where I can add additional nodes in the list publish/subscribe pattern and control rates.

short hazel
wintry quarry
#

you could certainly write a little utility class if you want to implement that kind of thing

whole idol
wintry quarry
#

the one on the right is nothing

whole idol
#

ok

rocky canyon
#

its paused..

#

but since it wasnt playing.. its nothing as said

wintry quarry
#

I think if you have that mode on the right it will start the game paused when you press play

#

but otherwise it does nothing

rocky canyon
#

this yup

short hazel
#

Paused but not playing. You can use this if you want the game to pause on the very first frame when play mode is enabled

grizzled zealot
short hazel
#

The third button is only active when in play mode and paused. This allows you to advance execution to the next frame

short hazel
#

Debugging, mainly

wintry quarry
#

it will be very simple

grizzled zealot
#

I understand how to write it, but wanted to save time 😄

#

Don't want to reinvent the wheel.

timber tide
#

invoke, coroutines, you've a lot of options

whole idol
sage mirage
sage mirage
#

I dont know what to put inside else

wintry quarry
fathom mist
#

I have a sprite sheet that I want to put into my game for an assignment but I'm not sure how to code the animation or really where to begin with that as well as initiating a scene change into a new area by going through like a door - can someone help me out? I'm like astronamically awful with coding so the things I've seen online are really confusing to me so far

short hazel
low path
#

What are your other current states? Paused?

sage mirage
wintry quarry
sage mirage
#

oh

#

Yes thats true

whole idol
# short hazel You'll have to do a bit of debugging here. Is `OnTriggerEnter` executed in your ...

I didn't code this. This was in a ready made package. I don't code in C# at all


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;
public class Ladder : MonoBehaviour
{

    public Transform playerController;
    bool inside = false;
    public float speed = 3f;
    public FirstPersonController player;
    public AudioSource sound;





    void Start()
    {
        player = GetComponent<FirstPersonController>();
        inside = false;


    }



    void OnTriggerEnter(Collider col)
    {

        if (col.gameObject.tag == "Ladder")
        {
            Debug.Log("TouchingLadderTrue");
            player.enabled = false;
            inside = !inside;
        }


    }

    void OnTriggerExit(Collider col)
    {

        if (col.gameObject.tag == "Ladder")
        {
            Debug.Log("TouchingLadderFalse");
            player.enabled = true;
            inside = !inside;
        }


    }

    void Update()
    {
        if (inside == true && Input.GetKey("w"))
        {
            player.transform.position += Vector3.up /
            speed * Time.deltaTime;
        }

        if (inside == true && Input.GetKey("s"))
        {
            player.transform.position += Vector3.down /
            speed * Time.deltaTime;
        }

        if (inside == true && Input.GetKey("w"))
        {
            sound.enabled = true;
            sound.loop = true;
        }
        else
        {
            sound.enabled = false;
            sound.loop = false;
        }




    }


}
#

@sage mirage Ελλαδάρα

short hazel
#

Modify the code to add more debug statements inside OnTriggerEnter/Exit

#

Maybe they're not getting executed because your physics setup is incorrect?

sage mirage
#

I have to make a separate function and add it to my game over state

wintry quarry
short hazel
# whole idol Most likely this

For OnTriggerEnter to happen, you need two colliders, one checked "Is Trigger", the other not, and at least one Rigidbody on either of the objects

#

Usually the player has both the Rigidbody and the non-trigger collider, which leaves the trigger collider for the other object that needs to be detected

sage mirage
#

Can I make a thread and show you more information? I mean if you have available time.

whole idol
# short hazel For `OnTriggerEnter` to happen, you need two colliders, one checked "Is Trigger"...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;

public class Ladder : MonoBehaviour
{
    public Transform playerController;
    bool inside = false;
    public float speed = 3f;
    public FirstPersonController player;
    public AudioSource sound;

    void Start()
    {
        player = playerController.GetComponent<FirstPersonController>();
        inside = false;
    }

    void OnTriggerEnter(Collider col)
    {
        if (col.gameObject.tag == "Ladder")
        {
            player.enabled = false;
            inside = true;
        }
    }

    void OnTriggerExit(Collider col)
    {
        if (col.gameObject.tag == "Ladder")
        {
            player.enabled = true;
            inside = false;
        }
    }

    void Update()
    {
        if (inside && Input.GetKey("w"))
        {
            player.transform.position += Vector3.up * speed * Time.deltaTime;
        }

        if (inside && Input.GetKey("s"))
        {
            player.transform.position += Vector3.down * speed * Time.deltaTime;
        }

        if (inside && Input.GetKey("w"))
        {
            sound.enabled = true;
            sound.loop = true;
        }
        else
        {
            sound.enabled = false;
            sound.loop = false;
        }
    }
}

north kiln
#

!code

eternal falconBOT
north kiln
short hazel
#

There's no need to post the code - you removed the debug logs entirely, and you didn't confirm or deny that your objects are correctly set up for OnTrigger messages to happen

whole idol
#

I asked chatgpt to make this cause I dont code in C# ...

short hazel
#

Mistake

rocky canyon
#

you get what u pay for

whole idol
short hazel
#

Learn C#, or delegate the task to someone else. Server rules here says to not ask nor answer questions with unverified AI output

whole idol
#

btw isn't OnTrigger like a function variable here?

short hazel
#

I explained the required setup, and vertx linked their troubleshooting website, choose either or both

#

vertx's one is more complete and covers pretty much all the edge cases that could happen

whole idol
#

oh ok true, i should probably learn some C# scripting for unity.. thats true but i was told you can code in any language of your choosing or use the visual nodes and stuff

#

like blender

#

But Im not sure if this problem is code related

short hazel
#

Unity only supports C#, but they have their scripting nodes solution: #763499475641172029
The code looks fine, it's probably just that your two objects aren't set up correctly

whole idol
#

because im followign a tutorial and these are the exact same assets the person on youtube is using

#

Ok so he says you should place the object collider like this. Which doesnt rly make sense. I would just leave it on the body of the yellow ladder and not move it at all

short hazel
#

Triggers are detections areas, no more, no less. They don't collide with other colliders

whole idol
#

yeah but are we required to place the second one like that?

short hazel
#

It's to make it so you have to jump to activate it.

whole idol
#

Ok so you're supposed to go through that collider as I understand it and colliders work kinda like minecraft redstone elevators instead of collision handlers?

short hazel
#

If you had it lower, breezing past it diagonally would activate the climbing, which you probably don't want.

rocky canyon
#

its just a trigger.. if ur in the trigger ur climbing code runs

#

almost every player will jump towards a ladder anyway

#

saving time.. and whatnot lol

short hazel
whole idol
short hazel
#

I'll let you scroll up for the troubleshooting links and/or the code debugging steps

midnight harbor
short hazel
# midnight harbor

I think the script (first screenshot) is referring to the wrong InputManager type, seeing that the class (second screenshot) has "0 references" as per the indicators above the class name

#

Make sure you have a using Niipperi.Manager; at the top, and that it's not picking up some from another namespace

#

And go to where _inputManager is declared and Ctrl+Click the InputManager, it will take you to where the class is defined, make sure it's your own script

midnight harbor
#

yes i am using it

#

but it still doesnt work

#

i am following the tutorial step by step but seems like somethink goes wrong

wintry quarry
#

you haven't shown what type _inputManager is

midnight harbor
wintry quarry
#

nor have you shown the error message

#

just looks like you didn't save your scripts tbh

midnight harbor
short hazel
#

Showing how your using is grayed out, you're not using it

#

So it's 100% choosing another type here

wintry quarry
# midnight harbor

Yeah just ctrl + click InputManaer here and it will take you to the type it thinks it's using

midnight harbor
#

i am clicking it but nothings happening

short hazel
#

With Ctrl held down

midnight harbor
#

yes ofc

short hazel
#

Or, right-click the word and select Go To Definition

midnight harbor
#

this one here?

short hazel
#

On InputManager

#

The type, not your variable

midnight harbor
#

aaaaaa😂

#

omd

#

now

#

yeah it puts me in the empty script, now i know whats happening

visual hedge
#

is there any particular reason why goto thing is not being used very often in c# from what I see everywhere?

Like (pseudocode) ```if (blah blah)
{
goto Case1;
}
else
goto Case2;

wintry quarry
#

why use a goto in that example instead of just local functions for example

short hazel
visual hedge
low path
#

I’m sure there’s a bottom middle hacker graph about goto

ivory bobcat
midnight harbor
short hazel
#

Yep

visual hedge
low path
#

Functions can solve those issues. Goto labels don’t provide the same guarantees as function calls so almost always avoided.

visual hedge
#

okay, thank you

midnight harbor
# short hazel Yep

i deleted it and i dont have any errors now, thank you and sorry for my stupidness

ripe shard
scarlet skiff
#

do both gameobejcts need to have a rigidbody to detect if they collided with eachother if both have a trigger collider?

ripe shard
scarlet skiff
#

so.. 2 gameobejct with "is trigger" box collider cannot interact?

ripe shard
#

they can trigger each other

#

if one has a rb

summer stump
scarlet skiff
#

im doing all those things but still wont work and cant figure out where i messed up

ivory bobcat
scarlet skiff
ivory bobcat
#

A rigid body or character controller would interact with the colliders

ripe shard
#

are you using OnTriggerEnter?

scarlet skiff
#

yes

#

but.. what the hell is this 😭

#

how does it even become negative scale

ripe shard
#

check your scales

scarlet skiff
#

oh wait, the player parent does have a script that flips the player

ripe shard
#

pro tip: never use scales other than 1,1,1

#

only bad things happen when you scale stuff

scarlet skiff
#

uh oh..

#

it would very hard to avoid scaling things up

#

or down

ripe shard
#

(you can use scale as a temporary effect or for temporarily testing things)

ripe shard
scarlet skiff
#

id have to fix the size of every sprite before importing, no?

ripe shard
#

obviously

scarlet skiff
#

like id have to be sure what size it should have

#

yea well thats difficult

ripe shard
#

well, technically scaling is a viable thing to do, if you know what you are doing, for some effects its necessary, but scaling because "you dont know" isn't gonna end well

#

anyway, just a rule of thumb

scarlet skiff
#

the obejct that has this issue doesnt get scaled i dont think

scarlet skiff
potent nymph
#

how do I get this exact rotation value via script? transform.localEulerAngles.x returns 358 instead of the value shown here:

north kiln
scarlet skiff
ripe shard
ripe shard
#

a root is the element in a tree that has no parent

gaunt kestrel
#

Hi, i began coding in unity a few months ago, and i am starting a new project, i have unity basics, know c#, understand how game objects, components and stuff work etc.. but recently ran into a problem, i my project i need to create instances of a class and i am not sure i understand correctly how theses instance are linked to actual game objects

ripe shard
gaunt kestrel
#

yes, i think i understood this correctly, but my issue is different, it's kinda hard to explain but ill try :

scarlet skiff
#

here is how it looks like in hierchy

ripe shard
#

so are "ground" and "Main Camera"

#

"Game" is a scene, which is a container for hierarchy trees

gaunt kestrel
#

i want to create new instances of a class, but they should be represented as game objects (in my case "World", this class is monobehavior and attached to a game object that i turned into a prefab to create new instances with my main script, but i want my worlds game object/class to be made up of Regions, wich is another class, these regions should be represented as game objects, child of the World game object, but i cannot figure out how to do it properly, my wold class contain a list of Regions, but then how do i turn theses region into a game object in my scene?

#

my problem is making the link between "virtual" instances and game object in the scene

scarlet skiff
#

so i would be checking the parryHitBox and player?

ripe shard
gaunt kestrel
#

currently no, but i think it should be ? but i still don't fully understand how i can make this "link"

timber comet
ripe shard
#

If you want to associate a Region with a GameObject you have to maintain that association manually, for example you could create a GameObject instance for each region, and store them in a dictionary with the respective Region object as a key

gaunt kestrel
#

well i think in my case i don't really want to associate a game object to a region, but i want the game object child of the world to be the regions that make it up (if that make sense)

ripe shard
#

it would probably make sense to have regions derive from monobehaviour though and just create regions as gameobjects with a region component

gaunt kestrel
#

yes i think this is what i need to do, but don' t fully understand how

timber comet
gaunt kestrel
#

i think my problem is that i don't really knw in what case use monobehavior and in what case not to

ripe shard
#

you make a GO with a world component and add children to that gameobject with a GO for each region which all have a Region component

gaunt kestrel
#

so i need to make a prefab for my region game object?

timber comet
gaunt kestrel
#

also not sure when to use thoses

ripe shard
timber comet
gaunt kestrel
#

no they will contain data in the future, like props etc

gaunt kestrel
#

the goal of my project is basically to take a file, read data from it (world/regions data), and create a world/regions from the file data in my scene that i could later save into another file, i think i need to make these worlds and region game object and not just regular class because they will contain compoenents such as mesh filter/renderer etc...

teal viper
#

What data exactly do you need to save?

#

Components are not data btw. But they could be storing or referencing data.

gaunt kestrel
#

data that will basically be stored in json, in this case its objects name and position in the scene

ripe shard
#

its only caveat is, that it doesn't offer any guidance and is VERY generic.

teal viper
gaunt kestrel
#

but then if i use monobehavior for everything, to use a method for a specific region i would have to do World.regionList(n).getComponent(region).myMethod() or something like this?
where as with regular class i could just do World.regionList(n).Mymethod

ripe shard
#

those are not the same thing

#

GetComponent is an abstraction so you can have any type of component on your container object

gaunt kestrel
#

yes, it's something else but i was also wondering how to access the regions method using monobehavior for both

ripe shard
#

you'd have to do the same thing in your DIY component system

#

you can also cache any result you get from GetComponent and put into a property you'd access directly like in the plain C# example you gave

gaunt kestrel
#

but then the regionList of the world class will be a list of GameObject or Region? if i make the region monobehavior and be GO

ripe shard
#

actually, if you generate the world, there should be no reason to use GetComponent since you can assign all the references while you are spawning the world

ripe shard
#

mind unity is just plain old c# with some extras, you can do almost everything you like, the only thing you cant do is call new on a monobehaviour.

#

in a way monobehaviours are just making c# classes visible, touchable and hierarchically composable.

gaunt kestrel
#

This component system is really getting me lost, i thought i understood it well i the beginning but now that i start using it this way i realize its not that easy

ripe shard
#

its very easy

#

you are probably overthinking it

floral kettle
#

does anybody have a good ik solver for unity? without being the default one

gaunt kestrel
floral kettle
ripe shard
floral kettle
#

ok

ripe shard
#

it has lots of features, so that stands in the way of simplicity

#

the internal one is considerably more low level and thus "simpler"

ripe shard
# gaunt kestrel i think i am

maybe you can watch a video or read some intro to the component system just to get into the right frame of mind or mental model

olive heron
# gaunt kestrel This component system is really getting me lost, i thought i understood it well ...

A normal class definition (non monobehaviour) requires you to make an instance of that class and keep a reference to it as a field or property or local variable right?
A monobehavior derived class is the same, the main difference is that an instance of that class requires it to be a component attached to a gameobject in the scene.
There are more difference and nuances to it but you can ignore that for now

gaunt kestrel
#

so i cannot create instances of regions (monobehavior), if there is no game object attached to it?

olive heron
#

As far as I've worked with monobehaviours, they've always been attached as a component to a gameobject in the scene

wintry quarry
#

MonoBehaviours are components. Components cannot exist without being attached to a GameObject

#

if you want a class that can be created without a GameObject, don't make it a MonoBehaviour

gaunt kestrel
#

so in my case, i my monobehavior world, my "populateWithRegion" method should create Children game object for that world with the region component, while keeping a reference to theses region in the list of the world

teal viper
gaunt kestrel
#

but i need the regions to be game object because in the future they will contain other components for mesh rendering and other stuff

teal viper
#

If you want it to be a MonoBehaviour it would be wise to make a Region prefab that you instantiate and initialize with your data.

olive heron
#

Look at it like this:

You create a game, and you have a gun in that game, the gun has a method "shoot" which makes it fire a bullet in the 3D world. This gun object will be a monobehaviour because it influences your scene, it's attached as a component to the gameobject representing your gun. Just as that gameobject will have components that make it so it renders a 3D model for the gun etc.

But you also want to calculate damage for that gun shot. So you create a class and call it "GunDamageCalculator.cs", and inside you have a lot of methods and whatever that you use to calculate damges with and general helper stuff. This script just does the code that you need it to do but isn't represented in your game scene so it doesn't have to be a monobehaviour. (it could be a monobehaviour but it doesn't have to be)

gaunt kestrel
#

ok i get this

olive heron
#

In your case

You have a world gameobject. And it has region properties. Do you need your region objects to do something in your scene at all?

#

or is it all just abstract logic, as a part of your 'world' object

gaunt kestrel
#

No they need to physically be in the scene

#

so i made the region class monobehavior

olive heron
#

Also what dlich reccomends is the way to go I think.
Create one of these region gameobjects, attach your region component to them, save that gameobject as a prefab.
Give your 'world' class a field that can reference that prefab so that you can instantiate new instances of the region object in your scene, and access it's region component to initialize it with whatever makes that region unique

google tutorials or examples of unity prefabs instantiating if that's a bit too much info

gaunt kestrel
#

no i understood that right ty, ill try this out

fathom mist
#

!code

eternal falconBOT
olive heron
# gaunt kestrel no i understood that right ty, ill try this out

A tip:
You don't have to do

public GameObject RegionPrefab;

You can actually use the region's component type for your prefab field:

public Region RegionPrefab;

And then your list of Regions can be filled with those compoents straight out of instantiation

`private List<Region> _regions = new List<Region>();

Region newRegion = Instantiate(RegionPrefab, this.transform);
newRegion.InstantiateMethod("whatever parameters you want");
_regions.Add(newRegion);`

like that

(your region prefab gameobject root needs to have the Region component attached for that to work)

fathom mist
#
// using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class PlayerMovement : MonoBehaviour
{

    //two text varuable
    public TMP_Text ScoreText;
    public TMP_Text WinText;



    //create a speed variable for the player
    public float speed;

    //counting system

    public int count;

    //create a rigidbody variable for the player
    Rigidbody2D rb2d;

    //call sound controller script
    SoundController sc;


    // Start is called before the first frame update
    void Start()
    {

        //get the rigidbody2d component to access it
        rb2d = GetComponent<Rigidbody2D>();

        WinText.text = "";
        ScoreText.text = "Score:";

        //Initialize SoundController Script
        sc = GameObject.Find("SoundController").GetComponent<SoundController>();
        
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        float moveHorizontal = Input.GetAxis("Horizontal"); //x
        float moveVertical = Input.GetAxis("Vertical"); //y


        // Debug.Log(moveHorizontal);

        //need vector2 value by combining x and y

    Vector2 movement = new Vector2(moveHorizontal, moveVertical);

        // add physics to force the player to move with certain speed
        //rb2d.AddForce(movement * speed);
        rb2d.velocity=(movement * speed);
    }

    private void OnTriggerEnter2D(Collider2D other)
    {

        //When a gameobject with a collider passes through an object on trigger checked
        //it'll do something
        if (other.gameObject.CompareTag("PickUp"))
        {
            //it will set the other game objects active status to false

            other.gameObject.SetActive(false);

            count = count + 1;

            ScoreText.text = "Score: " + count.ToString();
            sc.PlayScoreSound();

            if (count >= 4)
            {

                //display win text
                WinText.text = "Gathered all materials";
                sc.PlayWinSound();

            }
        }
    }

}

#

I was told to share my script here, I'm trying to code a player character moving around and assign a walking animation to each direction- I'm not sure where to go from here

fathom mist
rich adder
fathom mist
#

What is that qwq

rich adder
fathom mist
#

I'm so sorry in advance for the dumb questions AU_sweat

rich adder
#

its fine dw

fathom mist
#

is this for 3d?

#

or does it not matter

whole idol
#

anyone knows what this is?

rich adder
rich adder
#

make sure to restart pc after doing so

rich adder
fathom mist
#

Sweet!

#

that'll help for this then?

rich adder
#

they come from your Inputs

#

You just apply those from moveHorizontal / moveVertical

fathom mist
#

Aa i might have to find a video that goes through the motions

fathom mist
#

The player movement script is something I had prewritten from another simple project

rich adder
#

not a diffcult process tbh

fathom mist
#

I just get really confused easily with this

#

I also have this error but I'm assuming it's because all I have rn are the animations and no script attached?

rich adder
#

and no the script shouldn't matter for animator

fathom mist
#

I reopened it and got a new error hh

rich adder
#

yeah its probably have a fit with your layout for some reason

fathom mist
#

Oh ok

rich adder
#

you can always reset layout and do it again if it keeps coming back

whole idol
#

I just installed it

fathom mist
#

My camera dissapeared?

whole idol
slender nymph
fathom mist
#

I added it back and my sprite is gone on the preview

#

I messed with the variables and cant find the sprite ._.

rich adder
fathom mist
#

It would at least show the sprite so I could do the animations?

#

I was able to test it by making him fall on a box

rich adder
#

oh.. so just check if its in front of it

summer cave
#

I keep looking it up and trying but i cant get it to work so ima ask here. How do i make something Ignore all collisions when a certian object has a tag/layer apllied to it

summer cave
rich adder
#

switch it to a layer that has no other layers to collide with

summer cave
#

ty, i will look into it

fathom mist
#

Thank god restarting fixed it

#

ok so I did find a video explaining the blend tree but there's already a movement script attached to the character- I feel like ripping the script from the other project with different names and stuff will just break it

rich adder
fathom mist
#

What

queen adder
#

Your player should have a animator component connected to it. The animator will have parameters that you can set for it that will determine what animation plays. But you have to set those parameters for the animator via code

#

You set up the parameters that will dictate what animation plays. But in order for that to happen you have to get a reference to the animator via code

fathom mist
#

So the blend tree isn't needed?

#

It's saying that there's a weird error but when I play test it the sprite floats around according to the keys presssed so it's working fine?

rich adder
#

you have to map X to horizontal and Y to vertical

fathom mist
#

Side note can I keep it purely directional instead of allowing it to to diagonals by getting rid of line 40

fathom mist
#

sorry im functioning on pure panic rn

rich adder
#

as floats

fathom mist
#

in the code?

rich adder
#

no read carefully what i said lol

fathom mist
#

OH

#

Right right in the animator window thing

#

in unity

static cedar
fathom mist
#

It is inspired from it yes :3c

#

I do that for each animation then individually and not worry about the controller yet?

#

Ignore that I figured it out LOL

rich adder
fathom mist
#

So do not worry abt the script itself yet

rich adder
#

not rn

#

you just have to setup the animations first

#

the code part is the easiest tbh

#

2 lines

fathom mist
#

https://youtu.be/d_gSegD2FXo?si=pd4V1X85_I6mZZNW

This video keeps telling me that I gave coding to do and idk what that is

Learn how to setup animations for your 2d Unity characters. This tutorial demonstrates creating an animator controller, creating animation clips or motions, setting up a blend tree, and scripting animation parameters so your animator controller can display the right animation at the correct time.

Part 2 https://youtu.be/NgTf4av7vmE
Script https...

▶ Play video
#

Oh ok

rich adder
#

should not be hard to follow, vid is legit

#

the only difference the code at end uses new input system

#

but the method for SetFloat is the same

fathom mist
#

ok so I think I got most of it but for some reason it's looping the walk left animation and just still floating around

#

Idk what object it's refering to either?

cosmic dagger
#

we can't tell anything from that message alone . . .

fathom mist
#

ok nvm abt the error

#

but I dont know why it's just playing one animation and still moving like it's floating

teal viper
#

Upload it as mp4.

cosmic dagger
queen adder
#

okay

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

public class PlayerMovement : MonoBehaviour
{

 
    //create a speed variable for the player
    public float speed;

    //counting system

    public int count;

    //create a rigidbody variable for the player
    Rigidbody2D rb2d;

 
    // Start is called before the first frame update
    void Start()
    {

        //get the rigidbody2d component to access it
        rb2d = GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        float moveHorizontal = Input.GetAxis("Horizontal"); //x
        float moveVertical = Input.GetAxis("Vertical"); //y


        // Debug.Log(moveHorizontal);

        //need vector2 value by combining x and y

    Vector2 movement = new Vector2(moveHorizontal, moveVertical);

        // add physics to force the player to move with certain speed
        //rb2d.AddForce(movement * speed);
        rb2d.velocity=(movement * speed);
    }

    private void OnTriggerEnter2D(Collider2D other)
    {

        //When a gameobject with a collider passes through an object on trigger checked
        //it'll do something
        if (other.gameObject.CompareTag("PickUp"))
        {
            //it will set the other game objects active status to false

            other.gameObject.SetActive(false);

            count = count + 1;

        }
    }

}
#

this is my script btw

queen adder
#

wait how do you post scripts like that?

fathom mist
#

im not sure what he means about the package manager?

#

!code

eternal falconBOT
fathom mist
#

Like that

queen adder
#

thanks!

queen adder
#

i have this issue where i can stick to the wall whenever im moving "ps im using a rigidbody" ping me if you have an idea of how to fix it

slender nymph
#

show code

fathom mist
teal viper
fathom mist
#

I tried adding the private Animator animator;
animator = GetComponent<Animator>(); and it hit me with all these

#

so im assuming I shouldnt just add that

#

Nothing in the console

teal viper
teal viper
#

As for the animation issue, where do you set the animator parameters?

fathom mist
#

I fixed that bc it was in reference to a sound thing

wintry quarry
fathom mist
#

I'm so confused

#

I think I need a new script from scratch

#

Because trying to edit this one is just making it more confusing

midnight harbor
#

Yo, can someone help me? i wanted to make player movement smoother as was showen in yt tutorial but i am still getting errors, how can i fix this?

slender nymph
midnight harbor
#

what should i remove from that line of code?

slender nymph
#

learn about lerp and then think about what exactly you are trying to lerp. then you should be able to determine what the parameters you need are
https://unity.huh.how/lerp

midnight harbor
#

i figured out, the upper line is its should be

#

thannks!

fathom mist
#

I just copied the script from this DaanFacepalm

#

I've been at this for like two hours I'm just as lost as I was before

#

ok so the problem is I still dont understand why the animation for walking left only plays no matter the direction

#

I'm nervous to start messing with things myself bc last time I did that I broke like everything

teal viper
#

Share the code.

fathom mist
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour

{

    public float movSpeed;
    float speedX, speedY;
    Rigidbody2D rb;

    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        
    }

    // Update is called once per frame
    void Update()
    {

        speedX = Input.GetAxisRaw("Horizontal") + movSpeed;
        speedY = Input.GetAxisRaw("Vertical") + movSpeed;
        rb.velocity = new Vector2 (speedX, speedY);
        
    }
}

slender nymph
#

why are you adding instead of multiplying

fathom mist
#

I wish I knew

#

I''m just following the tutorial

teal viper
#

45 sec long video is not a tutorial

slender nymph
#

not well enough because the "tutorial" multiplies by movSpeed it doesn't add it

fathom mist
#

I was following another video I just needed the barebones script for movemtn bc my last one was not working for me bc it was just me editing something from anothe rproject

#

please be patient with me I've been at this for awhile and I dont know what im doing Im sorry

slender nymph
#

you should consider going through some basic courses to learn what you are doing so you'll have an easier time at this. there are some great c# courses pinned in this channel and the pathways on the unity !learn site are an excellent place to start with learning the engine

eternal falconBOT
#

:teacher: Unity Learn ↗

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

fathom mist
#

I'm in a class for this rn I just want to assign the animations to the different directions the character moves ;^;

#

He moves fine now I just dont know how to do that and the videos I watch keep confusing me

teal viper
#

Wdym by "I'm in a class for this"? If you're in a class do what they taught you in the class

fathom mist
#

I just wanted to make a walk cycle

supple citrus
#

Methods to detect whether an object has been clicked other than OnMouseDown() and rect.contains(Input.MousePosition) ?

rugged beacon
#

var currentPos = new Vector2Int(Random.Range(-map.size,map.size), Random.Range(-map.size,map.size));

is there any unity method exclude a range like 50 from (0,0) or something simliar from the random.range ?

fathom mist
#

I just wanted to figure out how to add animations to the sprite floating around and right now he moves fine but it just keeps playing the walk left animation and I don't know how to fix that that's all I'm asking help for rn

teal viper
teal viper
fathom mist
#

The video I watched awhile ago confused me, I have the blend tree set up

#

In the code?

teal viper
#

Ofc. Where else?

fathom mist
#

In the unity engine itself I just wanted to make sure

#

Please don't be mean qwq

teal viper
#

Unity engine can't read your thoughts. The way you tell it what to do is via code

fathom mist
#

Learn how to setup animations for your 2d Unity characters. This tutorial demonstrates creating an animator controller, creating animation clips or motions, setting up a blend tree, and scripting animation parameters so your animator controller can display the right animation at the correct time.

Part 2 https://youtu.be/NgTf4av7vmE
Script https...

▶ Play video
#

I thought you were telling me to mess with the blend tree sorry

#

I dont know what you mean by animation parameters

frosty hound
#

Watch the video then?

fathom mist
#

This was the video I was using but he mentioned the package manager and do I have to worry abt that?

teal viper
fathom mist
#

I dont know what he means when he talks about it at around 8:30 ish

teal viper
#

I can't watch the video now. What do they say exactly?

supple citrus
#

Im trying to detect if '5' gets clicked

fathom mist
#

"In my player controller script wherever you get the import values that are allowing you to move certain directions - in this case im using the import manager event which is available in window package manager"

#

For some reason this is just not computing with me and I get hung up on this

#

It seems he's using that as the basis for the animation parameters?

teal viper
abstract finch
#

What should I name a variable that holds the information for levels?
I'm trying to create a struct which contain a list of levels in a roguelike game so it resets on death.
Should I name it struct Stage?

supple citrus
teal viper
supple citrus
#

The only way i can think of is rect.contains(mouseposition) but the rect transform of this object is relative to the centre of its anchor for some reason

#

while input.mouseposition isnt

#

so Contains doesnt compute

queen adder
#

You dont have to do it like that

#

Unity has interfaces that allow you to detect what was clicked in the UI instead of constantly checking where the mouse is

teal viper
supple citrus
#

Even if the parent has a collider and the children dont, OnMouseDown() doesn't trigger

queen adder
#

Are the children clickable?

teal viper
#

Don't make this children detectable to the pointer.

supple citrus
#

how

#

They arent meant to be

teal viper
#

Ui doesn't use collider for pointer events.

queen adder
#

Put them on the IgnoreRaycast layer

#

Thats it

teal viper
#

It uses Graphics components and there's a setting to make them not detectable.

queen adder
#

UI components shouldnt have colliders

floral kettle
#

i kinda want to make a spider-like procedural walk animation but i cant find anything to help me do it, do yall have anny recommendations

queen adder
cosmic dagger
floral kettle
#

yeah i saw it, he doesnt really explain how

supple citrus
queen adder
#

It can be

floral kettle
cosmic dagger
queen adder
#

i'd reccomend looking on youtube

floral kettle
queen adder
#

But UIs have there own seperate mouse detection

cosmic dagger
supple citrus
queen adder
#

Thats because you dont really understand how raycasting to a canvas works

queen adder
#

UI components do not need colliders to pick up mouse detection

cosmic dagger
# floral kettle thats an asset in unity

anything can be an asset. an asset is just someone else code that you use. this means, you can also do it on your own. there are tutorials for creating procedural animation. a google or youtube search will yield results . . .

supple citrus
#

So in order to get it to detect mouse clicks i delete the collider and ....

queen adder
#

Well yes delete the collider first

#

Put the children objects on the IgnoreRaycast Layer

floral kettle
#

sorry couldnt hold back

#

😭

#

anyways yeah ill search a bit more

fathom mist
supple citrus
fathom mist
supple citrus
#

Currently 1-5 has UI layer and everything but has Ignore Raycast

fathom mist
#

Yeah I tried following the video again, I deleted a bunch of stuff and tried something else but this is where I ended up

teal viper
#

Did you check the documentation on the methods before using them?

queen adder
#

Ok nice

#

Ur script should work now does it not?

supple citrus
#

No :d

#

None of these are triggered xd

fathom mist
#

This is where the video told me to add the parameters so I was just following what he was saying

queen adder
#

Do u have a event system in ur hierarchy?

#

Its not getfloat

#

Its SetFloat

teal viper
fathom mist
#

SetFloat was giving me an error

queen adder
#

Then ur doing something wrong?

#

Also you cant pass in variables as strings

fathom mist
#

Which is why I'm asking for help

teal viper
fathom mist
#

I don't know what that means

queen adder
#

Theres alot wrong with the code

abstract pelican
#

Hey guys
Can you tell me how to change the value through the code? I want when I aim there was a target, and when I release the targeting key there was a player.

queen adder
#

No offense

fathom mist
#

Yes because it gave me a reccomended fix and I wanted to try something before asking for help again

#

I know thats why im here

queen adder
#

Your trying to pass in two parameters as one entire string

teal viper
fathom mist
#

I'll just send what I originally had

queen adder
#

What error does animator.SetFloat() say?

#

Did u pass in one parameter to it?

fathom mist
#

I'm just gonna go back to my old script bc I think that one's better

fathom mist
#

Lemme send it

queen adder
fathom mist
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class PlayerMovement : MonoBehaviour
{

    //two text varuable
    public TMP_Text ScoreText;
    public TMP_Text WinText;



    //create a speed variable for the player
    public float speed;

    //counting system

    public int count;

    //create a rigidbody variable for the player
    Rigidbody2D rb2d;

    //call sound controller script
    SoundController sc;


    // Start is called before the first frame update
    void Start()
    {

        //get the rigidbody2d component to access it
        rb2d = GetComponent<Rigidbody2D>();

        WinText.text = "";
        ScoreText.text = "Score:";

        //Initialize SoundController Script
        sc = GameObject.Find("SoundController").GetComponent<SoundController>();
        
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        float moveHorizontal = Input.GetAxis("Horizontal"); //x
        float moveVertical = Input.GetAxis("Vertical"); //y


        // Debug.Log(moveHorizontal);

        //need vector2 value by combining x and y

    Vector2 movement = new Vector2(moveHorizontal, moveVertical);

        // add physics to force the player to move with certain speed
        //rb2d.AddForce(movement * speed);
        rb2d.velocity=(movement * speed);
    }

    private void OnTriggerEnter2D(Collider2D other)
    {

        //When a gameobject with a collider passes through an object on trigger checked
        //it'll do something
        if (other.gameObject.CompareTag("PickUp"))
        {
            //it will set the other game objects active status to false

            other.gameObject.SetActive(false);

            count = count + 1;

            ScoreText.text = "Score: " + count.ToString();
            sc.PlayScoreSound();

            if (count >= 4)
            {

                //display win text
                WinText.text = "Gathered all materials";
                sc.PlayWinSound();

            }
        }
    }

}
queen adder
#

airy What is this supposed to show us?

#

Also dont get Input values from FixedUpdate

#

@supple citrus did u get it figured out?

fathom mist
#

This si what I started with, I couldnt figure out how to get the animation to stop looping on the walk left one so I ditched it and tried a new script but I want to know how to add the animation parameters from the video to this because I keep getting confused

queen adder
#

The code u had was almost fine

fathom mist
#

I just want to know how to get the animations to play properly while moving around

#

Oh

cosmic dagger
#

are the animation transitions setup correctly?

queen adder
#

I think that part is fine

fathom mist
#

I'm sorry I've been having this same issue for a little over two hours and I'm just losing my mind trying to teach myself how to make a walk cycle

queen adder
#

He was using the wrong method

#

Its not that hard

#

You made a simple mistake

#

Go back to what u had with animator.GetFloat()

#

Ill walk u thru it

supple citrus
fathom mist
#

Thank you so much let me uh copy and paste it back into here since I removed it

#

not the chat ofc

queen adder
#

Show me ur entire editor

#

Flawless

cosmic dagger
#

if y'all are doing that, i'd make a thread. a walkthrough will take up the chat . . .

queen adder
#

Again instead of GetFloat use set float

#

And look at the error

supple citrus
queen adder
#

From what i can tell you dont have a event system

#

You need one

fathom mist
#

I made a thread so I dont take up the chat anymore should I delete it

supple citrus
frigid sequoia
#

This is more an UI question, but since it seems that it does indeed requieres code I am gonna ask. How should I make a canvas scale depending of the size the text of its textmeshpro childs? Does this really need to be made manually by a custom script?

supple citrus
#

Also while theres a screenshot does anybody know why those 3 objects are red

#

theyve been like that forever but they work fine so i just ignore it

queen adder
#

I believe its because you deleted the original prefab

supple citrus
#

probably I dont remember its been months

queen adder
#

Are those other things UI?

supple citrus
#

Only things under UICanvas and Canvas are UI

queen adder
#

The event system is what controls UI events

supple citrus
#

But the rest of the UI works...

queen adder
#

Thats weird then

supple citrus
#

I just cant select the presets

abstract pelican
queen adder
#

Add one anyway

#

The methods should work then

abstract pelican
#

What am I supposed to do?

supple citrus
#

A type of object or a script or

queen adder
#

its under UI

#

Its a Gameobject

supple citrus
#

Oh i see

#

sigh

#

that really was it

#

thanks lol

queen adder
#

Its working now?

supple citrus
#

yeah

#

Wonder why all the other buttons work fine though

queen adder
supple citrus
#

shrug if it works it works

queen adder
#

Do they have a button Component?

supple citrus
#

no

#

OnMouseDown()

#

and colliders

#

All i did xd

queen adder
#

Thats for normal gameobjects

#

Thats why

abstract pelican
#

help guys

queen adder
#

Whats set to target?

abstract pelican
#

sight

#

The tarnsform seems to change, but it still gives an error.

queen adder
abstract pelican
queen adder
#

Read the error message

#

You have a simple NRE

summer stump
abstract pelican
queen adder
#

It says those things arent set to a reference

#

Your target and player have there references so its not them

#

Only one thing on those lines could be null

abstract pelican
#

Oh, the thing is, I forgot to delete the old target.

#

but, now I still have another problem, I can't see the picture.

queen adder
#

Wdym cant see the picture?

#

Also u dont need to delete the old target

abstract pelican
#

I can't see the scope for some reason

queen adder
#

You set vcam to a new one

abstract pelican
#

no

queen adder
#

Are u still getting the NREs?

abstract pelican
queen adder
#

Are u still getting the NREs

#

Ur code wont run until you fix them

abstract pelican
#

NRE?

#

Write normally, I don't understand your slang.

queen adder
#

Its not slang

#

I am talking normally

#

It stand for Null Reference exception

wintry quarry
abstract pelican
#

I turn on the scope object, it worked before until I started working with vcam.

abstract pelican
teal viper
#

NRE is a runtime error. You won't get it until you run the game the execution runs into it.

queen adder
abstract pelican
#

It's weird, I put 5 in here and the sight appeared:D

queen adder
#

What are u trying to show us?

#

Oh thatll do it

summer stump
#

Since it is an offset from the camera or something?

abstract pelican
#

I don't know

#

I don't have an offset in my code.

queen adder
#

Camera clip plane is on the main camera

abstract pelican
queen adder
#

You could also just the cursors sprite to whatever sprite ur using for the aiming

abstract pelican
#

When there is a virtual camera, you can't change anything on the main camera

queen adder
#

Thats what i originally thought u were doing but i guess not

summer stump
abstract pelican
abstract pelican
#

I know that. That's what I'm telling him.

teal viper
#

The sprite is parented to the v cam, so when it had position 0 on Z, it was right on/out the boundary of the camera frustum.

#

Which would make it not visible of course

abstract pelican
#

yes

#

I figured you'd have to poke around the Z.

queen adder
summer stump
#

To be clear, the offset I mentioned before is the offset from the camera, not something in code

abstract pelican
#

All right, brother.

#

I've almost done what I want to do for my game, now I just need to do the shooting. 😄

queen adder
#

Also clipping planes isnt effect by cinemachine anyway lol. But im glad to hear ur game is almost finished

summer stump
#

You can always just access the main camera and adjust if, while still using a virtual camera

abstract pelican
#

Such a big screen is awful, get yourself a screenshot app.

abstract pelican
abstract pelican
teal viper
#

To be fair vCam can override the clipping plane settings of the camera iirc.

queen adder
#

Im not going to some random link lol

#

Thank u anyways

teal viper
#

Win + shift + s

summer stump
summer stump
queen adder
#

Theres is quite literally a prtsc button

#

At least on my keyboard

summer stump
queen adder
#

Oh shit

#

good to know then

abstract pelican
summer stump
#

I'm on mobile though. Not sure about desktop

queen adder
#

Still good to know

teal viper
#

It was fine. Discord doesn't load the full res image in preview. Especially on mobile. You need to download it to see the full res.

abstract pelican
#

has anyone done a gun recoil?

queen adder
#

Anyone down for a code review on me?

#

For my PlayerMovement and PlayerAnimator

#

Curious to hear ur guys thoughts

teal viper
#

Sure, just share the code

cosmic dagger
#

time to destroy . . .

queen adder
#

!code

eternal falconBOT
queen adder
#

Oh god please dont lol

teal viper
#

Is there anything in the code that concerns you?

cosmic dagger
#

the first thing is naming convention for variables . . .

queen adder
#

Ah yes

#

Ive been told about the naming conventions

#

More so a personal preference

#

When i work with other ppl i do camelCase but for solo i do pascal

cosmic dagger
#

_moveDirection not _move_direction. makes it harder to read the variables. especially, when you have 2+ underscores, like box_cast_distance. everything is lowercase and takes longer to read what the variable is, instead of boxCastDistance . . .

teal viper
queen adder
#

The last two lines were for debugging i need to delete them actually

queen adder
teal viper
#

I'm also, not sure about boxcast for ground detection, but I guess it's more of a design decision.

cosmic dagger
#

the boxcast for ground check is a bit weird . . .

queen adder
#

Really?

cosmic dagger
#

ashh, you beat me to it . . .

queen adder
#

What would u guys do?

cosmic dagger
#

i feel like it'll get caught in seems more easily . . .

#

anythig round is easier . . .

teal viper
#

Sphere circle maybe.

queen adder
#

Ahh i see

#

I havent had any problems yet but when i do ill keep that in mind

teal viper
queen adder
#

Design decision on my part

#

I feel like if their feet are touching the ground they shouldnt be falling. Even if its llike a pixel of there foot. Idk if thats normal tho

#

Mind the music

cosmic dagger
#

nah, they should slide and fall from that . . .

queen adder