#💻┃code-beginner

1 messages · Page 149 of 1

stuck palm
#

idk what it is

#

did u find anything with the particle systems btw?

rocky canyon
#

looks like its grabbing the first collider.. and if ur happening to be overlapping (2) of em.. it just gets the first one and ignores the 2nd

stuck palm
rocky canyon
stuck palm
#

making it smaller and nothing happened so

#

idk whats up with that

fervent abyss
#

I'd love if someone explain me what are Interfaces in C# for
Ive watched some youtube videos about this but still dont get itwahh

rich adder
polar acorn
#

So, if you really don't care what an object does when it gets shot (Is it a crate that breaks? An enemy that dies? A target that opens up a locked door?) you can have an IShootable interface on all of them and your bullet can just say "Please call your GetShot() method, whatever it is"

fervent abyss
#

So is it just a thing with methods/variables that you cant give behaviour to, but you can add the interface, and give these methods/variables inside a behaviour that you want?

rocky canyon
#

IClickable with a CLick() method for example... it can be a NPC it could be the player, or a pickup.. each script would use the IClickable interface.. so each script would need the Click() method for it to compile.. so now u can call Click() on anything u click and the script will handle w/e it does..

rich adder
rocky canyon
#

that way ur click script that does the clicking doesnt need to do a check each time to find out what type of script ur clicking on

fervent abyss
rich adder
rocky canyon
#

yessir

rich adder
#

but they all have the same method

rocky canyon
#

so it works for things that are common

#

IClickable. IDamageable. IMoveable

#

etc

polar acorn
# fervent abyss So is it just a thing with methods/variables that you cant give behaviour to, bu...

It's a thing that defines methods and properties, but doesn't implement them. You can make any other class implement that interface, and the compiler will force you to add those methods/properties to that object, and an instance of any object that implements that interface can be stored in that variable.

Using the example above, you'd have classes with type lines that look like this:

public class BreakableCrate : MonoBehaviour, IShootable
public class Enemy : MonoBehaviour, IShootable
public class Target : MonoBehaviour, IShootable

And your bullet could simply do:

other.GetComponent<IShootable>().GetShot();

and it'll get whichever MonoBehaviour on that object implements IShootable

fervent abyss
rich adder
rocky canyon
#

its so when u click u dont have to do 10 different checks to find out what kind of Method ur calling..

polar acorn
rocky canyon
#

^ to avoid that exactly

polar acorn
#

And any time you added a new shootable thing you'd need to go change this function

rich adder
#

exactly you would have a huge mess of if checks

polar acorn
#

If you use interfaces, you can add in a new script:

public class Balloon : MonoBehaviour, IShootable

and it instantly works with the bullet, no other changes needed

rocky canyon
#
        if(confirmedHit)
        {
            if(!shiftModifier)
            {
                if(hit.collider.TryGetComponent(out Unit_RX orderRx))
                {
                    SelectUnit(orderRx);
                }

                if(hit.collider.TryGetComponent(out Selectable selectedTarget))
                {
                    Select_WorldObject(selectedTarget);
                }
                Debug.Log("Normal Click");
            }
            else
            {
                Debug.Log("Shift + Click");
                if(hit.collider.TryGetComponent(out Selectable selectedTarget))
                {
                    //HandleSelectedTarget(selectedTarget);
                }
                else
                {
                    HandleUnselectable(hit.collider,hit.point);
                }
            }
        }``` heres an example of my script that imma be changing over to interfaces
#

no need for a big ass nasty if else chain. esp when i start adding more and more selectable objects

spare umbra
#

While other Actions are working, Look is not

#

What is wrong?

polar acorn
#

Did you save the input asset and make sure "generate C#" is checked?

fervent abyss
rich adder
#

no

rocky canyon
#

u dont even have to tell it what class..

polar acorn
rocky canyon
#

all it knows is if its an Interface of that type.. it calls the method regardless

#

each method would be written to do different things in each script that uses that interface

polar acorn
# spare umbra yep

If you try to use Look, do you get any errors in Unity, or just the IDE? It might need to have the project files regenerated to realize the input asset changed

robust condor
#

If I have a function I want to run every 5 seconds, not every frame, how can I slow that down?

robust condor
#

With yield seconds?

fervent abyss
#

Thanks

robust condor
#

And I can put that in Update?

rich adder
polar acorn
spare umbra
#

no errors in unity

polar acorn
spare umbra
#

I mean, is this the equivalent of getaxisraw

robust condor
#

But how do I make it run forever? That ends after 5 seconds. Do I put a while loop inside it?

rocky canyon
# fervent abyss Thanks

https://hatebin.com/thcuqpgtku
an example usage.. Interface at the top, two different scripts that use the interface in the middle.. and on the bottom how a script would determine if its an interface and call the Method of it, edit: as long as it find a script that uses the interface you know u can call the Method... b/c all the classes using it MUST have that function in order to be properly implemented

spare umbra
trail fox
#

im tryna make an inventory but need a design where can i make it

rocky canyon
#

have fun 👍

#

inventories are tough to design from scratch

trail fox
#

where can i do it tho

rich adder
#

in the code

rocky canyon
#

what do you mean where?

trail fox
#

cant i just use sprites or smth

rocky canyon
#

you can use sprites, text, or pixels.. or anything else u want

rich adder
trail fox
#

yea

#

for the ui

shrewd swift
#

i got a question

to interpret visual scripting ,unity automatically builds .cs files right ?

rocky canyon
#

start browsing for tutroials.. or examples on youtube or github.

shrewd swift
#

like shader graph builds shader assets

rocky canyon
#

find one thats already built on the asset store.. and reverse engineer it

#

you code inside an IDE (Visual Studio Community) (VS Code) (Notepad)

#

an inventory would be a mix of Graphical elements.. and code

shrewd swift
#

I know this is technically unrelated to coding since im going to talk about visual scripting, but I got a friend that loses ALL created variables when building (out of the project folder ofc)

what could be the reason ? it happened multiple times

shrewd swift
rocky canyon
#

All the assemblies are located in /GAME NAME_Data/Managed/```
shrewd swift
#

mh

rocky canyon
#

it isn't technically .cs files after you build

shrewd swift
#

but does is go through the process of creating cs files before compiling ?

polar acorn
#

Probably not

#

It likely compiles into machine code like the CS files do

shrewd swift
#

i asked the question on the VS server in case, maybe someones knows for sure

#

idk how unity can remove variables from grpah assets when building

#

ty for the answers guys

shrewd swift
rocky canyon
#

tell ur friend to rip the bandaid off and start coding in csharp

#

in the long run, they'll not regret it

languid spire
rocky canyon
#

ive seen that before whats IL abbreviation?

polar acorn
#

Intermediate Language I believe

rich adder
#

Intermediate lang

languid spire
#

IL Intermediate Language

prisma silo
#
transform.position.y = cameraGameOBject.transform.position.y;
``` doing this gives me the error Cannot modify the return value of 'Transform.position' because it is not a variable
rich adder
rocky canyon
#

u cant directly modify the transform's individual properties

prisma silo
#

oh ok

polar acorn
rocky canyon
#

copy the entire value, edit that and plug it back in 👍

prisma silo
#

ig ill just make a new vector 3

polar acorn
rocky canyon
#

we need some slash commands for vertx's page 😄

shrewd swift
rocky canyon
#

always with a deadline lol

shrewd swift
#

xD

#

"school" project

rocky canyon
#

well, they might require him to do it in visual scripting

#

iono, but i dont trust visual scripting at all. u kinda confirmed it better for me

shrewd swift
#

lucky i already did a lot of lua, py and php so learning csharp wasnt that hard for my game project scope

#

it was more about learning how unity works

rocky canyon
#

ya, that makes sense.. if i were to chose tho i'd pick a very small project im able to complete (even with little scripting knowledge) than a bigger one that i end up not finishing with visual scripting (which seems easier from the outside looking in)

shrewd swift
#

before learnign unity, i was using blueprints in UE for 1 year and a half

and damn that UE did a good damn job with VS

#

i first tried unity VS but it was horible

rocky canyon
#

if you say so

shrewd swift
rocky canyon
#

ya, cuz u cant see anything 😄

#

this needs fixed
burns down computer

rich adder
#

to be fair I've seen people's code be exactly the same thing

#

you just don't "see it"

shrewd swift
#

VS code cant be more easily messy than other languages
but csharp can still be a bunch of code written evrywhere with no logic

rocky canyon
#

lol. atleast you can use keywords and the find function to help..

rich adder
#

eh as long as you can get the job done, doesn't matter what you use

rocky canyon
#

in visual scripting ur just moving around nodes to make them look pretty

#

ive seen a youtuber that coded on his telephone..

#

so ur correct @rich adder the tools are irrelevant.. (in a sense)

shrewd swift
#

yeah VS doesnt help you to get well structured

rocky canyon
#

you can hammer a nail into the wall with a screwdriver if u want..

#

it'll eventually go in

rich adder
rocky canyon
#

gotta give respect where respect is due

shrewd swift
#

this is a kinda well sorted graph for me

#

like regular code each people got their manners

rocky canyon
#

ya, thats pretty normal

rich adder
#

still looks horrible but ig depends what you're used to reading

rocky canyon
#

you can group the nodes together too to make it even better

shrewd swift
#

this was before making it more readable

shrewd swift
rocky canyon
#

u can encapsulate nodes into a group

#

and clean it up a lot

#

what are they. Macros i think they call em

shrewd swift
#

yeah ik

#

let me open my project

#

damn its been more than half a year i didnt do UE

#

Unity takes all my time :(

rocky canyon
#

ya, i thought i was going to swap to unreal.. but came right back to unity..

#

unreal is pretty but unity to me is easier and more powerful

shrewd swift
#

im still team UE
but Unity is really decent

#

thought it was trash tbh ...

#

didnt dig much of it before trying to dev

rocky canyon
#

well if ur in the UE echo-chamber.. thats probably what id expect

shrewd swift
rocky canyon
#

ya, thats better.. thats the only way i can use visual scripting.. is to use different colors and groupings

#

otherwise i get super lost

shrewd swift
#

introducing a part of my save system

#

atleast its pretty

rocky canyon
#

pretty spaghetti

shrewd swift
rocky canyon
#

gotta use Headers too

shrewd swift
#

yeah for inspector

#

but iwas talking the code in visual studio

rocky canyon
#

mmhmm, im constantly organizing

#

having OCD and game developing is a hassle..

shrewd swift
#

i always try to make readable inspectors when needed

rocky canyon
#

niice..

#

is that NaughtyAttributes?

shrewd swift
#

yeah

#

and the dictionarry stuff is from rotary heart

#

allows me to serialize it

rocky canyon
#

pretty tidy inspector

shrewd swift
#

ty

#

(im a maniac)

rocky canyon
#

do u always make ur floats and integers into sliders like that

shrewd swift
#

no

#

rarely

#

but when i know the limits i usually do a big slider

icy junco
#

can anyone help me everytime i start game my player just starts floating away

languid spire
icy junco
languid spire
#

this is a code channel, so what do you think?

graceful citrus
#

what? everything looks fine what is this?

languid spire
wooden bay
#

Is there a way to reset Coroutines? In my code I start a coroutine and then part way through it I stop it in a different part of the script. Instead of stopping it I want to stop it and have it reset so the next time I call StartCoroutine it plays from the beginning.

languid spire
rich adder
#

there is no "Reset" Coroutine

wooden bay
#

I thought stoping a coroutine stops it where its at and then start plays it from there

#

Mb

languid spire
graceful citrus
rich adder
wooden bay
#

Ah

#

Maybe my issue is just a different part of my script then

rich adder
#

perhaps state your actual issue

#

instead of asking for X problem is prob Y

languid spire
#
Coroutine cor = StartCoroutine(MyMethod());
...
StopCoroutine(cor);

I suspect you are not stopping correctly

graceful citrus
#

oh shit

#

i just realised what it is

#

its not that but its similar

#

i was using gameobject.getcomponent for a component that didn't exist

#

🤦

pliant sleet
#

So for me my C# Intellicode extension is not working for programming in Unity , I have vs code and like it doesn't recommend other commands for me and doesn't show any information at all. I have been using vs code like that and it's quite stressing

eternal falconBOT
rich adder
#

Unity extension now exists also it installs new devkit

small helm
#

Google does not have any pages that include the exact phrase "does not have any associated build rules"

robust kelp
#

can you use onCollisionStay instead of raycasting for ground checking or is it a bad idea because i havent seen anyone do that

languid spire
rocky canyon
#

the raycast is better

robust kelp
#

im trying to find alternative to raycast because i cant figure out how to handle slopes

rich adder
eternal needle
robust kelp
#

i thought oncolissionstay would be more precise and i wouldnt have to adjust raycast lenght

eternal needle
languid spire
#

CollisionStay is never a good solution for ground check

swift crag
#

Freshly installed packages won't work properly until Unity manages to compile. That could be what's causing that

small helm
#

I decided to start from scratch with their default VR template. Things are working now, I'm not sure if it's because I also switched back to the last LTS build or something else but I'm not questioning it rn

#

Thanks for the help though fen

mossy panther
#

hey guys is it still worth it to learn unity after the decisions made about the pricing or whatever

#

i didnt read too much about it yet but decided to ask here to just understand it better

slender nymph
mossy panther
slender nymph
mossy panther
#

ok thanks

languid spire
# mossy panther ok thanks

At the end of the day, the chances of it ever affecting you are as close to zero as it is possible to get

rocky canyon
#

lol, i be wishing it'd affect me ;D

languid spire
rocky canyon
#

i'll be sure to still send ya a key when its gone viral and all the streamers are playing 😛

languid spire
solemn wraith
#

Hi, I have a question. I have seen some GTA style overhead camera transition (I hope you understand) and I was wondering if it may be possible to like have some sort of script to automate it; I think unreal has something like camera cutscene idk. Or do I just have to hardcode the animation. I was just curious, thanks

rocky canyon
#

epic! lol ill expect a biased review to boost my exposure

rocky canyon
#

^ this.. its just an animation and a camera

#

cinemachine would also be helpful..

#

has dollys, and tracking, and stuff

solemn wraith
rocky canyon
#

no, the timeline is a component/ a Graphical panel

solemn wraith
#

what?

#

Is it like a ui tool to make animations easier, is that what you are saying?

rocky canyon
#

its ^ like a video editor type thing

#

made for cutscenes and whotnot

solemn wraith
#

im trying to make something very quick you see

rocky canyon
#

Create your own Unity short film:
https://courses.obalfaqih.com/courses/unity-filmmaking-101
Animation Track | Getting Started with Timeline (Unity)
Need help? Book a consultation session now:
https://store.obalfaqih.com/products/unity-consultation-session
This is the second tutorial about Timeline, and it's about the Animation Track.
We'll go t...

▶ Play video
rocky canyon
#

with cinemachine u can just toggle different camera's and it'll automatically transition between them

solemn wraith
rocky canyon
#

could make a cinemachine camera with its own animation.. and just toggle the main camera off and the new camera.. it'll automatically transition to that camera.. and then could be animated.. u could swap back to the main camera when its finished

polar acorn
rocky canyon
#

can then just disable ur movement script stuff until u go back to it

shell herald
#

if i want to use a Tilemap Renderer component in a script, how do i do that? do i need to use additional stuff except the System.Collections, System.Collections.Generic and UnityEngine?

or do i simply use it like a Sprite renderer instead?

rocky canyon
#

Tilemap stuff should be inside the default UnityEngine;

solemn wraith
#

huh i think for me just making something really simple like just a simple coroutine in my camera controller with some lerps should do the trick actually probably i guess. thanks though! I'll definetily look into that

rocky canyon
#
  • System.Collections is usually used for Coroutines
  • System.Collections.Generic is usually used for <Lists>
languid spire
#

Tilemaps is in UnityEngine.Tilemaps namespace

slender nymph
wraith mango
#

Assets\Scripts\Player\PlayerController.cs(81,27): error CS1061: 'TypeWrite' does not contain a definition for 'last_text' and no accessible extension method 'last_text' accepting a first argument of type 'TypeWrite' could be found (are you missing a using directive or an assembly reference?)

eternal falconBOT
slender nymph
eternal falconBOT
rocky canyon
# solemn wraith huh i think for me just making something really simple like just a simple corout...

It really is super simple to use cinemachine. It actually uses the same camera.
A cinemachine camera is just basically like a placeholder for the camera..
Its just 1 component and you can set the priorities of the camera..
You can disable and enable camera's and it automatically just works.. or you can change the priorities and the camera will
go to the cinemachine camera with the highest priority..

wraith mango
#

i'm trying to access the variable

#

inside of typewrite

polar acorn
polar acorn
wraith mango
#

be prepared for a mess

polar acorn
#

Well, before we gett too far into the weeds: Have you saved

honest haven
#
        {
            FreeLook = GameObject.FindGameObjectWithTag("Free Look");

            if (FreeLook)
            {
                FreeLook.SetActive(false);
            }

            player = GameObject.FindGameObjectWithTag("Player");

            if (player)
            {
                player.SetActive(false);
            }
        }``` is this the best way to pause stuff?
honest haven
#

ignore the player one. the free look is cinemachine

wraith mango
#

thank you 🤣

polar acorn
#
  1. You should not be using Finds like this, you should cache those references once
  2. Disabling an object is a bad way to pause it, anything that references it still runs, it'll run any OnEnable/OnDisable logic, and any non-Unity methods will still be working as normal. The best way to pause something is to have some sort of singleton "PauseManager" object that anything that's pausable can read from and handle itself being paused in its own way
wraith mango
#

quick question

#

is there a way to have a sprite inside of a TMP text object

like "Do X for 10 🪙"

#

the coin being the sprite of a coin

rocky canyon
#

yup, a singleton to pause is a good call

honest haven
polar acorn
#

get the reference once and reuse it

slender nymph
rocky canyon
#

player = GameObject.FindGameObjectWithTag("Player");

the player isnt gonna change probably.. u can cache the player as soon as the script first runs..
then just call that reference any other time you need it..

player.DoSomething()

rocky canyon
#

i was thinking that it could just be a simple static class.. as thats all it does.. cs void Update() { if(Input.GetKeyDown(KeyCode.Space)) { gameIsPaused = !gameIsPaused; PauseGame(); } } as this is all it does

honest haven
#

When you say cache this is where i get lost. are you saying get cache in the player script becuase i have access to it. And not on a Game menu script using the find.

rocky canyon
#

no hes saying dont get the same reference that it'll always be every single time you pause the game

polar acorn
rocky canyon
#
private void Awake()
{
    freeLook = GameObject.FindGameObjectWithTag("Free Look");
    player = GameObject.FindGameObjectWithTag("Player");
}

private void Pause()
{
    if (freeLook)
    {
        freeLook.SetActive(false);
    }

    if (player)
    {
        player.SetActive(false);
    }
}```
slender nymph
rocky canyon
#

like why would you ever need to grab the gameobjects other than once?

#

even if the position has changed.. the gameobject has not..

#

player.transform.position would still be updated to the new position of that guy.. when that function asks for it

honest haven
#

oh i see. sorry i was reading this as dont ever use find game object

#

sorry guys

#

peeny dropped

#

many thanks

rocky canyon
#

you shouldn't unless u need to

#

find has to go thru the entire project

#

or the heirarchy atleast

honest haven
#

yes. thanks for your help.

#

one more thing that just popped int omy head. if this script was dont destroy on load and the player was. and im using on awake to find the object. Would awake be called again. and would i have to change script order to make sure the player Instantiated game object is being loaded first?

summer stump
#

It is called one time in the objects life

honest haven
#

So would that then lose a cached ref to the player?

summer stump
honest haven
#

player is never in any of my scenes he is being cloned

summer stump
#

I dunno what this script is, but maybe the Player could reference it and register themselves in Start?

#

Oh, like a PauseManager?

honest haven
#
    {
        // Check if player, camera, and Cinemachine already exist in the scene
        if (GameObject.FindGameObjectWithTag("Player") == null)
        {
            Instantiate(playerPrefab);
        }
        
        if (GameObject.FindGameObjectWithTag("FreeLook") == null)
        {
            Instantiate(CinemachineFreeLook);
        }
        
        // Ensure that this GameObject persists across scene changes
        DontDestroyOnLoad(gameObject);
    }```
summer stump
#

I would consider a static accessor

honest haven
#

this is my ddol

modest dust
summer stump
#

To be clear, you are wanting to switch scenes and do this check then?

honest haven
summer stump
#

Not sure what a singleton is supposed to do with what they said?
Did you mean to respond to me saying static accessor?
Otherwise, no, caesar did not mean make it a singleton

native seal
#

so I have an inventory and on each inventory slot i have a script that will send an event when an item is dropped on it (to signal to modify the actual inventory along with the ui) How can I get a reference to that event on my scriptable object inventory which holds the logic?

#

like what is the best way to do it

honest haven
#

i was replying to casar then,. I was just asking if it ran awake again but you answered my question. thanks

modest dust
#

I didn't read everything but if you basically want to re-spawn the player on scene change then use OnEnable()

#

If I remember correctly DDOLs get disabled and re-enabled on scene change

wild dagger
#

for some reason it can't move beyond this point when I press D?? I have no idea why

wintry quarry
rich egret
#

yo, i need code for damage popup text

modest dust
#

Provide more detials

wild dagger
#

Yh Im just taking ss's one sec

rich egret
north kiln
polar acorn
rich egret
blazing prairie
#

Is it ok to nest actions?

rich egret
wild dagger
#

I've disabled everything new that I added before it was broken

#

And in the actual scene its genuinely just tiles, haven't added any fancy effects to them or anything

slender nymph
round scaffold
#

yo ive always wanted to try and make this but im not sure the name of it, basically my character keeps bumping just below the edge of a platforms box collider and i want them to just get on top of that since they would have barely missed the edge is there like a name to this mechanic that i could look up or some kind of way to make it

#

ive heard of edge bumping but that doesnt seem to lead to anywhere

wild dagger
#

@modest dust @wintry quarry nvm I think I figured it out

#

do either of y'all know how to make the camera stop defaulting to the new camera that I've added?

#

I just want it to stick to the main

native seal
#

does anyone have a good source to learn about an event system?

eternal needle
abstract finch
#

Is there a way that I could FindObjectOfType and output the variable all in one if statement? It would be similar to TryGetComponent out var

honest haven
#

So i encounted a problem because my camera and player are being instatiated on awake in another script when i use private void Awake() { freeLookCamera = GameObject.FindGameObjectWithTag("FreeLook").GetComponent<CinemachineFreeLook>(); player = GameObject.FindGameObjectWithTag("Player"); } in another script i get NullReferenceException. if i put it inside start it works. Will this be safe in start. all the script does or is going to do is bring up a save menu.

ivory bobcat
short hazel
abstract finch
honest haven
#

you wouldnt recommend using Script Execution Order and make my DDOL come before my GameMenu script?

short hazel
ivory bobcat
buoyant knot
#

i use custom script execution order for just a couple of things that I know must go before/after everything else

wintry quarry
#

I recommend using Cinemachine instead of multiple Unity cameras if you just want multiple camera angles

wild dagger
#

Ok thanks I'll look into it

open sierra
#

is it possible to code an object to go in a patrol way and if it sees a player, it runs towards it and when the player is off the object's tracking system, it goes back to normal patrol mode?

wild dagger
#

Im only using 2 cameras one for battle and onefor free roam

open sierra
#

if so, what function would I need to use?

wintry quarry
wild dagger
#

luckily I fixed my issue by going so far back that it stopped and carefully adding what I wanted to add

wintry quarry
open sierra
#

I see

#

thank you

wraith mango
#

so i have a type writer effect, and I want to be able to skip specific keywords that won't be typed letter by letter, but I don't know how to go about this

https://hastebin.com/share/wezacesufi.csharp

#

specifically because the sprite won't show up until it is done typing

polar acorn
#

Assuming it's just those rich text tags you want to be parsing like that

wraith mango
#

yea that probably will be my only use case, thanks i will try doing that

limber narwhal
#

hi, I was wondering what do I have to google to understand how to use these static animation images that came with a free game kit i downloaded

#

do i have to turn them into a sprite sheet?

slender nymph
#

this is a code channel. but if it did not come with animated prefabs or animation clips or anything like that then yes, you'll need to set up the animation(s) manually yourself

limber narwhal
#

ah okay, sorry. i wasn't sure if it was done through code (like looping thru the images) or not.. since the images are already there do i just skip to this part in the unity tutorial?

short hazel
limber narwhal
vast vessel
swift crag
#

If you want to change how the door is oriented with a rotation of zero, parent it to an empty object and rotate the parent to compensate.

vast vessel
#

so do i just replace every transform.rot with transform.localEulerAngles?

swift crag
#

this may differ from the world rotation of the door if it's parented to something

#

but yes, if you use localEulerAngles, you'll (probably) see the same value in the inspector

#

you can still get different numbers out, since those Euler angles will be turned into a Quaternion, and then turned back into Euler angles to display in the inspector

north kiln
modern plank
#

Hi ive got two cams one on a render texture and one showing the screen how canimakethe UI panel show only on the one in the render texture

wraith mango
# polar acorn You could try checking the character before printing it, and if it's `<`, keep l...

i got it working, but do you know if this method could bring any problems or if there are more efficient ways of doing it

        for(int i = 0;  i < writer.Length; i++)
        {
            if(writer[i].ToString() == "<")
            {
                Debug.Log("Detected"); 
                for(int d = i; writer[d].ToString() != ">"; d++)
                {
                    caught_text += writer[d]; 
                    i = d + 2; 
                }
                tmpProText.text += caught_text += ">"; 
            }
            
            tmpProText.text += writer[i]; 
            yield return new WaitForSeconds(timeBtwChars);
        }```
quasi rose
#

but 99% time prob worth worrying more about like polys, texture, lighting, etc.

wraith mango
#

caught text would only be +='d when it catches a sprite in the text

short hazel
#

Also prefer comparisons to character literals, instead of converting them to strings

if (writer[i].ToString() == "<") // meh
if (writer[i] == '<') // better - notice single quotes to make a character literal
supple citrus
#

Christ I'm so bad at references objects

wraith mango
supple citrus
#

what do i put hereeee 😭

rocky canyon
#

should let ya know if it'll be sufficient for ya

wraith mango
rocky canyon
#

thanks, after i got the text writer working it was easy enough to add a panel, and just pass the string to the writer

wraith mango
#

or better question

#

is "Sun" an object or script

supple citrus
#

both which is stupid but I want to reference the object so I can get its position

wraith mango
supple citrus
#

Ye i had that until 2 seconds ago because i thought i finally figured it out :v

rocky canyon
#

u put the sun gameobject in there..

#

u can just call newPosition = Sun.transfrom.position;

#

not sure why ud want to grab the sun component each time ur trying to build that vector

supple citrus
rocky canyon
#

yea, but ur referencing a class called Sun

#

so that object must have a Sun.cs component on it

supple citrus
#

it does

rocky canyon
#

otherwise id just use a gameobject reference..
public GameObject theSun;

#

yea, then u can just slot ur sun gameobject in there.. and in the script calling Sun.transform.position will get the transform of the gameobject.. that has the Sun

#

(the one u referenced in teh inspector)

supple citrus
#

But it comes up with type mismatch

rocky canyon
#

b/c u didnt add the transform

muted wadi
#

quick question, what would adding parentheses in a line like this do?
rb.AddForce(0, knockbackUp, (playerOpposite.y) * knockbackForward, ForceMode.Impulse);

rocky canyon
supple citrus
#

When i try to drag the object into the reference part, the box says type mismatch

rocky canyon
#

parenthesis get calculed first..

#

then the math is finished

muted wadi
#

thank you

rocky canyon
#

a + b + c is not the same as (a + b) + c

muted wadi
#

needed to make sure

rocky canyon
#

is sun on the SAME gameobject..

supple citrus
rocky canyon
#

or a child of that gameobject?

quasi rose
#

that was smooth

rocky canyon
#

when (in rome) u have the tools at ur disposal..

#

not true

polar acorn
rocky canyon
#

dont make the name the same as the class

#

😅

polar acorn
#

Oh, wait, that was quite a scroll down I didn't do

rocky canyon
#

change the name and u'll probably be fine

muted wadi
#

im struggling to figure out a calculation that can get the opposite direction of another object's y rotation. For example, im trying to make the enemy that gets hit by the player's sword attack be knocked backwards based on the player's y rotation, but for some reason it gets knocked back the same direction regardless of player rotation. Any ideas?

rocky canyon
#

if u have a rotation u can just add 180 degree's to it and that'll be the opposite rotation

muted wadi
#

oh thats a much better idea than what i had

rocky canyon
#

or if u have a direction u can just negate it -direction

#

and that'd be the opposite way

muted wadi
slender nymph
#

why not just use the player's transform.forward and optionally project it on a plane represented by the ground's normal

polar acorn
muted wadi
#
playerOpposite.Normalize();```
this is what i tried just now but i realise it wouldn't work
rocky canyon
#

welp, the 180 degree turn is always a win

muted wadi
rocky canyon
#

couldnt u just use the players facing direction?

#

and just multiply it by a force

polar acorn
muted wadi
#

yeah it made sense in my head

muted wadi
slender nymph
# muted wadi tried that too

show that attempt because using the player's forward is better than manually adding to its rotation and is already a direction

rocky canyon
#

yea im thinking both of those solutions would be adequate

#

probably just some misplaced mathmatics

rocky canyon
#

player.transform.forward * force

#

ur just using a y coord.. thats not really enough

muted wadi
#

oh wait im stupid

rocky canyon
#

if ur facing forward its technically a rotation of 0

#

0 * anything would make it a non-existent force

muted wadi
#

when the player approaches the enemy

muted wadi
#

idk man im dumb

rocky canyon
#

lol, no worries, rotations and quaternions are always a bit of a challenge for beginners

muted wadi
#

let me try the forward thing

#

idk why i didn't do that from the start

rocky canyon
#

overthinking it sounds like

muted wadi
#

the usual suspect

cobalt solstice
#

Is there a way I can get a variable from one scene and use it in another one? If anyone can explain or link a good video to me?

muted wadi
cobalt solstice
#

Just tryna get a timer to save the final time and display it on a credit screen 😅

rich adder
cobalt solstice
#

Yeee I'm just tryna do a game for my A-level project, whilst this bit doesn't qualify as complex enough I'm trying to eventually save those times in reference to a login of sorts . So I'm just trying to work my way up 😂

rich adder
#

UnityCloudSave for example lets you save similiarly . All it is Key-Value save

cobalt solstice
rocky canyon
#

super simple

cobalt solstice
#

Damn, outputting the data as a graph? Would that be able to make it more complex

rich adder
#

not really

rocky canyon
#

that'd be scripting that calculates and draws after u retrieve the data

#

the playerprefs save and load would still be the exact same

cobalt solstice
#

I'm just tryna get some complexity in the project 😅

rocky canyon
#

well, why not have it track ur new time vs the last time u tried..

#

give a breakdown afterwards telling the player if they did better or worse

cobalt solstice
#

Ohhh that's what I meant by graphing

#

Like over time it saves their attempts and compares them

rocky canyon
#

that might be too complex for player prefs

#

ud probably want to serialize a list or something to track attempts.. and have it dynamic to be able to register a single attempt or as many as the player plays

cobalt solstice
#

Ahhh alr

rocky canyon
#

but then again idk.. playerprefs is supposed to be short and sweet.. saving strings, ints, simple stuff

rich adder
#

technically you can put any json data in PlayerPres, even list

#

but 1MB limit

rocky canyon
#

then whats the point of the playerprefs part?

rich adder
#

consistent location? 1 method to save to file

rocky canyon
#

i just rather use json at that point

#

ahh ok

rich adder
#

you can still use json into a string playerprefs is what I meant

rocky canyon
#

json wasnt that hard to set up imo..

#

and well worth it to have json vs playerprefs

rich adder
#

json is just a string formatting

cobalt solstice
# rich adder but 1MB limit

I mean, idk how much it'll end up taking storage wise over time but in my write-up for the problem and solution this is a local save so it'd only be one computer

rocky canyon
#

just serialization i guess?

rich adder
rocky canyon
#

ahh ok. lol. i used "data.spawnsave"

#

having my own filename extension was pretty cool to me lol

rich adder
#

ah yeah Ik what you mean

#

when you saving anything that is serialization itself

rocky canyon
#

ya, basically i just wrote out structs for everything..

rich adder
#

so even doing JsonUtility and then saving that into PlayerPref.SetString is serializing
its just limited to string size in PlayerPrefs

rocky canyon
#

json'd those into a notepad file disguised as some cool proprietary save type

#

BUT, wasn't very secure

rich adder
#

keeps away commons 😄

#

at least

timber tide
#
switch (Order)
{
    case RotationOrder.XYZ:
        transform.rotation *= Quaternion.AngleAxis(LookRotation.x * Time.deltaTime, Vector3.right) *
                              Quaternion.AngleAxis(LookRotation.y * Time.deltaTime, Vector3.up) *
                              Quaternion.AngleAxis(LookRotation.z * Time.deltaTime, Vector3.forward);
        break;
    case RotationOrder.XZY:
        transform.rotation *= Quaternion.AngleAxis(LookRotation.x * Time.deltaTime, Vector3.right) *
                              Quaternion.AngleAxis(LookRotation.z * Time.deltaTime, Vector3.forward) *
                              Quaternion.AngleAxis(LookRotation.y * Time.deltaTime, Vector3.up);
    case RotationOrder.YXZ:
    case RotationOrder.YZX:
    case RotationOrder.ZXY:
    case RotationOrder.ZYX:
        break;
}```
So I'm just testing rotation orderings with AngleAxis and it seems like the ordering is showing zero impact to the rotations or am I missing out on something here
rocky canyon
#

and wasn't really moddable either.. as it was just settings and.. level number

#

i guess u could skip to the end like that.. but thats kinda lame

timber tide
#

What's the typical FPS rotational order?

rocky canyon
#

whats going on in this thing?

#

well, z rotation is really never used in FPS

timber tide
#

true

rocky canyon
#

unless u count those leaning mechanics

rich adder
timber tide
#

quaternions have ordering which is why I'm doing this but I'm not seeing the differences on these specific cases

rocky canyon
#

umm.. i never done it like this so i cant say.. usually i rotate the player (capsule shape) on its Y axis.. and then the camera is parented beneath.. and it would rotate locally on its X axis..

cobalt solstice
#

Also another thing I was meant to ask of less importance, how do you make it so that the text on buttons is less blurry (idk if that's a me issue but it always seems to be more jagged in the game)

rocky canyon
rich adder
rocky canyon
#

but its crazy to see in a switch like that.. idk man lol i just aint never seen it hehe

timber tide
#

to remove my shitty euler's gimbal locking

#

test script

rich adder
#

ohh dang I wish I knew rotations that well enough

timber tide
#

at y 90 my camera was flicking around

#

with euler

#

I guess fps games don't let you do 90 anyway but still

rich adder
#

i normally also dont rotate camera for fps(only X), just the char's Y

timber tide
#

makes sense. Not exactly doing this for a fps but the targeting still applies similarly

#

need the x-tilting and stuff

rocky canyon
#

ahh, not sure, how does LookAt() do it?

timber tide
#

magic

cobalt solstice
timber tide
#
public void LookAt(Transform target, Vector3 worldUp = Vector3.up); ```
Yeah, I'm not sure but since it's not specific to an axis I guess it'll use a combination of axis by refering the world up direction?
rich adder
cobalt solstice
north kiln
#

LookAt would just be transform.rotation = Quaternion.LookRotation(target.position - transform.position, worldUp);

#

or something similar

amber spruce
#

anyone know a good tutorial or smth on how to make a good floating enemy boss ai

timber tide
#

even though quaternion multiplication is not commutative, it seems like multiplying by each axis doesn't seem to have affect on the ordering. Atleast through the AngleAxis method here.

#

now watch me be wrong and it'll bite me in the butt later on

#

but then there's these operations which do have an impact on the ordering:

Quaternion rotatedDirection =  Quaternion.LookRotation(direction) * rotation;```
north kiln
#

Rotating by a orientation made with LookRotation is so bizarre lol

north kiln
rugged fern
#

so when the guy slashes forwards with his sword in hand i want the shield box to cause it to not hit the capsule but when i cause it to play the animation it doesnt get effected is there a way i can fix that

rich adder
#

depends how you're currently detecting collision from sword/hand

teal viper
rugged fern
#

technically animation and collision i want collision to be the reason it cant hit it

teal viper
#

That's gonna be difficult to implement.

rich adder
#

You need IK

rugged fern
#

but if i cant i just thought about it and i could just do a trigger that un plays the attack animation

#

nvm i think im just doing to much tbf

teal viper
timber tide
timber tide
# north kiln https://hatebin.com/wpbfhbbgtq

ok, so if I were to pick a ordering and add angles one by one it seems to be consistent to all rotational orderings, but if I were to update two angles at once then there seems to be some ordering relevance.

north kiln
#

Not sure what you mean by one by one

timber tide
#

start at an identity and add angles to the x, then the y and let it rotate

#

it'll always end up in the same rotation no matter the ordering

north kiln
#

That's what my code is doing, no? And it's different depending on the order

timber tide
#

right, was this based on my code up there?

north kiln
#

Yes, but I removed the constant rotation stuff, which just confused matters

timber tide
#

rather the tilting on the x stays consistent throughout the y rotation

#

doesn't seem to have problems with x at angle values of 90 either which is what I was having with eulers

north kiln
#

I am fairly sure that your axes are reversed btw, and that when you say XYZ you're actually performing ZYX

#

The way I think about quaternion multiplication is A * B, A "rotates" B

#

where B is the original orientation and A is the rotation that's happening to it

timber tide
#

hmm, alright. I'll be looking into it more since I'm changing every single euler method I've made, haha

#

thanks

timber tide
#

such that we'd consider this as the XY rotation

transform.rotation *= Quaternion.AngleAxis(LookRotation.y * Time.deltaTime, Vector3.up) *
                      Quaternion.AngleAxis(LookRotation.x * Time.deltaTime, Vector3.right)```
north kiln
#

Yes, but this "rotating by a compound axis" is a really hard thing to comprehend and I'm not sure why you're doing it

timber tide
#

As opposed to using any other rotational method?

north kiln
#

transform.rotation *= <- confusing
transform.rotation = easy to understand

timber tide
#

oh, alright yeah

muted wadi
#

does anyone know why when using transform.LookAt on an empty with textmeshpro text, the text is backwards?

north kiln
#

because what on earth is C = C * A * B
It's like... B, rotated by A, rotated by C, which is also constantly moving? It's confusing AF

timber tide
#

I believe that's like that because I was animating it with degrees per second

#

otherwise I'd just set it I believe

north kiln
muted wadi
#

is there a way to change that?

north kiln
#

No, don't use LookAt, use Quaternion.LookRotation with the opposite direction

muted wadi
#

ah thats smart

#

i didn't know there was a method like that

bleak trout
#

wsg yall 😁 im fresh new to unity (literally just finished downloading the editor)

#

i want to get into game dev stuff

timber tide
#

nice, brush up on some of your c# skills before delving too deep

bleak trout
#

c#?

timber tide
#

yep, what you'll be coding with

bleak trout
#

aight

timber tide
#
bleak trout
#

im assuming i click game dev w/ unity right?

timber tide
#

The unity looking one, yeah. The other is c++ for unreal and other c++ game engines

bleak trout
#

do i need any of these optional things? (alrdy have unityhub

summer stump
eternal falconBOT
livid tundra
#

What's the most idiot-proof way to draw a circle (in a 2D scene) at a Transform position via code? I want to draw it at a specific frame in an Update() loop

north kiln
north kiln
#

Otherwise you'll have to calculate a circle and use Debug.DrawLine

#

Which isn't hard if you know what you're doing, but it's not idiot-proof

#

Alternatively, you spawn an actual object in the scene, and take care to only do it in the editor

livid tundra
timber tide
#

Handles has draw circle I think

livid tundra
#

looks like that just draws a line segment

timber tide
#

or maybe that's just wireframe

livid tundra
#

it just has 3D objects

north kiln
livid tundra
#

I'm just debugging

north kiln
#

It's a "3d object" in the same sense that so is anything in Unity if you rotate it

#

I always forget whether you can use Handles anywhere reasonable

livid tundra
#

...which it won't be, but I just figured Unity would have a circle somewhere and I was annoyed how long it was taking me to figure that out with Google

#

Took a few wrong turns

bleak trout
#

guys should i start a coding club at my hs? like a game dev club or smth

frosty hound
#

Go ahead?

timber tide
#

sure why not

livid tundra
#

NO!

#

(I mean, "yes" 🙂 )

muted wadi
#

is it possible to use the fill method for a circular healthbar like this?

#

the sprite itself is square so it wouldn't work if i tried to fill it from left to right

#

but is there a way to actually do this using a sprite that is a circle?

timber tide
#

need to use masks probably

muted wadi
#

what does that involve

timber tide
#

a sprite mask

#

;)

muted wadi
#

how didn't i think of that

#

is that the best way?

timber tide
#

uh, otherwise animate UVs of a quad? idk

muted wadi
#

because im on the documentation and was wondering if it would be possible to configure each slice of the drawing manually

livid tundra
#

I opted for Handles fyi

#

just since it's a quick-and-dirty use case

muted wadi
livid tundra
#

Handles.DrawWireArc(transform.position, new Vector3(0,0,1), Vector3.up, 360, 10);

livid tundra
slender nymph
muted wadi
livid tundra
#

Can anyone help me understand how isBouncing is reading as true even though I only set it once and I set it to false?

north kiln
#

!code

eternal falconBOT
north kiln
#

Also, where do you set it to false? It doesn't look like you change it outside of the initializer, which is only the default, before being overridden by the value serialized in the inspector

livid tundra
#

It's initialized to false

#

it's not serialized to true

#

it's not serialized (not literally, anyway. I verified that the prefab's value for this is false in the inspector)

north kiln
#

Then how are you testing that it's true?

#

Is it that Debug.Log("Bouncing"); line?

livid tundra
livid tundra
north kiln
#

Then search the scene t:Sword_Skill_Controller and find the instance that's true

livid tundra
#

I even fed it the boolean

#

it says true right now

#

I'm looking at my Console

livid tundra
north kiln
#

No, you search the scene in the hierarchy window

livid tundra
#

ok let me check

#

yeah, it instantiates a sword with the value being "true"!

#

why tho

#

that is so unexpected

#

what's the point of initial values then

#

I guess I'll try setting it to false in Awake()

north kiln
#

Presumably it's being set or animated, or you're doing something else I can't tell

livid tundra
frosty hound
#

The point of initial values is to give it an initial value. It of course isn't just flipping it without some code telling it to, somewhere.

livid tundra
#

that variable doesn't exist on another object and it isn't used in other scripts

frosty hound
#

Do a reference search in code

livid tundra
#

I checked to make sure

livid tundra
#

however

charred spoke
#

Someone has to be setting it to true

livid tundra
#

setting it in Awake() fixes the problem

#

...meaning it's not being forced true after I set it in Awake

#

something is happening when it is instantiated

#

the gameObject it makes

#

this controller thing

livid tundra
#

or rather

#

if it was, it would have been true after setting it false in Awake(), right?

#

setting it false in Awake() "solved" the problem

north kiln
#

Can you select the prefab from the reference that's spawning it without opening it?

livid tundra
#

but it isn't clear whey there was ever a problem

charred spoke
#

Depends on who sets it when

livid tundra
#

oh...that's weird

#

so...I have a "Skill Manager" for these swords

#

and the value is true

#

but the sword prefab's value is (correctly) false

#

so it was all about serialization after all

#

it was exposed in two places and I didn't realize

#

thank you @north kiln

#

and @charred spoke

#

@frosty hound

north kiln
#

Do you have two prefabs, or are referencing an instance somewhere else or something? I don't really understand why there would be multiple

charred spoke
#

His prefab is under another prefab and thus isBouncing being true counts as an override

charred spoke
livid tundra
#

So this variable belongs to a script called "Sword_Skill_Controller" and there is an empty in the scene that has it. The controller's job is ultimately to decide what skills the Sword object has and to handle their logic.

When the game runs, it give the sword prefab a skill. The value of isBouncing for the prefab in the Project view is different from the value when I open it up and look at it.

livid tundra
#

Or I copied it wrong 👀

livid tundra
#

I take it back, I still don't see the "override" button on the sword object so that object is correctly updating with my intentions

livid tundra
charred spoke
abstract finch
#

Why cant I modify structs in a foreach loop?

teal viper
#

Because structs are value types

slender nymph
#

because the local variable created as part of the foreach loop is a copy of the object stored in the array

abstract finch
#

ahh ok

#

that makes sense

deft siren
#

how can i make it so everytime i press a button the activation state changes?

#

i want so everytime i press E it disables/enables an audiosource

tacit estuary
deft siren
#

ye

tacit estuary
# deft siren ye
public bool toggle;

void Update()
{
    if(Input.GetKeyDown(KeyCode.E))
    {
        toggle = !toggle;
        
        audio.enabled = toggle;
    }
    
}```
deft siren
#

really tought there would be a function for it :/

#

but thanks a lot!!!

night mural
#

how about

audio.enabled = !audio.enabled
tacit estuary
deft siren
#

if it doesnt bother u guys, mind explaining what the ! does

#

(im REALLY new on code)

slender nymph
deft siren
#

(besides obvious resons) why u say that

night mural
deft siren
#

makes sense, thanks again!!

tacit estuary
slender nymph
deft siren
#

yeah that is the most logical course

#

but for this game im really going for the "do i want to expert on this?" so kind of not so worried about failing

#

its kind of a 'test'

night mural
#

are we passing your test? 😄

deft siren
#

the community is being the best part so far <333

#

everyone is so polite to each other

#

(and REALLY patient)

deft siren
#

mb

#

that'd work right?

slender nymph
#

no

deft siren
#

ah

#

is it only for bools

slender nymph
#

well yes. but also IsActive isn't a thing

deft siren
#

*SetActive ma fault

#

thanks again all of u!!

#

best of luck

slender nymph
# deft siren *SetActive ma fault

SetActive is a method so you cannot assign to it. you can pass it a bool though and you can use the ! operator said the bool if you want to use the opposite of its value

deft siren
#

damm, smart

slender nymph
#

literally just basic concepts

deft siren
#

okey :D

#

ok so, this is supossed to tp the monster randomly when he gets in the triger, not working for some reason

slender nymph
livid tundra
#

This function is supposed to contain logic for a sword stuck in something, whether that be an enemy or anything else. The "if()" statement in the middle prevents the sword from staying stuck in an enemy when there are more enemies left to hit.

#
private void StuckInto(Collider2D collision)
    {
        canRotate = false;
        cCollider.enabled = false;
        
        rb.isKinematic = true;
        rb.constraints = RigidbodyConstraints2D.FreezeAll;

        if (isBouncing && enemyTargets.Count > 0) // allows sword to stop spinning and stick in ground if close to a target during bounce skill
            return;

        //"If not isBouncing or we have no more enemies to bounce to"
        anim.SetBool("SwordSpin", false);
        transform.parent = collision.transform;
    }

I would rather not interrupt the logic this way. Instead, I would rather remove this if() statement and put the last two lines in the inverse "if()" statement. I figured that DeMoran's Law would help me construct this, but I am having difficulty interpreting it.

#

(A ∩ B)' = A' ∪ B'

#

the inverse of ("isBouncing" and "more than 0 targets") is "not isBouncing" or "0 or fewer targets"

#

🤔

#

actually, maybe I do get it. Let me try again

#

that worked 🙂

#

I don't know why that didn't make sense to me a minute ago. It sounds perfectly logical now.

#

...and the code is more focused 😉

#

I am a LOGICAL MELON FARMER!

deft siren
#

i made a long time ago ok, didnt remember i hadnt put a colidor in it

sleek halo
#

I didn't even touch anything and somehow gave myself more errors. There's more in the yellow box regions. Can someone please help me?

#

Also

#

None of my things are showing up in inspector

#

I just......how?

charred spoke
#

You have two files named ClickerScript in the project

#

The error is pretty self explanatory

sleek halo
#

Is there an easy way to figure out where the second one is? Cause I've only made one script for this whole thing

charred spoke
#

Just search for the name in the project tab

#

You have either duplicated it or made a new script with that name

sleek halo
#

It duplicated

#

Found it

#

Thank you!

#

Still have errors, but a whole lot less lol

#

Any chance you could help me with this too please?

#

I, unfortunately, copied this from a youtube video and the "this" wasn't touched on and now I'm just lost

#

Also, I'm still not getting any of the things in inspector....

rich adder
sleek halo
#

Lmao this is the same kind of stuff that always screws me up with papyrus too 😂

charred spoke
# sleek halo Thank you!!!

I suggest you do a beginner c# course before continuing otherwise you are not going to have a fun time making a game

sleek halo
charred spoke
#

Confusing = and == isnt exactly screwing up. Its lack of basic knowledge that simple hinders progress

teal viper
open sierra
#

I'm about to learn coding using the unity official tutorial on the website, any parts I need to really pay attention to? And should I memorise the code lines or what each word means?

rich adder
timber tide
#

what is a scene
what is a gameobject
what is a monobehavior
what is a component
what is the difference between a plain c# script and a script inheriting from monobehavior

eternal needle
timber tide
#

additionally,
what is a constructor -> why can't you use a constructor when inheriting monobehavior
what is the alternative to using a constructor if we cannot use it
what is serialization
why do we set values from the editor to our object scripts (components) and what are the benefits

proud robin
#

Hi
how can i normalize speed of charactercontroller when going up and down ramps
they seem faster than walking on flat surfaces
my movement is controlled by root motion

supple needle
#

I have a question
So when i change a feature in visual studio and come back to the scene, there is a load time where it checks the backend, then i need to press the play button to look at another load time until i can test the feature to see its not working.

Im just curious, is there an easier way to do the process above? Like some debug mode or something

north kiln
#

Read all the documentation (especially the subpages) if you plan on using it

supple needle
#

Will do. thanks!

#

Wait one more question

#

Do most devs use this feature? Is this a conventional way of doing this?

north kiln
#

I cannot speak to most devs. I use it on every project, and advocate for its usage. But if you're using assets or have written code that hasn't catered for it you can experience bugs that will be confusing based on the incorrect state of static variables

#

it is significantly faster (almost instantaneous on small projects) to enter playmode, which is a massive productivity boost

supple needle
north kiln
#

Also, just general advice for debugging: use the debugger to do debugging. By adding breakpoints and tracepoints instead of logs you can avoid recompiling just to check logic or state

supple needle
#

Oh jeez, i need to read up on all this, thanks anyway!

north kiln
#

There's resources related to the debugger pinned to this channel 👍

queen adder
#

Is this code begginers or C# beginners?

livid tundra
proud robin
#

and then i just lerp the player angle to target angle
and play animation
the rest collision n stuff are handled by charactercontroller

livid tundra
#

Because you normalize the direction vector, the character travels at the same speed (prior to applying speed, I mean) regardless of whether they are on flat ground or a steep incline.

#

...and that probably looks weirdly fast to you

#

in fact, I just wrote some code to make my character climb steep slopes when they couldn't before

#

they are moving at the same speed up the slope as on flat ground

#

it looks a little fast, but it keeps the action moving and I don't mind it

#

Is the speed "increase" more serious than just this? Maybe something else is going on

proud robin
#

my character doesnt jump

livid tundra
proud robin
#

i checked velocity
flat = 5~6m/s
incline = 6~7m/s (depending on angle)
so yea it is faster

eternal needle
proud robin
# eternal needle show more of the code, like where you do the actual movement
void Update() {
        movement = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
        Vector3 direction = new Vector3(movement.x, 0, movement.y).normalized;

        if (direction.magnitude >= 0.06f) {
            AnimatorStateInfo currentState = animator.GetCurrentAnimatorStateInfo(0);
            float targetangle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cameraTransform.eulerAngles.y;
            if ((animator.IsInTransition(0) && animator.GetNextAnimatorStateInfo(0).IsName("run anim name")) || (!animator.IsInTransition(0) && currentState.IsName("run anim name"))) {
                float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetangle, ref turnSmoothVelocity, turnSmoothTime);
                transform.rotation = Quaternion.Euler(0f, angle, 0f);
            }
            mAnimator.SetBool("isRunning", true);
        } else {
            mAnimator.SetBool("isRunning", false);
        }
    }```

and the running bool just makes the animations play by the animator controller
and then anims' root motion moves the character
eternal needle
#

i assume you have a rigidbody which is keeping your player from going into walls and such

proud robin
#

just charactercontroller component

#

that should handle collisions?

eternal needle
#

yea the CC will handle depenetrations, but still i dont think you have any control over the speed here because its animation movement. The animation is trying to move just along a flat surface i assume, but the CC is also depenetrating and moving it up the slope at the same time

queen adder
#

Is this code begginers or C# beginners?

ivory bobcat
#

Unity beginner coding

queen adder
#

Right?

ivory bobcat
queen adder
#

Answer pls

ivory bobcat
#

If it's c# with Unity and relative to beginner concepts, this channel is fine.

#

If it's unrelated to Unity, it's not meant for this server.

verbal dome
#

There's also a !csharp server

eternal falconBOT
queen adder
verbal dome
queen adder
ivory bobcat
slender nymph
ivory bobcat
queen adder
ivory bobcat
ivory bobcat
slender nymph
queen adder
#

I got answer C# server

ivory bobcat
queen adder
#

Yes please understand what u are answering

#

That's all I needed, bye

#

Thx for the answer

ivory bobcat
# queen adder I got answer C# server

We're assuming you're attempting to ask unrelated questions to Unity by blurring the border between c# and coding - happens every once in a while where someone attempts to reason why asking non unity related questions should be allowed.

livid tundra
#

How can I set default parameter values for inherited parameters? 🤔

verbal dome
livid tundra
#

I'm putting default values in all my scripts because I don't trust [SerializeField] anymore

livid tundra
verbal dome
#

Ah with inherited parameters you mean inherited variables/members

livid tundra
#

yeah

verbal dome
#

I think you can only do that with a property, not with a field

queen adder
livid tundra
#

in my Entity class, I have

[Header("Knockback Info")]
[SerializeField] protected Vector2 knockbackDirection;
[SerializeField] protected float knockbackDuration;

and in my Player class (which inherits from Entity I...don't. I don't have these parameters. They are serialized, but I want...oh wait

ivory bobcat
livid tundra
#

yeah I can do this in Awake()

#

nvrmnd

ivory bobcat
#

Where Unity uses the first.

queen adder
#

Exactly

#

So bye

weary finch
#

bye

verbal dome
#

Yeah Awake works too

livid tundra
verbal dome
#

It serializes the 'backing field' of the property

#

Which is what holds the actual data

fringe plover
#

!code

eternal falconBOT
fringe plover
#

Sup, i have a question, i need to make RaycastHit2D ignore 2 layers, but idk how, i'm currently using this, is there any way to do that?

        int layerToIgnore = LayerMask.NameToLayer("NotGround");
        int layerToIgnore2 = LayerMask.NameToLayer("Player");
        int layerMask = ~(1 << layerToIgnore);
        RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down, checkDistance, layerMask);
        if (hit.collider != null) grounded = true;
        else grounded = false;
        // Debug.DrawRay(transform.position, Vector2.down * checkDistance, grounded ? Color.green : Color.red);
        // Debug.Log(Physics2D.Raycast(transform.position, Vector2.down, checkDistance, layerMask).collider.gameObject.name);
timber tide
#

layerToIgnore |= LayerMask.GetMask("Player");

#

I think that may work

#

oh wait what's nameToLayer again

fringe plover
#

Gets layermask with this name

slender nymph
#

NameToLayer returns the layer index, not a mask

fringe plover
#

ah yes

#

im not good at this..

slender nymph
#

you can just use LayerMask.GetMask, pass in the two layers you want to ignore then invert that. or create a LayerMask variable, serialize it, and assign it in the inspector instead of all this

fringe plover
#

thank you so much

shrewd swift
#

Im having an issue when reloading a scene (so I can start a new game)

from the console, it looks like I am calling a method inside myClass (inside another gameobject than my player), but since it destroyed (because I reloaded the scene) there is an error

can this be the issue ?

// inside PlayerController class
public static event Action PlayerStartPlaying;

//somewhere inside
PlayerStartPlaying();
// inside myClass
private void Awake()
    {
        PlayerController.PlayerStartPlaying += StartGeneration;
    }```
#

is there a way to "clear" the PlayerStartPlaying callback (is this the good word for this?)

slender nymph
#

you can assign null to it (from within the class that owns it)

shrewd swift
#

okay

shrewd swift
#

idk if this is the correct use

slender nymph
#

you can only assign null to it within the type that owns it. the whole point of decorating it with the event modifier is so that other objects cannot invoke it or modify it except for subscribing and unsubscribing

#

but if your intention is to just unsubscribe the one method from it, then yes -= is how you do it

shrewd swift
#

ah okay ty

#

well that wasnt the fix

#

nvm it did
ty box

maiden turret
#

Hi, i have a weird problem with my rotation. My Code is very simple, i want a gameobject to look away from another gameobject

Vector3 direction = new Vector3(unit.transform.position.x, 0, unit.transform.position.z) - new Vector3(MainPoint.transform.position.x, 0, MainPoint.transform.position.z);
Quaternion rotation = Quaternion.LookRotation(direction, Vector3.up);
unit.transform.rotation = rotation;

As you can see in the picture, the rotation is nearly right, but not exactly. What do i miss here? Thanks for any help

#

Oh the red line is a debug ray, which shows the correct vector3

jovial sandal
#

does some1 know how u play a partical after a given amount of time

fringe plover
#

trough script i guess lol

eternal needle
maiden turret
vernal bone
#

I have a question.
Is there a best way to access object's script, or GetComponent<>() is best i get?

eternal needle
eternal needle
vernal bone
honest haven
#

Could do with a little help debuggin please. in my current scene the main scene i have the player prefab in the scene all my animations work fine. but as soon as i delete him and load him with my Instantiate script one of my animation.. well my only Any state animation wont play and the player freezes. This only happens if i Instantiate him. I have 3 scripts attached. my state script. my player controller script and my DDOL script. https://gdl.space/cetupiziwu.cs

#

line 126 debug does get called if (Input.GetMouseButtonDown(1))
{
Debug.Log("Attcking");
playerState.ChangeState(PlayerState.State.Attacking);
}

#

but then freezes. in the animator the all the animations stop

#

again this only stops working when the attack is trying to play when my player objected is being Instantiated

nimble apex
#

im almost at the verge of braindead, i need to draft something out lol

#
if(A && B && C){
   bool = true;
}else{
   bool = false;
}

if(B && C){
   bool = true;
}else{
   bool = false;
}```
#

so A is unnecessary?

languid spire
#

correct

nimble apex
#

thx

gilded sinew
#

guys what is going on here. I have variable moveSpeed with which i want to adjust speed of capsule that i want to move around. But regardless of its value even if i lower it by 1000, capsule moves the same speed and very fast for my liking. how should i fix this

honest haven
#

is the var public and is it different on the game object. might be trying to over ride it in the script but game object is changing it

gilded sinew
#

yikes let me see

#

FML

#

ty bro

honest haven
#

no wories been there done that lol

gilded sinew
#

completely forgot that i set it in game object

#

i was pissed at chat gpt i tell it to fix code something is not working, i tried 5 different versions and all the same. now for obvious reason

weary finch
#

is there an optimization or profiler channel?

languid spire
honest haven
#

thanks

languid spire
#

also your singleton pattern should be in Awake not Start

honest haven
#

thanks ill change that. was thinking about ditching the singleton any

open python
#

has anyone tried his state machine https://www.youtube.com/watch?v=RQd44qSaqww&t=14s

Show your Support & Get Exclusive Benefits on Patreon (Including Access to this project's Source Files + Code) - https://www.patreon.com/sasquatchbgames
Join our Discord Community! - https://discord.com/invite/aHjTSBz3jH

In this Unity tutorial, We'll use, from the ground up, the State Machine programming pattern to setup some simple logic for o...

▶ Play video