#💻┃code-beginner

1 messages · Page 681 of 1

chilly prism
#

but they show up when i am playing the game

slender nymph
#

prove it

rocky canyon
#

then u have the gizmos enabled in the game-view

chilly prism
rocky canyon
#

never seen it tho

chilly prism
#

the game is running and i can see them

slender nymph
#

you've messed something up with your canvas then since that would not be the position of either of those objects in game view if it were a screen space overlay canvas

#

show the actual canvas component

chilly prism
#

ok

strong shoal
#

public class EnterCommand : MonoBehaviour
{
[SerializeField] private TMP_InputField commandField;
private Dictionary<string, Action> _commands;
private String command;

private void Start()
{
    _commands = new Dictionary<string, Action>()
    {
        { "givemoney", GiveMoney }
    };
}

public void CommandEntered()
{
    command = commandField.text.ToLower();
    
    if (_commands.ContainsKey(command))
    {
        _commands[command].Invoke();
    }
    else
    {
        Debug.Log($"There`s no command named: {command}");
    }

    commandField.text = "";
}

private void GiveMoney()
{
    String[] parameters = command.Split(' ');
    FindFirstObjectByType<PlayerScript>().Money += Convert.ToInt16(parameters[2]);
}

} does someone know why its not detecting the command???

slender nymph
#

!code

eternal falconBOT
slender nymph
# chilly prism

so this is a screen space overlay canvas. which means what you are seeing in game view is either something else or a unity bug. if that isn't a different object then restart the editor

chilly prism
#

hmmmm ok

chilly prism
#

i restarted the editor but i can still see them

slender nymph
#

did you bother confirming you were actually looking at the right object inspector first?

chilly prism
#

yes

#

it's the canvas

rocky canyon
#

this was the gizmo button i was mentioning just in case.. couldnt actually tell by ur screenshot

slender nymph
#

even with gizmos enabled that shouldn't appear in the position they've shown

rocky canyon
#

not that thats what it is. b/c as box said ya ^

#

that

#

something screwy going on

chilly prism
#

ooo

chilly prism
# rocky canyon

when i pressed that button the lines disappeared thank you!

slender nymph
#

that's just hiding the issue, not actually fixing it

rocky canyon
#

theres two different buttons for each window

#

game view and scene view

#

ya true..

#

unless that number is actually a world-space object

#

it doesnt make sense

#

but i think it may not actually be part of the canvas

slender nymph
#

the corner of a screenspace overlay canvas wouldn't be in the center of the screen in game view though

rocky canyon
#

ya true.. this is what i was expecting to see

rocky canyon
chilly prism
#

i am basically making flappy bird but he has a gun

rocky canyon
#

just to humor us

chilly prism
rocky canyon
#

the 0

chilly prism
#

here's the hiearchy

rocky canyon
#

its inside the canvas tho?

#

ahh yea that is weird

slender nymph
#

expand the folded objects

chilly prism
#

ok

rocky canyon
#

can u show the Text (Legacy) selection in the inspector?

chilly prism
#

ok

#

what do i do if i want the text to be behind the pipe

rocky canyon
#

you'd probably need to use a world space canvas for the number (and then that type of canvas does align in ur camera like normal objects)...

#

you'd then just change the sorting layer so its behind the pipes

#

or just move it behind it.

chilly prism
#

when i changed it to world space the "0" got removed

#

now what

rocky canyon
#

it just moved..

#

select it and press F while hovering the scene view

#

it'll focus on where it is

chilly prism
rocky canyon
#

you'll have to position it wherever ur pipes and gamefield is

chilly prism
#

it's not showing up on game view

digital haven
#

hey i got things going again, but i keep getting a error here with both phrases: CharacterControls

#

using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Windows;

public class characterMovement : MonoBehaviour
{
//variable to store character animator component
Animator animator;
//variable to store optimized setter/getter IDs
int isWalkingHash;
int isRunningHash;

PlayerInput input;

// variables to track movement and input state
Vector2 currentMovement;
bool movementPressed;
bool runPressed;

void Awake()
{
    input = new PlayerInput();

    input.actions.CharacterControls.performed += ctx =>
    {
        currentMovement = ctx.ReadValue<Vector2>();
        movementPressed = currentMovement.x != 0 || currentMovement.y != 0;
    };
    input.CharacterControls.Run.performed += ctx => runPressed = ctx.ReadValueAsButton();
}

void Start()
{
    //set the animator reference
    animator = GetComponent<Animator>();
    //set the ID references
    isWalkingHash = Animator.StringToHash("iswalking");
    isRunningHash = Animator.StringToHash("isRunning");
}

void Update()
{
    HandleMovement();
}

void HandleMovement()
{
    
    bool isRunning = animator.GetBool(isRunningHash);
    bool isWalking = animator.GetBool(isWalkingHash);

    if (movementPressed && !isWalking)
    {
        animator.SetBool(isWalkingHash, true);
    }

    if (!movementPressed && isWalking)
    {
        animator.SetBool(isWalkingHash, false);
    }
    if ((movementPressed && runPressed) && !isRunning){ 
    {
        animator.SetBool(isWalkingHash, true);
    }
         if ((movementPressed && runPressed) && !isRunning){ 
    {
        animator.SetBool(isWalkingHash, false);
    }
}

void OnEnable()
{
    input.actions.Enable();
}

void OnDisable()
{
    input.actions.Disable();
}

}

#

is there a way to fix this so i can make my model to move around using a controller? I have been on this for a day now and i am stuck

rocky canyon
#

from the image that means in this view its WAY WAY WAY on the top right corner OFF the screen

#

b/c screenspace canvases work differently than worldspace canvases

#

a screenspace canvas is always that BIG square off to the side.. (ur game camera doesnt actual render it.. it gets renderered on top of wat the camera sees)

#

while a worldspace canvas does matter b/c the camera must be looking at it..

#

if u adjust ur game-view you'll notice that the bounds of the UI Canvas adjusts with it (if its set to scale correctly)... again having nothing really to do with the actual game stuff and the camera-view

digital haven
#

Like i keep getting this error and i dont know why. I am following a tutorial to the letter:

rocky canyon
#

those errors are related to the input system.. its looking for actions u havent set up... or not named the same

#

in the tutorial he should have a section where he sets those up

chilly prism
#

oh ok

digital haven
rocky canyon
#

it'd be something like that ^ this is a screenshot of the default ones that come in some of the unity projects but im not sure if they're using those

#

or they made their own or modified them a bit

digital haven
rocky canyon
#

im sure its in there tho.. ofc the inputs aren't really the main focus if ur doing animation..
you can use the old input system.. Input.GetKeyDown type stuff just as easily..

wintry quarry
rocky canyon
#

capitalization usually is important when scripting 😉

#

just saying

digital haven
#

my bad then

rocky canyon
#

im not 💯 thats the problem..

#

but if ur following a tutorial. and ur not naming things the exact same as the tutorial it'll not work the same

#

unless u keep track of what u renamed.. and when they use their version.. u swap out and use ur renamed version..

digital haven
#

Well I thought I was naming it correctly, but yeah I’m still getting a error in my code even after changing it to Character Controls

digital haven
chilly prism
wintry quarry
#

It's because you didn't constrain the rotation on your Rigidbody2d

#

but also - shouldnt the player be dying when you collide anyway?

chilly prism
#

counts to 9

#

then resets to 1

#

and doesn't add to the score anymore

digital haven
#

So can no one help?

chilly prism
wintry quarry
chilly prism
#

ah ok

wintry quarry
#

Actually yes confirmed

#

you can see in the inspector that is happening

chilly prism
#

thx

#

you were right

digital haven
#

this is what i get in the debug menu

wintry quarry
#

the tutorial is adding extra confusing by naming their input actions asset "PlayerInput", which conflicts with the name of a common componnent from the INputSystem itself

#

but you seem to have named yours "player input" or "playerinput" instead of PlayerInput

#

In fact this is happening which is 😵‍💫

#

anyway - do you have an IDE which is properly showing you errors and making autocomplete suggestions?

#

Because it seems like you probably don't

digital haven
#

I don’t believe so

rocky canyon
#

depending on how beginner u are it may actually be better to just restart

digital haven
#

I don’t wanna restart

wintry quarry
#

!ide

eternal falconBOT
rocky canyon
#

well get ready to experience game-dev first hand 💪 😅

chilly prism
#

why doesn't this work

rocky canyon
#

hover it and read what it says

wintry quarry
chilly prism
wintry quarry
#

I don't understand why you are doing this

#

this is not needed

#

you needn't change anything in the code

#

just make the text object larger

chilly prism
#

i wanna center it because when it goes over 10 it just looks bad

digital haven
wintry quarry
chilly prism
digital haven
#

Yes?

wintry quarry
#

you don't need to do anything in code

wintry quarry
digital haven
wintry quarry
chilly prism
#

to center it when it's less than 10 the x postition has to be 85

wintry quarry
#

make it centered

rocky canyon
digital haven
wintry quarry
#

or make it larger^

rocky canyon
#

also.. pro-tip.. when ur designing UI type out the MAX amount of characters u expect to have

digital haven
#

like right here? i thought this was fine

rocky canyon
#

and then design THAT to fit

wintry quarry
chilly prism
wintry quarry
wild peak
chilly prism
#

oh wait

#

ooo

#

thx

rocky canyon
chilly prism
#

i sound so stupid omg

rocky canyon
#

everytime ur like.. well. dang i dont know how to do that..
take a step back.. look around ur environment..
and then if u cant figure it out carry on with ur question 😅

#

best way to learn imo is just fiddling with stuff

#

Ctrl+Z is my partner in crime...

  • what does this button do.. <Ohh crap>
  • Ctrl+Z, welp now I know... lol
wild peak
#

If there wasnt undo world would be hard mode

digital haven
#

but it already is updated?

wintry quarry
digital haven
#

But I don’t see anything else I can do? I already checked everywhere in the package manager, it wouldn’t let me check in the help > check for updates.

digital haven
#

Yes I did that a while ago

wintry quarry
#

and you still don't get errors and autocomplete in VS?

#

Can you showe a screenshot of your VS window?

digital haven
#

Yes

wintry quarry
#

looks like it's working fine

digital haven
#

Yes but I keep getting that error and it won’t let me use it

wintry quarry
#

but yeah your code is using the PlayerInput component class

#

not your generated C# class

#

Like I mentioned above you're getting confused because of how the tutorial stupidly named things

digital haven
#

Okay then what can I do?

#

Yes i am

wintry quarry
#

go look at the generated C# class file

wintry quarry
#

wait

#

also

digital haven
#

The Player Input?

wintry quarry
#

why are you doing input.actions.CharacterControls?

#

There's no way the tutorial is doing that

#

the tutorial almost certainly has input.CharacterControls

#

(which will also not work if you're not using the generated class)

digital haven
wintry quarry
#

yeah scroll down to where it actually defines the class

digital haven
#

Sorry where would that be exactly?

wintry quarry
#

where it says public class <class name here>

digital haven
#

He didn’t edit this file so I assumed that I wasn’t supposed to edit it

wintry quarry
#

you aren't supposd to edit it

#

I'm just showing you why what you did is wrong

#

and why it's not working

digital haven
wintry quarry
#

See how theis class is named Playerinput?

#

And your code is using PlayerInput

#

notice the differently capitalized i?

#

you are trying to use the wrong thing in your other code, partially because you named your actions asset differently from the tutorial

#

which lead to this class being named differently

rocky canyon
#

snowball effect

wintry quarry
#

With the added confusion of the fact that PlayerInput is a built in component in the Input System

#

So this is partially the tutorial's fault for naming things poorly, and partially your fault for not following the tutorial precisely

digital haven
#

So wait in the character Movement document I need to change to Player input for all of the Player Inputs?

wintry quarry
#

Why not just go back

#

and change the name of your actions asset

#

so it's the same as the tutorial

rocky canyon
#

anywhere the code references it it must be referenced the correct way..

#

ur either changing everything to match what u made..

#

or ur changing what u made to match everything else

#

hence why i said earlier it might be better to start over.. b/c
it actually might be quicker in all honesty lol

digital haven
#

I don’t wanna start over tho

rocky canyon
#

u dont have to retype every script.. just change the parts that need it

#

i meant basically going back to the start and seeing where u went wrong.. remedying it one step at a time

digital haven
#

So wait is that why CharacterControls is having issues or a part of it?

rocky canyon
#

as said u can just chagne the input stuff to what it needs to be.. regenerate ur class or however they do in the tutorial.. and then u could go and change ur focus to the console.. see what errors u have after having the correct input system set up

wintry quarry
#

fix that, and it will work

rocky canyon
#

ya, anything with input is gonna be messed up for now

digital haven
#

Okay where do I fix it in the code.

wintry quarry
#

fix the name of your input actions asset

rocky canyon
#

make the input work w/ the code lol ^

wintry quarry
#

so that it's the same as the tutorial

digital haven
wintry quarry
#

this thing

#

this is what you need to rename

#

make it so it is named the same as what the tutorial named it

digital haven
#

Okay it’s named as the tutorial but it’s still getting errors

wintry quarry
#

also which tutorial is this?

digital haven
# wintry quarry also which tutorial is this?

Learn to move characters in Unity 3D with this beginner-friendly explanation of Unity's new input system and root motion!

With this deep dive tutorial, you will not only have a better understanding of root motion and Unity's new input system, but you will also have an animated character by the end of the video!

SUPPORT THE CHANNEL:
💛 http...

▶ Play video
wintry quarry
#

also - this tutorial kinda sucks

digital haven
#

Right yes I changed that

wintry quarry
#

they are not following C# naming conventions

digital haven
#

I see

wintry quarry
#

and they uselessly did using UnityEngine.InputSystem - notice it's greyed out because they're not actually using that

#

it's just adding to the confusion

#

and makes me think further they don't know what they're doing

digital haven
#

I’ve been going through this these tutorials for like 2 months now

#

And no one ever said anything about it before when I posted here

wintry quarry
#

¯_(ツ)_/¯

digital haven
#

Okay here is the vid I made for the naming conventions

#

I’m not sure what to do now. I just wanted this to be a few fixes and get my character moving

wintry quarry
#

Looks like you still have input.actions in the code which is not correct

#

and is not in the tutorial

digital haven
#

What about Run and performed?

wintry quarry
#

what about them?

digital haven
#

I removed actions, but I’m still getting errors

wintry quarry
#

what errors

#

I can't see your screen

#

I can't see what errors you have if you don't show them

digital haven
wintry quarry
#

the top one you did not copy the tutorial code correctly

#

The bottom one you will need to actually tell me what the error is

#

because this is just a screenshot of a squiggly red line

#

oh look

#

from your screenshot above

digital haven
wintry quarry
# wintry quarry

once again a problem that you didn't name things the same as the tutorial

#

The tutorial named it Run, you named yours run

grand snow
#

Things are case sensitive! visual studio should have given you suggestions as you typed so you can avoid mistakes

digital haven
#

im getting this error now in a seperate C# script

wintry quarry
digital haven
#

I see so what can I do?

wintry quarry
#

Also it's C# not C+

grand snow
#

they are very helpful to me

wintry quarry
#

but it's weirtd that you even have this code here

digital haven
#

Where exactly?

wintry quarry
#

it seems like you're mixing up code from two different tutorials probably?

wintry quarry
#

that's where you declare the type

digital haven
#

I don’t understand why it’s attaching to that third person controller

wintry quarry
#

Basically your project is in a weird state - you have multiple scripts doing completely different workflows for handling input

digital haven
#

Okay where is that variable that is defined?

wintry quarry
#

How should I know

#

it's wherever you define this variable

#

higher up in this script, presumably

digital haven
grand snow
#

Looks like its the unity third person controller and it appears to have been pre set up with movement input so I can only presume its been broken by the action changes

wintry quarry
#

well it's broken because the type here is PlayerInput which again is ambiguous between your generated class name and the built in component

#

since the generated class lives in the global namespace it's just always picking that

#

Are you even using this script anymore?

wintry quarry
#

Didn't you write a different script for controlling the character?

#

If you're not using this script anymore you should just delete it

#

otherwise - you can change that variable to use the UnityEngine.InputSystem.PlayerInput class explicitly

digital haven
wintry quarry
chilly vigil
#

how do i use the locked function in unity

rocky canyon
#

which one? theres dozens of locks..

tawdry axle
#

Hey everyone. I've been working on this arcade game and I'm having trouble getting the 2D navmesh to work for the enemy AI. Right now when I hit play the enemy switches to the wrong plane and isn't visible by the player

#

I've tried rotating the surface to XY in the navigation surface component and then baking it but that hasnt worked

rocky canyon
#

why not rotate the pizza slice as a child object

  • Agent < move this
    • Gfx < rotate this to align towards camera
lilac cape
#

Does anyone by chance have a code example of using the new input system to interact with an object?

grand badger
fossil plaza
#

yo can someone teach me how c# works

#

im an idiot and cant understand tutorials

eternal falconBOT
#

:teacher: Unity Learn ↗

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

fossil plaza
#

im too dumb to look at that lol

cosmic dagger
#

Then you're going to have a hard time doing anything . . .

fossil plaza
lusty viper
#

If you can't understand tutorials then I dunno how someone would be able to teach you lol

polar acorn
#

We're also just text on a screen you know

fossil plaza
#

Questions

polar acorn
#

Yes we answer those. You have actually ask some first though

brisk granite
#

i was looking into OnParticleTrigger and was a bit confused by the documentation. is it supposed to be the OnTriggerEnter variation of OnParticleCollision? if so, it would be possible to use OnParticleTrigger to inflict damage on enemies/mobs, right?

ruby python
#

Early morning math issues. lol.

I need to remap values of 0 to areaHeight, to 0 to 90 (ie 0 to 2000 to 0 - 90) but my brain is failing. Any help please? 🫣

sour fulcrum
#

inverselerp then lerp?

grim flower
#

coming back from developing after a few years. is there a new way to do rb.drag?

sharp abyss
grim flower
#

Created a script for player movement. I am getting a lot of visual stuttering. Any clue what the issue might be?
Code:

public class playerMovement : MonoBehaviour
{
    InputAction moveAction;
    InputAction jumpAction;

    [SerializeField] private Rigidbody rb;
    [SerializeField] private BoxCollider bc;

    [SerializeField] private float movementSense = 3.33f;
    [SerializeField] private float lookSense = 1f;

    private Vector3 force;

    private void Start()
    {
        // Find the references to the "Move" and "Jump" actions
        moveAction = InputSystem.actions.FindAction("Move");
        jumpAction = InputSystem.actions.FindAction("Jump");

        rb.linearDamping = 10f;
    }

    void Update()
    {
        Vector2 moveValue = moveAction.ReadValue<Vector2>();
        force = new Vector3(moveValue.x, 0f, moveValue.y);
    }

    private void FixedUpdate()
    {
        if (jumpAction.IsPressed() && isGrounded())
        {
            rb.AddForce(Vector3.up * 5f, ForceMode.Impulse);
            Debug.Log("jumped");
        }

        rb.AddRelativeForce(force * movementSense, ForceMode.VelocityChange);
    }

    private bool isGrounded()
    {
        return Physics.Raycast(transform.position + Vector3.up, Vector3.down, 1f);
    }
}
keen dew
ruby python
chilly prism
#

help my play again button isn't working

frail hawk
#

is the button click triggered? use a debug

chilly prism
#

idk tbh

chilly prism
frail hawk
#

if you don´t know the button is working use a debug log inside the Restart Method

#

narrow down your problem

chilly prism
#

how

#

how do i check if the button is pressed or not

#

using Debug.Log

frail hawk
#

!learn, you lack basic unity knowledge

eternal falconBOT
#

:teacher: Unity Learn ↗

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

teal viper
chilly prism
#

yeah but how do i check

#

like what's the code

teal viper
#

Check what?

#

Debug log

#

Check docs for the proper signature

chilly prism
#

if (button == clicked) { Debug.log("clicked")}

teal viper
#

And no, you don't need an if statement

chilly prism
#

then what do i write

teal viper
#

You just need to put the log in the button method

chilly prism
#

ooooh

#

wait imma try smth and come back

#

will this work?

ruby python
#

More math brain failure.....

Would somebody be willing to take a look at this If declaration and see if I'm doing it right?

values are between 0 and 90 and I'm checking if my newLatitudeMin/newLatitudeMax variables fall within the min/max range. And also doing the negative (0 to -90)

                    if (rule.Latitude.Max < newLatitudeMax && rule.Latitude.Max > newLatitudeMin
                        ||
                        -rule.Latitude.Max > -newLatitudeMax && -rule.Latitude.Max < newLatitudeMin
                        )
chilly prism
#

i made this editor and runtime so i can press it while the game is paused

#

but when i press it it doesn't show up on the Console

stuck field
chilly prism
#

i am pretty sure i am pressing it

#

lmb

#

am i supposed to right click it or smth

stuck field
#

Does it change color to what you have defined?

frail hawk
#

pressing and being triggered are different things

chilly prism
#

why is my button not buttoning

stuck field
#

If you even have one on the object that is

teal viper
#

Test in play mode.

naive pawn
ruby python
#

Yeah I know, just couldn't think of the word. lol.

naive pawn
#

what exactly is the intention?

#

what's the input, which are constants

#

(if they're nonnegative, why check for negatives?)

ruby python
#

If the 'new' min and max value are between the min/max values of rule.latitude >> Do things

I have xml data that I'm reading in to a scriptable object, and the min/max values in the rules are between 0 & 90, so I also need to check for the negative to properly assign latitude values in both the northern and southern 'hemispheres' of my game world.

naive pawn
#

and the "new min/max" can be negative?

#

are you supposed to be using rule.Latitude.Min in some of those spots?

ruby python
#

Oh wait, hang on. I just realised that it's totally wrong. lol.

newMin and newMax are 'converted' from the 0-90 value in the rule.LatitudeMin/Max to the world values (currently set temporarily to 4096, so if rule.LatitudeMax is 90, newLatitudeMax is 4096) so I'm using completely the wrong things in the if statement. lol.

#

For context I'm using this.

https://assetstore.unity.com/packages/tools/terrain/procedural-terrain-painter-188357

And this script is hooking into it and generating the layers and rules (that govern the splatmaps), but it doesn't have a rule for latitude, so this is just a simple if statement to check the latitude from the xml that I have and simple turning of the other 'rule' layers (height and slope).

                <Rule>
                    <Layer Material="Snow"/>
                    <Height Min="0.0" Max="1.0"/>
                    <Latitude Min="80" Max="90"/>
                    <Slope Min="0" Max="30"/>
                </Rule>

Example of a rule in the xml

Get the Procedural Terrain Painter package from Staggart Creations and speed up your game development process. Find this & other Terrain options on the Unity Asset Store.

ruby python
#

My brain hurts. lol.

Sort of thinking out loud atm.

But I need to make an if statement that enables my terrainLayer rules between the values of rule.Latitude.Min and rule.Latitude.Max, otherwise disable them.

chilly prism
#

why is my button not working

chilly prism
#

can i screen share with one of you

teal viper
chilly prism
#

did someone figure out what's wrong

stuck field
#

There is a reason it isn't detecting it, and it can be found at that link (At least from my view)

ruby python
frail hawk
chilly prism
#

so how do i press it? i keep left clicking it

stuck field
#

Read it, and check it all

#

You can also try what the others said if that doesn't work, but I suspect it's something that is on that page

chilly prism
#

none of them are touching the button

#

i tried disabling the image and that still didn't work

ruby python
#

Check you container object (game over screen)

wild peak
chilly prism
#

it appeared before but i deleted it

wild peak
stuck field
#

Exactly what they would've added if they didn't ignore me 😭

ruby python
#

LMAO. Missed that one myself.

chilly prism
#

how do i add it

frail hawk
#

well you need the event system..

stuck field
wild peak
chilly prism
#

😭 🙏

#

literally the first thing on the website 😭 🙏

ruby python
#

Not trying to be a dick, but

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

stuck field
#

Should've listened

chilly prism
#

thx it works now

#

♥️

ruby python
#

dammit. lol.

frail hawk
#

it should not be possible to remove the event system but some things are weird in unity

ruby python
#

Yeah tbh, I've always thought that it should kinda be something that's there in the background anyway

chilly prism
#

how do i get that score number behind the pipes

stuck field
frail hawk
#

you can simply change their hierarchy order

chilly prism
#

imma try that

#

doesn't work

#

i also tried doing this, but it still doesn't work

frail hawk
#

in the hierarchy, you simply move them up and down( if you have seperate gameobjects)

chilly prism
#

the pipe isn't in the heirarchy, it spawns after you open the game

#

it is a prefab that spawns when you play the game

frail hawk
#

i see

#

you could use world space for your ui and play with the z

chilly prism
chilly prism
#

do i just make the z value in the negatives?

chilly prism
ivory bobcat
ivory bobcat
# chilly prism

There ought to be something more than that.. without a renderer there wouldn't be anything drawn to the scene..

chilly prism
#

it is a prefab

ivory bobcat
#

Doesn't matter

chilly prism
#

the renderer is on the children

ivory bobcat
#

Show us the child then

chilly prism
ivory bobcat
#

In the renderer component. There should be some sorting order value. I'm on mobile and it's quite difficult to see.

stuck field
#

Set it to 1 if you want that object in front of all the objects with order in layer to be 0 (I think)

chilly prism
#

ok

ivory bobcat
#

The canvas renderer would have one too. Try modifying the value to be different from the canvas' value.

chilly prism
#

doesn't work

stuck field
#

Gotta be more descriptive, did it do anything? if so, what did it do?

#

"Doesn't work" is too vague for us to determine why it didn't work, if it did nothing, then it's probably the wrong option/other objects aren't a lower value than what you set

chilly prism
#

the text is still in front

stuck field
#

And what is the texts order in layer value?

chilly prism
#

i made a new layer and called it pipe

stuck field
#

Might be why it doesn't work

#

It's the renderer order within the sorting layer

ivory bobcat
#

Show us the canvas' inspector

stuck field
#

Changing it means it's 1 in the pipe sorting layer, not 1 in the UI sorting layer

chilly prism
stuck field
#

Should be fine, sort order is 0

#

And I'm pretty sure that's just the order the canvases render but I might be wrong

ivory bobcat
chilly prism
#

then?

stuck field
#

It's flappy bird, doing that would make it be a bit wacky

#

I believe it's meant to be world space, not pixel space (camera space)

chilly prism
#

yoo

#

it works now thx

stuck field
#

Make sure the game still functions as intended just in case

chilly prism
#

i put the camera in the "render camera"

#

and made the z axis of the text -1

#

now it's behind the pipes

slender nymph
#

note that using a world space canvas is what was suggested when you asked about this yesterday

chilly prism
frail hawk
chilly prism
#

please excuse me guys if i sound stupid or do stupid stuff i am a beginner after all

#

🙏 🙏 🙏

stuck field
chilly prism
slender nymph
#

instead of just throwing a bunch of shit at the wall and seeing what sticks, you should take the advice you've been given multiple times and go through the pathways on the unity !learn site to actually learn what you are doing

eternal falconBOT
#

:teacher: Unity Learn ↗

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

frail hawk
#

btw the learn site is down ( for me at least in germany)

chilly prism
#

i like trying stuff until it works

sharp abyss
slender nymph
stuck field
frail hawk
#

anyone else having problems to see the learn site

stuck field
#

Nope, mine seems to be working just fine

slender nymph
#

nope, it's working for me. try clearing cache

frail hawk
#

tried

stuck field
#

Strange, maybe swap browsers?

naive pawn
frail hawk
#

it is down

naive pawn
#

that can mean a lot of things

#

the NX Finished probe/domain thing?

#

a cloudflare 522?

#

a 404?

#

an hsts error?

frail hawk
#

!oh no you broke the internet

#

lol

naive pawn
#

i ask because if it's a 404 then it might just be a bad redirect rather than it actually being down

frail hawk
naive pawn
#

yeah, thats the bad redirect

frail hawk
#

yeah it mus be somehthing with the redirection to the de

naive pawn
#

it's trying to redirect for localization but localization doesn't use that slug

frail hawk
#

well it used to work , i am only asking because someon else told me they cant see the page also from germany

naive pawn
slender nymph
#

remove the /de from the url then when the page loads scroll all the way down and select your preferred language

naive pawn
frail hawk
#

it auto redirects to the de and no way to avoid it

naive pawn
#

does that workaround work

frail hawk
#

allright

slender nymph
frail hawk
#

let us wait a little bit., might be some temp problem

naive pawn
#

it isn't

#

as evidenced by the message i linked to being 5 days old

frail hawk
#

oh now i read the previous messages, you are right

small wyvern
#

Hey so, i am a beginner. I wanted to do a 2d Top down based game (like pokemon).Right now i try to figure out how to make a scene swich in unity. So i can interact with an NPC or get another Trigger wich starts a TurnBased battle. What do i need to look up for this or are they any videos. Dont found much related to this.

ruby python
#

Could anyone explain this to me please, as it seems like a very bizarre thing.

#

This is how the SO's get created.

Slope layerSlope = ScriptableObject.CreateInstance<Slope>();
slender nymph
#

the method expects a Type object as the first parameter, not a type. you can get the Type object for a specific type using typeof

cosmic dagger
slender nymph
#

but also you should ideally be using the generic overload rather than that one anyway

ruby python
#

Right okay, it's just for editor useage, as on second run the SO's break everything. lol.

teal viper
sharp abyss
#

Took some parts from examples and modified it.

teal viper
sharp abyss
#

But what can solve that?

#

I tried removing walls that collide with more than 1 wall but that didnt do anything

sour fulcrum
#

Code does what it’s told. Either you don’t know how to tell it something or you don’t know how to obtain what that something is via code

#

You gotta figure out which of those is your current problem

teal viper
# sharp abyss But what can solve that?

Having a quick look at the code, you create positions for each wall and add them to a list. You'll just need to modify the logic that calculates these positions.

idle grove
#

im sorry for bothering yall, but is there something im supposed to do to not have my bottom function grayed out? in the tutorial im following it is working fine, but when i tried, even fixing some errors i did find, the editor dont even aknowledge errors or anything, the collision function just doesnt work

#

im sorry if its a stupid question

naive pawn
#

you misspelt it

#

it's OnCollisionStay2D

idle grove
#

ooh

inner crane
#

what are these icon called? - Texture2D icon = EditorGUIUtility.IconContent("sv_label_x").image as Texture2D; for the bigger ones but i need the dots

idle grove
#

i thought it would notify me for commiting such a blatant error, i need to be more aware

inner crane
#

mhm alright ty

umbral bough
#

Hi, I am trying to store references to my input actions in the inspector so they don't have to be initialized every time the game runs but this resets every time I reload the scene
https://hastebin.com/share/cavifoyija.csharp

Am I doing something wrong or is this just a limitation of the input system?

#

Please @ me and thanks in advance!

rocky canyon
#

use InputActionReferences?

kindred halo
#
Please set the PATH to a dotnet host that matches the architecture x64. An incorrect architecture will cause instability for the extension ms-dotnettools.csharp.

should I be worried about this?
I'm getting this in vscode ever since I installed C# extension

rocky canyon
#

did u install the correct one? did u install the 32 bit version on accident?

kindred halo
rocky canyon
#

well i dont know a whole lot bout the .net sdks and stuff but the error would lead me to believe its the wrong versioning

frail hawk
idle grove
kindred iron
#

Guys There is a button animation which is at a button and whenever the player hover the button an animation plays but when the player clicks to the button before the buttonhover animation is finished stays the button big cuz the anim couldnt finish itself. What should i do?

rocky canyon
#

if click -> snap to final size

kindred iron
rocky canyon
#

or change around the logic so the animation finishes regardless

storm frigate
#

why does mine onclick function doesnt work

slender nymph
#

You need to get your !IDE configured 👇

eternal falconBOT
storm frigate
slender nymph
#

it was not configured in the screenshot you sent

storm frigate
#

i did everything i need to do

frail hawk
#

do you have a collider on your gameObject and is this script on your desired gameobject to detect the OnMouseDown?

#

and as boxfriends said, it is crucial to have your IDE working properply along with intellisense

slender nymph
#

in fact, it is a requirement to have it configured to get help here

frail hawk
#

yeah i already pointed it out

slender nymph
#

you should read that too 😉

frail hawk
#

i did and this is why i answered

hallow acorn
#

hey i want to make a bush in my 2d topdown game where you can click on the bush to collect berries from it. how can i check the mouse position and if it overlaps the collider of the bush?

frail hawk
#

you could use the OnMouseDown on your sprite

hallow acorn
hallow acorn
frail hawk
#

make sure to put a 2d collider on your sprite if you haven´t yet

hallow acorn
frail hawk
#

really many ways to do that, it is up to you

hallow acorn
#

ty for the help

frail hawk
#

i am glad i could help

slate heath
#

Is there a way to make for certain cells in a tilemap have some tag or something reconocible by code?

slate heath
#

For example here, how can I make to detect that the cell is sand and not grass?

wintry quarry
#

With GetTile

slate heath
#

wouldn't that be expensive?

#

There should be another way

wintry quarry
#

Dictionary lookups are essentially free

red brook
proper compass
#

I need help, with my Movement/Locomotion, I have it so when you hit your controller trigger that hand gets ancorder and you can rotate your body around your hand (0 like gravity not to strong)
How would i make it so i can hold trigger puch or and let go of the tigger and i kindda jump on ait? I have tried this but i go in the wrong direction etc.

wintry quarry
#

Wat

rich adder
rich adder
#
public class BoardTile : Tile  {
public TileType TileType;
}```
slate heath
#

I’ll check that

#

Thanks

rich adder
pearl current
#

Hey guys, how do I make an enemy attack only once per swing in Unity?

I have a skeleton that chases the player and flashes a hitbox when close to attack. But right now, it deals damage multiple times per swing (based on frame rate). How can I make it only hit the player once per attack?

Here's the attack sequence code I currently have:

private void HandleAttack()
{
    animator.SetBool("isAttacking", true);
    attackTimer -= Time.deltaTime;

    if (attackTimer <= 0)
    {
        Attack();
        attackTimer = 0.78f;
        animator.SetBool("isAttacking", false);
    }
}

private void Attack()
{
    StartCoroutine(FlashAttackHitbox());
}

private IEnumerator FlashAttackHitbox()
{
    canDamage = true;
    attackCollider.enabled = true;

    yield return new WaitForSeconds(0.1f); // short hit window

    attackCollider.enabled = false;
    canDamage = false;
}

private void OnTriggerEnter2D(Collider2D other)
{
    if (canDamage)
    {
        canDamage = false;
        if (other.CompareTag("Player"))
        {
            PlayerHealth playerHealth = other.GetComponent<PlayerHealth>();
            if (playerHealth != null)
            {
                playerHealth.TakeDamage(attackDamage);
                Debug.Log("Player hit by skeleton.");
            }
        }
    }
}```
rich adder
#

you might have multiple coroutines running

#

nothing here should be dependent on framerate afaik

#

but coroutines can be overlapped without checks there is no limit to how man times you can run them

pearl current
#

would i put the if statement within the flashattackhitbox function or within the attack funciton you think?

rich adder
#

up to you .. maybe you can even do

attackTimer <= 0 && canDamage```
#

or actually yeah put it before StartCorutine

#

if(!canDamage) return;
StartCoroutine(

pearl current
rich adder
pearl current
#

very true... idk why it's being called multiple times 😵

rich adder
pearl current
prime goblet
#

how can i access the Image from a script?
public Image promptBacking;
the hierarchy wont accept it

rich adder
prime goblet
#

it's in the scene too

#

and it doesnt do anything when i drag it into the slot

rich adder
prime goblet
#

using UnityEngine.UI;

#

namespace?

#

the script has no namespace

#

unless oyu mean that

rich adder
#

using statements use namespaces yes

prime goblet
#

ah alright

rich adder
#

is the script on an actual gameobject ?

prime goblet
#

yes

#

it's an Empty

rich adder
#

in the scene ? and is Image in the scene too

prime goblet
#

Yes

#

backing is the image, ladderpromptspace is where the script is defined

rich adder
#

what happens when you drag the Backing object in the ladderPromptSpace image field

prime goblet
#

nothing

#

the thing under the cursor just goes back to the hierarchy

#

and i restarted unity

rocky canyon
#

hover ur Image reference make sure its the UnityEngine.UI. one

rich adder
#

I guess we will never know sadpanda

rocky canyon
#

screenshots were too cryptic anyway

past yarrow
#

Hey,

Why the attribute InspectorName() doesn't work for my variables MINES_AMOUNT, GRID_WIDTH and GRID_HEIGHT please ?

past yarrow
teal viper
past yarrow
wintry quarry
teal viper
past yarrow
past yarrow
teal viper
#

If it's regarding serialization, then you can't serialize constants. That's the whole point of them - they remain constant.

past yarrow
teal viper
#

In code

past yarrow
#

argh

#

so I can't make them "const" because I need to see them in inspector but at the same time I don't want to be able to change them through code, so I guess I have to go for readOnly ?

#

even with readonly it complains 😦

teal viper
#

You could have a getter property pointing to the serialized field.

past yarrow
#

mhhh

teal viper
#

Though, you will need to remember only to use the property.

past yarrow
#

yeah 😬

#

Well I won't make it const nor readonly, and will make it lower case to see it displayed properly in inspector

#

Wait, how does FormerlySerializedAs() work ?

#

There's only 1 parameter being oldName so how does it get the new name that I want 🤔

teal viper
#

The new name is the actual name that you change.

past yarrow
teal viper
#

In code..

#

If you change the name of a field but want to preserve the previously serialized value, you use that attribute and put the old name as the argument.

past yarrow
#

wait, so if it displays still as MINES_AMOUNT instead of Mines Amount, I'm really confused

teal viper
past yarrow
teal viper
#

What did you change?

#

Why are you trying to use that attribute?

past yarrow
teal viper
#

I don't think that's how it works.

past yarrow
#

oh ok 👍

trim lintel
#

Im having some trouble making a project, every time I try to make one using the 2D (built in render pipeline) or Universal 2D, it gives me the "Failed to decompress", Am I missing something, thanks in advance

teal viper
teal viper
#

That only answers one of my questions

trim lintel
#

oh sorry, i have to recreate it real quick

#

After this happens, it doesn't allow me to use the project at all

teal viper
#

Try reinstalling the edior and pay attention to any issues/errors in the process.

sour fulcrum
#

What happens if I use previously serialisedfield attribute while still also having that previous field existing? Does it deserialize to both?

wintry quarry
#

Maybe an error

#

Nothing good certainly

sour fulcrum
#

Will do later today 😄

It’s not something I wanna do but it’s an established released api thing so I’m very restricted on options

proper compass
#

I need help, with my Movement/Locomotion, I have it so when you hit your controller trigger that hand gets ancorder and you can rotate your body around your hand (0 like gravity not to strong)
How would i make it so i can hold trigger puch or and let go of the tigger and i kindda jump on ait? I have tried this but i go in the wrong direction etc.

past yarrow
#

!code

eternal falconBOT
past yarrow
#

Guys I struggle making my grid generate in the center, how can I do that please ?
Like depending on the FOV of the Camera, the grid size, etc... the grid isn't in the middle of the screen, big grids have their right side outside of the visible part, so I can't press those tiles there making the game unfinishable 😬

What's the best approach to make it adapt to the screen size and be in the middle of the screen please.

Here's my code : https://paste.mod.gg/ujggasskdyjt/0

trim lintel
storm frigate
#

how do i fix it

ivory bobcat
eternal falconBOT
teal viper
#

Is there any reason you need to use that api?

storm frigate
#

i just forgot about this player

chilly prism
#

how do i make the background music stop when the game over screen appears

teal viper
chilly prism
#

how

stuck field
# chilly prism how

Exactly how dlich stated it, I really do recommend going through the pathways at !learn as we've told you many times, it'll help a lot (I get you dislike reading, but it'll help a lot)

eternal falconBOT
#

:teacher: Unity Learn ↗

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

stuck field
#

Just call Stop the same way you call Play

#

But I really do recommend heading to learn, give it a shot at least

chilly prism
stuck field
#

Yeah I really do think you need to go to the learning pathways

chilly prism
#

🙏

#

i tried making a stopbackground music function but idk how to use it

#

doesnt work

sour adder
#

You need to put (); at the end there.

chilly prism
teal viper
chilly prism
#

i already did, i just got confused here

#

i know how to write a function and use it i just got confused for a second

#

but you're right i still need to learn a lot of stuff

teal viper
#

Then you should know that it's called a method, not a function in C#.

chilly prism
#

i got confused again, i learnt python first

#

i thought they were called the same in both languages

sour adder
#

Stopping a sound abruptly may introduce audible popping/clicking... you can fade out the volume before stopping, but that's more advanced. If you don't hear anything it may be fine.

teal viper
chilly prism
#

I will go over the basics again!

thorny swan
#

can somebody help me? im in the rollaball tutorial and i wrote the script exactly as it shows to move the ball yet when I press play it shows all compiler errors...

teal viper
thorny swan
#

@teal viper

teal viper
stuck field
#

Check console

teal viper
#

Did you not look at the console?

thorny swan
#

idk im a beginner

stuck field
#

You should learn how the unity interface works before getting into the programming part

cloud skiff
#

Damn why are people blasting here wtf

#

Relax

thorny swan
#

it shows this

teal viper
eternal falconBOT
#

:teacher: Unity Learn ↗

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

thorny swan
#

yet i have that error

#

wdym

#

who makes a game about blue balls in his spare time

teal viper
#

TIP: case(upper/lower) matters in C#.

thorny swan
#

ill revise it again

teal viper
thorny swan
#

yep

proper compass
#

I need help, with my Movement/Locomotion, I have it so when you hit your controller trigger that hand gets ancorder and you can rotate your body around your hand (0 like gravity not to strong)
How would i make it so i can hold trigger puch or and let go of the tigger and i kindda jump on ait? I have tried this but i go in the wrong direction etc.

thorny swan
#

hell yeah now i have blue balls

frail crane
#

guys, I am trying to make a pong game but I can't get the movement to be how I want it. I want it to be so when the player presses a button and keeps pressing it the paddles move up or down as long as the button is pressed, BUT I also want them to stop the moment players takes their hands off. I tried velocity, transform and stuff, but the paddles only move once or keep moving due to velocity or force. I hope I could be clear. I would appreciate any help

twin pivot
#

sorry massive migraine laptop lights hurt

fast fern
#

What do I do if my application works on my device, but does some functions do not work on another user's device
basically its just, click button and things are supposed to move and make next page button active, but it does not work for my friend

#

is this code related btw? or this problem varies?

twin pivot
frail crane
twin pivot
#

this method of approaching it is just held together by hopes and dreams

chilly prism
chilly prism
#

i am trying to make a main menu button and this is the script but it doesn't work idk why

wintry quarry
#

GetSceneByName only works with scenes that are already loaded

chilly prism
#

YOOO

#

THX IT WORKED

#

you're goated fr

naive pawn
past yarrow
cinder void
#

Hi, im trying to make a game using cinemachine follow camera, i'm trying to fit two "rooms" in a single scene where the player can transition from one room to another using a trigger. However, i'm having problems because the cinemachine confiner only accepts one collider, i decided to try switching the confiner in code, but it seems that while the cinemachine camera DID move when changing rooms, the main camera itself doesn't, am i doing something wrong and is there a better approach than this? Thanks in advance

wintry quarry
signal nest
#

hiii,
so basically I tried installing unity but I have no clue what I'm doing. The tutorial I tried to follow used code that I don't think works in unity 6; I have been trying to figure out how to take player inputs but it all just isn't making sense to me, and I'm certain I keep finding different ways to do things. I know how OOP and C# work, but I'm at a loss when it comes to using it with unity. Can someone please explain how to take player inputs and why it works? Also, how do you link, like, code to assets?

wintry quarry
signal nest
#

ig that makes sense... shoudve thought of that

lusty viper
#

I use field and attribute interchangeably too in other languages but I know attributes are something different in c#

naive pawn
#

afaik methods are just a subset of functions
functions are either methods or free functions

lusty viper
#

free functions being functions not associated with a class? Can you even do that in C#?

#

Would be awesome if so

naive pawn
#

not really

#

i guess maybe you could consider delegates/local functions as "free", but maybe that should just be called a separate type of function

lusty viper
#

Gotcha

#

Yeah that's kinda how I've been doin functional stuff, not really local but I just have a class with only static pure methods

nimble apex
#

native C# question, is iparsable supported by unity?

#

i want to make a generic getter function

slender nymph
#

if you'd look at the documentation page for it you'd see it is only available in .net 7 and above

hallow acorn
#

hey im trying to make a clickable bush where you can harvest berrys when clicking in a certain range to it but i get a nullReferenceException on line 17. could anyone explain why this could be happening?

using Unity.VisualScripting;
using UnityEngine;

public class BushManager : MonoBehaviour
{
    [SerializeField] private float pickUpRange;
    [SerializeField] private float growTime;

    private bool berriesReady = true;

    void PickUp()
    {
    }

    private void OnMouseDown()
    {
        float distanceX = transform.position.x - GameObject.FindGameObjectWithTag("Player").transform.position.x;
        float distanceY = transform.position.y - GameObject.FindGameObjectWithTag("Player").transform.position.y;

        float distance = Mathf.Sqrt(distanceX * distanceX + distanceY * distanceY);

        if (gameObject.GetComponentInChildren<Transform>().CompareTag("Berry") && distance <= pickUpRange && berriesReady)
        {

        }
    }

    private void Grow()
    {

    }
}
naive pawn
#

which one is line 17

#

also use some variables

#

don't do FindGameObjectWithTag twice lol

#

also are you working in 2d or 3d?

hallow acorn
hallow acorn
polar acorn
#

Don't use Find. Make a variable and drag your reference in

naive pawn
#

and then you can do Vector2.Distance(transform.position - player.transform.position) instead of doing the hypot yourself

hallow acorn
#

ok i why is it failing tho?

naive pawn
#

there's no gameobject with that tag, presumably

#

gameObject.GetComponentInChildren<Transform>().CompareTag("Berry")
this also doesn't really make sense.

hallow acorn
naive pawn
#

it'll just get the current transform

naive pawn
naive pawn
#

show its inspector

polar acorn
hallow acorn
#

oh shit i was 100% sure i added the tag my bad

polar acorn
naive pawn
#

yeah, they're pretty fragile

polar acorn
#

And especially not twice

hallow acorn
#

ok ill try to avoid it

naive pawn
#

just use a reference, possibly a serialized one, or perhaps a singleton or a physics query if there's gonna be a ton of these

naive pawn
# hallow acorn why?

anyways about this
are you trying to check if a child object exists, or what exactly?

hallow acorn
naive pawn
#

use a serialized reference for that

#

CompareTag wouldn't work and GetComponentInChildren<Transform> wouldn't get the right component anyways

hallow acorn
#

serialized reference?

naive pawn
#

a public or [SerializeField] field that you drag the relevant object into

hallow acorn
#

ahh ok never heard the serialized before sry

sterile radish
#

hi, im currently trying to make a dialogue system similar to that of undertale. i already have it working so that it displays text whenever you interact with a character through a list of strings. how would i go on about adding dialogue choices to this system?

lusty viper
#

Maybe you could make it a list of structs instead of just strings - you could define a struct like

public struct Dialogue
{
  public string message;
  public string[] choices;
}

Then if choices is empty, you know it's a normal message without dialogue choices, otherwise if choices has stuff in it, then you display those as choices!

#

(nice pfp btw)

sterile radish
pallid nymph
#

Back when I was more active in another discord server, whenever dialogues were mentioned, people would suggest looking into Ink and Yarn (Spinner?). Those are pre-made dialogue systems that integrate with Unity.

sterile radish
lusty viper
#

I think it's good to try your own though just as a good way to learn!

lusty viper
#

So maybe it would be better to model it as sort of like a linked list

#

I.e.

public struct Dialogue
{
  public string message;
  public Dialogue[] choices;
}
rocky canyon
naive pawn
lusty viper
#

True my bad lol

#

You get the idea

naive pawn
#

i mean a linkedlist is just a unary tree...

lusty viper
#

True!

rocky canyon
#

i keep reading LinkedIn

sterile radish
naive pawn
rocky canyon
#

lol

rocky canyon
naive pawn
#

like a unary operator -x +x !x ~x

rocky canyon
#

ahh that what i thought makin sure

#

1ary - binary - trinary

naive pawn
#

ternary, but yeah

#

(ternary operator!)

rocky canyon
#

lol 🫡 til

naive pawn
#

-# imma take this oppurtunity to mention for no particular reason that ts has a quaternary operator

lusty viper
#

huh what's the quaternary? can't find any hits on google lol

naive pawn
#

quaternary would be 4 operands, it's A extends B ? C : D

eternal needle
naive pawn
lusty viper
#

Ah yeah, idk I would have thought that's just a composition of the conditional and extends

#

Like I guess you could have a 5-ary just by doing A ? B ? C : D : E

naive pawn
#

i mean it is the intent but:

  • there isn't any other check to use with a conditional
  • extends can't be used on its own in a type, it's only for conditionals (and constraints/inheritance, but that's a different context)
  • most AST parsers parse the entire thing as a quaternary operator, rather than a conditional with an extends clause as the condition
    • you can't put parens on the condition
rocky canyon
naive pawn
lusty viper
#

Ugh I love the ts type system

naive pawn
#

ikr 😄

lapis parrot
#

it's saying "the name 'playerdamage' does not exist in the current context" i don't see what's wrong please help private void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Player"){ other.GetComponent<PlayerController>().DamageTaken(playerdamage); Debug.Log("Player Hit"); } } // this is on one script public void DamageTaken(float playerdamage){ PlayerHealth -= playerdamage; if (PlayerHealth <=0f){ Debug.Log("Player Dead"); } }// this is on the other Please help

naive pawn
#

well then it doesn't exist

lapis parrot
#

huh

#

how

naive pawn
#

that's what the error says

lapis parrot
#

yeah but how does it not exist

naive pawn
#

first off, where is the error showing up

lapis parrot
#

in this line other.GetComponent<PlayerController>().DamageTaken(playerdamage);

#

i have no clue in the universe why

naive pawn
#

maybe because it doesn't exist?

#

like the error said lol

#

if you think it exists, where did you define it

lapis parrot
rocky canyon
#

well do u have a variable called This ^

#

these are two different things

lapis parrot
#

wait what

#

how

naive pawn
rocky canyon
#

this is an INPUT

#

u can put any variable u want in there ^

lusty viper
rocky canyon
#

and it'll get ASSIGNED to playerdamage (the one u made in the function float..)

naive pawn
#

DamageTaken(float playerdamage) means playerdamage exists in the context of DamageTaken (and its class)
the error is in the context of OnTriggerEnter2D and its class
the error says that playerdamage doesn't exist there

rocky canyon
# lapis parrot ohhhhhhhh🗣️
    float anyNumber;

    void CallDamageFunction()
    {
        Damage(anyNumber);
    }

    public void Damage(float playerDamage)
    {
        health -= playerDamage;
    }```
#

ya, playerDamage is a basically a local variable to the Damage() function

#

it doesn't exist outside of it

lapis parrot
#

so would DamageTaken be anyNumber

rocky canyon
#

in this example when it runs yes

#

Damage(10f); would work also

lapis parrot
#

well when i run it there's no errors but the player doesnt take damage

rocky canyon
#

basically these are teh same.. (whatever u call the function with becomes that local variable (w/e u named it)

#

but this has zero to do with the naming of anything

#

u can pass in any variable.. any value.. as long as its a

naive pawn
rocky canyon
#

so if u copied and pasted exactly

#

it wont

#

its basically 0 unless u define it as being something else

#

float anyNumber = 10f; <-- if u declared it like this.. and then called Damage(anyNumber)

lapis parrot
#

oh so would anyNumber == 10f work i'm so confused about numbers in coding

rocky canyon
#

it'd delete 10 from health

rocky canyon
lapis parrot
#

oh fr?

rocky canyon
#

buy anyNumber = 10f; would

#

or u can assign it before using it

naive pawn
#

or you can have it serialized so you can modify it in the inspector so you don't have to recompile every time you change the value

rocky canyon
#

    float anyNumber;

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            // pressing space sets number to 10 and calls function
            anyNumber = 10f;
            Damage(anyNumber);
        }

        if (Input.GetKeyDown(KeyCode.Return))
        {
            // pressing enter sets number to 20 and calls function
            anyNumber = 20f;
            Damage(anyNumber);
        }
    }```
#

heres a decent example

lapis parrot
rocky canyon
#

; at the end but yea

naive pawn
#

and name it better lol

lapis parrot
#

the thing is is that i'm trying to get an enemy to damage the player

#

and it's still not working 😭 i am extremely confused

naive pawn
#

show your current !code

eternal falconBOT
rocky canyon
#

youll need to DEBUG

#

like chris mentioned

#
  1. check if the function is being called
  2. check if the values are expected
  3. etc
rocky canyon
lapis parrot
rocky canyon
#

ohh jeez

lapis parrot
rocky canyon
#

ur IDE should look like its having a rager..

#

with red and yellow squiglies everywhere

lapis parrot
#

wth is ide

rocky canyon
#

the thing u code in

#

ahh nvm its fine

#

ur brackets are all just bunched up at the end

#

that threw me off

lapis parrot
#

triple brackets ftw

rocky canyon
#

but structured lol

#

both links are the same code?

lapis parrot
#

wait what

#

oh it is

#

there's 2 tabs tho

#

sorry

naive pawn
#

brackets

rocky canyon
rocky canyon
#

which logs do u get and which logs do u dont get?

lapis parrot
#

well i expect to see "Player Hit" in the debug logs

#

but there is nothing

naive pawn
#

add a log outside of the if statement

lapis parrot
#

a tumbleweed goes across

naive pawn
#

as the first thing the method does

rocky canyon
#

u should get rid of htis function

#

and that variable..

#

no reason to have that in the player code

naive pawn
#

i suspect the tag isn't matching

rocky canyon
#

^ yea its probably a collision issue

lapis parrot
#

hold up let me check the tags

rocky canyon
#

if (other.tag == "Player") and an alternative for this is just if(other.CompareTag("Player"))

#

and OnTrigger only works with Triggers

#

if ur Player or w/e ur touching for damage isnt a trigger (which i wouldnt see why it would be) that function isnt gonna run either

lapis parrot
#

wait isnt it oncollisionenter

rocky canyon
#

OnCollision...2D for contact yes

#

triggers are like invsible colliders ud use for a pressure plate/ doorway entrance/ lava pit