#πŸ’»β”ƒcode-beginner

1 messages Β· Page 297 of 1

teal viper
#

Well, what's the type of enemyCategory?

magic pagoda
#

string, yeah thats the issue Im aware

#

hm.. is there a way I can make that script grab the value of the enemyType stat- actually wait Im not gonna need that

#

there we go!

#

thanks y'all, I rlly appriciate it ^^

ebon quartz
#

this aint even giving me debug logs

timber tide
#

which usually means the if statement is false

languid spire
kindred nest
#

there should be a setting on the AudioSource/AudioClip component attached like "play on enable" - look for that and make sure it's disabled

#

I catch myself forgetting to do that too everytime I play with sounds πŸ˜†

long jacinth
#

its because redgrid i made it a gameobject

#

what do i do

#

what function does this work on

timber tide
#

should post code
!code

eternal falconBOT
timber tide
#

your error is that RedGrid is a type of game object and it does not contain a method of SwapTile

#

so you're mixing up your types here

long jacinth
#

i tried to make it Tilemap

#

but it says mismatch

timber tide
#

ya need to post some code cause I am not playing a guessing game

long jacinth
#

ok

timber tide
#

seems fine, but perhaps you have another error somewhere here

kindred nest
#

so it might just call the function on the initial collision when the vase hits the table

#

a quick and probably slightly dumb solution would be to disable it for the first collision in the game, but I wonder if there is an easier solution for this

#

basically add a private firstCollision=true variable and add this statement to the onCollision function:

if(firstCollision){
firstCollision=false
return;
}
#

make sure it's before the sound-making functions though

#

feels dirty, but should do the job

long jacinth
#

but when i put in the gameobjects for the public variables it says type mismatch

summer shard
#

is there a way to "launch" player when clicking fast when using distance joint 2d?

private void Update() {
        if (Input.GetKeyDown(KeyCode.Mouse0)) {
            Vector2 screenPos = mainCamera.ScreenToWorldPoint(Input.mousePosition);
            Vector2 gunTipPos = gunTip.position;
            Vector2 direction = screenPos - gunTipPos;
            RaycastHit2D hit = Physics2D.Raycast(gunTip.position, direction, grapplerDistance, grappable);
            if (hit.collider) {
                lr.SetPosition(0, gunTip.position);
                lr.SetPosition(1, hit.point);
                distanceJoint.connectedAnchor = hit.point;
                // distanceJoint.distance = ((Vector2)gunTipPos - hit.point).magnitude * 0.9f;
                distanceJoint.enabled = true;
                lr.enabled = true;
            }
            else {
                lr.enabled = false;
                distanceJoint.enabled = false;
            }
        }

        if (Input.GetKey(KeyCode.Mouse0)) {
            lr.SetPosition(0, gunTip.position);
        }
        else {
            lr.enabled = false;
        }
        
        if (Input.GetKeyUp(KeyCode.Mouse0)) {
            lr.enabled = false;
            distanceJoint.enabled = false;
        }
    }
``` rn it's completely stopping when i unhold my left mouse button
long jacinth
#

wait i think i know

kindred nest
#

give it a shot, should be good to go if my assumptions are correct

long jacinth
young warren
#

most bugs are because of silly mistakes you make 🀷

long jacinth
#

i tried to put a gameobject in the scene to the public gameobject variable in the prefab

ocean dove
#

Its a bool

kindred nest
#

that can be whatever you want it to be, i just invented that to make it easy to understand what is it's purpose

#

oh shoot yep i forgot to put the type, should be private bool firstCollision=true

#

sorry!

ebon quartz
kindred nest
#

yup, basically:


private bool firstCollision=true;

void OnCollisionEnter(Collision col){
    if(firstCollision){
        firstCollision=false;
        return;
    }

        myAudioSource.PlayOneShot(mySound, 1.0f);
}

anywhere within the class {} brackets

languid spire
ebon quartz
languid spire
#

or !learn

eternal falconBOT
#

:teacher: Unity Learn β†—

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

kindred nest
#

yup, you'll get the hang of pretty quick once you know why certain functions are called and when, and then debugging becomes much easier, have fun!

ebon quartz
languid spire
# ebon quartz nope, in the tutorial the code was working

listen, the code will not run if it is not attached to a game object. So...
if in the tutorial the code is running then at some point it was attached to a game object. So...
watch the tutorial again and this time pay attention

ebon quartz
summer shard
#

is there a way to "launch" player when clicking fast when using distance joint 2d?

private void Update() {
        if (Input.GetKeyDown(KeyCode.Mouse0)) {
            Vector2 screenPos = mainCamera.ScreenToWorldPoint(Input.mousePosition);
            Vector2 gunTipPos = gunTip.position;
            Vector2 direction = screenPos - gunTipPos;
            RaycastHit2D hit = Physics2D.Raycast(gunTip.position, direction, grapplerDistance, grappable);
            if (hit.collider) {
                lr.SetPosition(0, gunTip.position);
                lr.SetPosition(1, hit.point);
                distanceJoint.connectedAnchor = hit.point;
                // distanceJoint.distance = ((Vector2)gunTipPos - hit.point).magnitude * 0.9f;
                distanceJoint.enabled = true;
                lr.enabled = true;
            }
            else {
                lr.enabled = false;
                distanceJoint.enabled = false;
            }
        }

        if (Input.GetKey(KeyCode.Mouse0)) {
            lr.SetPosition(0, gunTip.position);
        }
        else {
            lr.enabled = false;
        }
        
        if (Input.GetKeyUp(KeyCode.Mouse0)) {
            lr.enabled = false;
            distanceJoint.enabled = false;
        }
    }
``` rn it's completely stopping when i unhold my left mouse button
queen coral
#

follow codemonkey tutorial and this is what he has

#

but when i try that i get this error

summer shard
#

remove using Systems.Numerics from ur usings on top of the code

queen coral
#

ahh got it thank you, no idea how that go there

hexed terrace
#

VS autocomplete will add it

hidden current
#

im trying to debug something, does anyone know of a way to like record the last value of a variable before the code reaches a breakpoint? is that possible?

#

like i know if its in memory visual studio does that, but when its not in memory it doesnt. i want to like record it before the GC erases it. idk if that makes sense

fossil drum
hidden current
#

i have to google that, i suck at debugging lol

kindred nest
#

we all do, print() is the way brother!

hidden current
#

print is good, but i have alot of printing to do, thats the thing

fossil drum
#

Print is easier for smaller problems yeah, but if you have a big problem, stepping through the code and checking if your assumptions match what the debugger says is easier imho.

hidden current
#

the problem is, i have a bug that happens randomly. and its very rare too.

#

ive been at this for days now .-.

ebon quartz
#

whats wrong with my code?

hidden current
#

did u click and drag perseguir to the script in the unity editor?

languid spire
slender nymph
eternal falconBOT
lost anvil
#

is it necessary to use scriptable objects for a system that allows you to pickup/drop objects and putting them into an inventory etc

ebon quartz
hidden current
ebon quartz
#

another error i found is that i typed "postion" instead of position in my code LOL

hexed terrace
#

oh, I you shared a screenshot, it deffo isn't configured

hexed terrace
lost anvil
#

alright i just dont want to get into this inventory and then realise it wont work because of new items i need or whatever

hexed terrace
#

SO's become cumbersome if you start having A LOT of items/ etc. If you're going to end up with hundreds, then another solution would be better.. if you're gonna have a few of each time, SO's are good

late bobcat
#

Hey guys i'm trying to understand how i should implement gravity change in my 3d game. I'd like the ball to stick to the left side by swapping gravity when the ball goes on the "black platform". I kinda achieved what i wanted but when gravity swaps the ball goes faster and it's kinda hard to control (you can also tell that by how fast the ball rotates)
What am i doing wrong? https://hatebin.com/cuvoqirjvz

slender nymph
#

you add force more than once per frame when gravity is swapped. also you really shouldn't be using AddForce in Update for continuous forces like that

#

physics should be performed in FixedUpdate to ensure it is consistent, because someone playing that with a higher framerate will end up applying more force than someone playing with a lower framerate

late bobcat
#

oh true

#

how do you suggest to edit the gravity part?

#

actually, i think fixedUpdate kinda fixed everything

hidden current
#

so i have this code, and i have an error in firstpair/lastpair. below it says its 2,5,0 and above it says its 2,1,0

is my variable getting written and changed for some reason? am i reading this correctly?

hexed terrace
#

above and below what?

hidden current
#

above meaning when it gets assigned initially, and below when im trying to read it

hexed terrace
#

Y changes because you add to it

hidden current
#

oh my lord

hexed terrace
#

πŸ™‚

ebon quartz
#

so basically in this script the sky needs to follow the camera, how do i fix this?

young warren
#

you have typed something wrongly. it's not your logic that's the problem

#

i'm assuming you're using Visual Studio

young warren
#

!ide

eternal falconBOT
ebon quartz
young warren
#

then click Vs code

ebon quartz
#

nah i aint understanding cause i did the same thing

hidden current
#

i thought there was some weird stuff going on with passing by reference, but that wasnt it. structs are pass by value. im getting closer >.>

thorn holly
ebon quartz
hexed terrace
#

!vscode

eternal falconBOT
#
Visual Studio Code guide

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

https://on.unity.com/vscode

hidden current
#

i think im going to package my project and see if anyone can fix my code, because i swear to god i feel like im poking at a bug in unity and i dont think i can solve this one

#

ill pass the torture onto you! πŸ˜„

wanton canyon
#

when I pick up a slime, I made it so it faces the player camera. but for some reason its body rotates around if you move your view around? any ideas?

waxen pond
#
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public float jumpForce = 10f;
    public float forwardSpeed = 5f;
    public float laneDistance = 3f; 
    public int currentLane = 1; 
    public float laneChangeSpeed = 5f;

    private Rigidbody rb;
    private bool isChangingLane = false;
    private int targetLane;

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

    void Update()
    {
        if (!isChangingLane && Input.GetButtonDown("Jump"))
        {
            Jump();
        }

        if (!isChangingLane && Input.GetKeyDown(KeyCode.LeftArrow))
        {
            SwitchLane(-1); 
        }
        else if (!isChangingLane && Input.GetKeyDown(KeyCode.RightArrow))
        {
            SwitchLane(1);
        }
    }

    void FixedUpdate()
    {
        if (isChangingLane)
        {
            float targetX = (targetLane - 1) * laneDistance;
            float newX = Mathf.MoveTowards(transform.position.x, targetX, laneChangeSpeed * Time.fixedDeltaTime);
            transform.position = new Vector3(newX, transform.position.y, transform.position.z);

     
            if (Mathf.Approximately(newX, targetX))
            {
                isChangingLane = false;
                currentLane = targetLane;
            }
        }
        else
        {
            rb.MovePosition(rb.position + Vector3.forward * forwardSpeed * Time.fixedDeltaTime);
        }
    }

    void Jump()
    {
        rb.velocity = new Vector3(rb.velocity.x, jumpForce, rb.velocity.z);
    }

    void SwitchLane(int direction)
    {
        targetLane = currentLane + direction;
        if (targetLane >= 0 && targetLane <= 2)
        {
            isChangingLane = true;
        }
    }
}
timber tide
#

pastebin large code

timber tide
waxen pond
young warren
eternal falconBOT
timber tide
# wanton canyon yes

kinda hard to really grasp the pivot it's looking towards, but it seems like it gets too close to the pivots when you look downwards.

wanton canyon
timber tide
waxen pond
fervent abyss
#

how can i do new lines in string in inspector?

young warren
#

wait

#

i need to research

waxen pond
#

I can't get help here :((

young warren
waxen pond
#

Anyways, bye.

fervent abyss
young warren
#

last i checked, you can't serialize dictionary. is this new?

young warren
#

then i wouldnt know. you should share the full context of your problem

hollow dawn
#

Can someone help me get better at c#? I'm a beginner I tried watching videos of variables and I don't understand it and gain nothing from watching those videos 😭

rocky canyon
#

learn by example.. just start making

hollow dawn
rocky gulch
#

can anyone explain how generic works, i thought i had learned it and it seemed that my theory about generics are wrong

so in this context i was trying to make a statemachine using generics and dictionaries, i tried it and it returned a null reference. After trying to find whats wrong with my code, i discovered that it was probably because of the dictionary not actually keeping the Enum value from the generics

public class StateMachine<State, StateEvent> where State : Enum where StateEvent : Enum 
{
    public BaseState current_state;
    public Dictionary<State, BaseState> states;
    public Dictionary<(StateEvent, BaseState), BaseState> transitions;
    public Dictionary<BaseState, List<(bool, BaseState)>> conditions;

heres a portion of the code that involves generic as a parameter

and heres how i applied it on another script


[RequireComponent(typeof(NavMeshAgent))]
public class Enemy : MonoBehaviour
{
    [SerializeField] private Transform Enemy_Target;
    [SerializeField] private float update_time;
    [SerializeField] private NavMeshAgent agent;
    public enum state_event
    {
        allydies
    }
    public enum state
    {
        Chase,
        Shoot,
        Cover,
        Dash
    }
    public StateMachine<state, state_event> SM = new StateMachine<state, state_event>();
    private void Awake()
    {
        agent = GetComponent<NavMeshAgent>();        
    }
    void Start()
    {
        SM.AddnewState(state.Chase, new Enemy_Chase(Enemy_Target, update_time, agent));
        SM.setState(state.Chase);
        SM.OnEnter();
    }
rocky canyon
#

episode 24 he starts building something.. (everything up to that point is just learning material).. my favorite playlist..

#

this one starts str8 up making the game.. but id watch the other series first

#

then theres ur classic Unity !learn

eternal falconBOT
#

:teacher: Unity Learn β†—

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

rocky gulch
# rocky gulch can anyone explain how generic works, i thought i had learned it and it seemed t...

i tested all of them, the code works fine
its just that current_state from the statemachine is still null but i did set it by doing AddState and setState

    public void AddnewState(State state, BaseState baseState)
    {
        states.Add(state, baseState);
    }
    public void setState(State state)
    {
        current_state = states[state];
    }

it was from that point that i knew that the dictionary is the problem here (i debugged the parameters)

hidden current
#

/*
*/

#

oh

#

that was for a comment

rocky gulch
#

thats comment

hidden current
#

my b

wintry quarry
slender nymph
#

raw string literals are a c#11 feature

#

you can do:

var string = @"
this is on a new line
";
#

or just use the \n character like you are doing there and just have it all on one line

slender nymph
rocky gulch
slender nymph
#

your dictionary is null. where do you initialize it

rocky gulch
#

πŸ’€

#

one sec lemme just initialize it

slender nymph
rocky gulch
#

great

#

thanks, i got stuck for a day just because i did not initiliaze it

#

so i wasnt wrong

#

i love when programmer forgets 1 step and loses braincells unknowingly to what factor

wintry quarry
#

It's called tunnel vision

#

you were so focused on the generics problem you forgot all the other basic stuff

rocky gulch
carmine sierra
#

yes

frigid sequoia
#

How come that ".enabled" is not something I can use with the generic Component class?

wintry quarry
wraith hornet
#

hi guys

#

pls help me with this

burnt vapor
wintry quarry
rocky gulch
#

use the new keyword :/

wraith hornet
#

oh i got it , thanks so much

burnt vapor
# wraith hornet pls help me with this

camera is an old Unity variable that exists in one of the inherited classes MonoBehaviour uses. It's deprecated and should not be used. You can use the new keyword to replace the variable. Alternatively name your field _camera to use a different name, considering your field is private anyway.

ivory bobcat
burnt vapor
#

I wonder if there will ever be a point where they remove all the bloat, including this

split dragon
#

Hello. I have a question: I have an int variable that takes values from the slider, and also have a text that will convert this to text. So: Is it better to use int or Slider for text? Personally, I think it will be the same thing, or int will be somehow better. But I'd rather ask the professionals.

wintry quarry
#

in this case it sounds like the ints array is that source of truth

burnt vapor
split dragon
#

One says slider and the other says int?

burnt vapor
#

But I don't get the question. Is slider a component?

#

Why would you have a second array when you have the slider already provide values?

#

The only thing I'd do is possible make a method that takes the value from the slider, so refactoring is easier

split dragon
willow scroll
split dragon
burnt vapor
#

But why do you have a separate int array? Because the slider returns a float?

#

If you just use it as a middleware because you want the response as an integer then just make a method that grabs the value from the slider

burnt vapor
willow scroll
burnt vapor
#

Just grab the value using a method and round it. If you want the extra performance boost use aggressive inlining

#

I don't think the array is used apart from being some middleware for casting, but Molorochik can answer that better

willow scroll
#

They could've answered that better, hadn't they disappeared from the discussion though

ivory bobcat
#

If it werecs int[] ints = new int[sliders.Length]; for(...) ints[i] = ... text[0].text = ... ...you'd probably be well better off not caching the integer values just to avoid casting or accessing the value property of slider.
If it werecs [SerializedField] private Slider[] sliders; public int[] ints; public void UpdateCacheAndText() { for(...) ... ... }where you'd like others to have access to the values without having access to the sliders then it'd be fine or even necessary to cache the data.

rugged sail
#

Hello, my name's Azerul and I'm a newbie at Unity/C#. Currently, I am working on a project for a class in university, but I hit a wall;

I'm having trouble detecting collisions with capsule colliders on an Enemy AI using Physics.Raycast in Unity to spawn bullet decals on them. So far, I've checked the capsule collider settings, and the raycast does hit the collider, but my method( called DetectSurfaceAndTrigger) isn't being called.

Any suggestions or advice on how I can resolve this issue would be greatly appreciated! Thank you in advance for any assistance provided!

frigid sequoia
rugged sail
wintry quarry
willow scroll
#

Neither can you start a coroutine on it

frigid sequoia
willow scroll
polar acorn
#

jinx

wintry quarry
# rugged sail

Nothing shown in this code ever calls your function DetectSurfaceAndTrigger

slender nymph
#

Collider is surprisingly another one, though it does implement its own enabled property

frigid sequoia
#

I cannot use .enable on a RigidBody?

willow scroll
frigid sequoia
#

Weird

wintry quarry
willow scroll
#

You can check it out in the Inspector too

#

While there is a tick on e.g. a BoxCollider, which enabled and disables it, there is no one a Rigidbody

frigid sequoia
#

Don't they have the little toggle button on the inspector? Isn't that the .enable toggle?

willow scroll
frigid sequoia
#

Oh, you are right, how weird, why is that?

polar acorn
#

And thus does not implement enabled

wintry quarry
#

well it's not a Behaviour

willow scroll
frigid sequoia
#

What if I wanted to get rid of a Rb through code?

wintry quarry
#

Destroy it

frosty lantern
#

I've inmported the probuilder package but my IDE isn't recognizing the UnityEngine.ProBuilder namespace:

wintry quarry
#

or make it kinematic

wintry quarry
willow scroll
#

Behavior is basically a Component, but with enabled and isActiveAndEnabled booleans

scarlet skiff
#

The collision is being weird, how does it keep damaging the player if the player is invincible? (logged the value is does become true when the player is invicne yet player still takes too much damage), also, when the player doesnt move.. they can stand and not take damage?

frosty lantern
#

vs just can't find the namespace fore some reason

wintry quarry
fossil drum
frosty lantern
rugged sail
hidden current
#

i hope im not asking for too much, but i think im ready to ask for help, i want to submit a bug to unity but i want help checking if my code is the problem first. i dont wanna waste some unity developers time because im not sure if my code is just bad

summer stump
eternal falconBOT
summer stump
#

Those of us on mobile cannot read it the way you shared it

hidden current
#

can i post it to github? theres a couple of files you'd have to read :/

wintry quarry
#

The recommendation is to use a site such as those listed above yes.

slender nymph
#

that pastemyst site listed in the bot message supports more than one file per paste

hidden current
#

ok, i will post it to github and pastemyst

slender nymph
#

you don't have to do both, just choose one . . .

hidden current
#

oh, then i choose github πŸ˜„

sage mirage
#

Hey, guys! I want to make on my game windowed and full screen mode. I have made the full screen mode but I am not sure of how to make the windowed mode. To note I don't want maximized windowed I just want windowed.

#

Can anyone help with that?

sage mirage
#

Yes, I know that! I have my documentation open on that

wintry quarry
#

So what are you having issues with?

sage mirage
#

That doesn't helps me a lot

#

I want to know the implementation

wintry quarry
#

implementation of what

rare basin
#

well, it's in the docs

wintry quarry
#

Screen.fullScreenMode = FullScreenMode.Windowed;

#

it's right there in the docs

rare basin
#

unity how to set windowed mode

#

first 5 links in google has the answer lol

sage mirage
#

If I am going to write that it will show that?

sage mirage
rare basin
#

show what?

sage mirage
#

In google

rare basin
#

that's a google phrase

#

you know how to google right?

sage mirage
#

Sometimes XD

#

I just have to put in front the topic?

rare basin
#

well, then you probably need to learn how to google things lol

#

otherwise you wont have a good time coding

sage mirage
#

In YT I just typed how to make full screen and windowed mode in unity

#

That's what I wrote

rare basin
#

ok

sage mirage
#

I found nothing

polar acorn
rare basin
sage mirage
#

that was related with windowed exclusively

wintry quarry
sage mirage
#

Alright

wintry quarry
#

so i'm confused how you didn't see it

rare basin
#

show the code you have

sage mirage
rare basin
#

huh

wintry quarry
#

that is not code

sage mirage
#

I am searching in docs

rare basin
#

and it's right there

sage mirage
#

And there I see not information for implementing the code

summer stump
#

"Unity fullscreen windowed" in google

wintry quarry
wintry quarry
#

that's the whole point of it

sage mirage
#

Is it screen.fullscreen?

#

I found it

wintry quarry
#

That's why I linked you to it

rare basin
#

do you even have your ide configured? @sage mirage

sage mirage
#

Yes!?

rare basin
#

do you even know what are you doing? lol

wintry quarry
#

I guess maybe you're lost because there's an assumption in the documentation that you can string together some basic C#

#

If you are having trouble with that part I recommend backing up and doing some basic C# tutorials

sage mirage
#

I know how to code XD

#

The whole problem was in searching the thing in how to implement it

wintry quarry
rocky canyon
rare basin
sage mirage
#

I am learning how to implement new functionalities that I probably didn't knew how to implement before.

rare basin
#

and how do you learn how to do it

sage mirage
#

I am searching tutorials, trying to find useful information and trying to write it on my own at the end.

rare basin
#

so what was different this time

sage mirage
#

For example new game mechanics

rare basin
#

when after googling the very basic phrase how to make wnidowed mode in unity there are 3 pages of how to do it

sage mirage
#

Nothing xd move on I am fine now

#

Thanks

vagrant lynx
#

Should I use a rigidbody and character controller on one player ?? Just asking, is it recommended ?

wintry quarry
#

If you do - the RB needs to be Kinematic.

vagrant lynx
#

Ohh ok

summer stump
wintry quarry
summer stump
#

OnCollisionEnter does not though

#

Only the trigger variety

wintry quarry
#

ofc but that wouldn't work with kinematic RB anyway

summer stump
#

True true

polar acorn
summer stump
vagrant lynx
#

Btw, In the character controller.isGrounded, what is ground for this script ?

hidden current
polar acorn
hidden current
polar acorn
hidden current
#

i dont know what is causing the bug, but i think its in the DropTiles() function

polar acorn
#

which is where

hidden current
#

TileSetter.cs

polar acorn
#

And what is the thing you're expecting to happen that is not happening

hidden current
#

im expecting all of the tiles to be filled with a tile which has a sprite, but some tiles are left with a null sprite from before they are filled

silent vault
#

Hello, I'm having an issue with IK for my animation. I'm trying to animate only the right arm of my character, I've created the mask and it works fine when I don't use IK target for my right hand. But when I use a rig for the right hand, I need to temporarily disable the Rig weight so the animation of the right arm work. I've created an animation event to handle that at the beginning of my animation, it does trigger but for some unknown reason, the weight of the rig is still 1 in the editorr inspector right after the break.

#

Here is my character rig and the logs

#

And here is my script

#

I'm checking the right hand weight to see if I need to cancel the IK. I do detect 1 and I then unpin the hand. I check the weight right after and it does debug 0 as expected

#

But in the editor, the rig weight is still 1

#

I've checked the character and rig name to make sure I'm using the correct objects and everything seems in order. But for some reason, the rig weight stays at 1 the whole time even after a break in the animation event.

#

How can that be possible?

#

The debug log show 0 but the editor shows 1

#

Is there some latency on the debug.break?

#

If I manually set the rig weight to 0 during the break and resume my animation, then it animates properly. But the script should have done that for me. Why is the rig weight stuck at 1 after the break ?

frosty lantern
#

Hey I just want to verify something. I have:

public abstract class ChessPiece : MonoBehaviour

and

#
public class King : ChessPiece
#

so if I use getcomponent, can I get chess piece if my object has a king script?

wintry quarry
#

King is a ChessPiece

#

but you will get the reference as a ChessPiece reference.

frosty lantern
#

ok cause I'm getting some broken references and want to make sure that the logic is right before I break something

wintry quarry
#

it has nothing to do with GetComponent

frosty lantern
#

none of the objects in my scenes or prefabs are showing as broken though

silent vault
frosty lantern
#

and now the errors are gone

#

idk why

solid sail
#

I searched a lot but still understand what is MVC and MVVM? What exactly they are ......

slender nymph
#

they are architectural patterns. and i doubt anyone wants to go through and explain how they work or how to design your systems to conform to those patterns

hot palm
#

Why is unity adding using directives I don't need and then complaining?

solid sail
#

Maybe I need to understand it with actual project? I just look the definition by searching in google that make my brain....

slender nymph
slender nymph
hot palm
slender nymph
#

yes, anything within the UnityEditor namespace (technically the assembly, but for this explanation just the namespace is fine) will not be included within a build

raw spear
#

Hey guys, just starting Unity. Do anyone know how to make the type proposition appearing ? Like as the left screen

rare basin
#

!ide

eternal falconBOT
slender nymph
raw spear
slender nymph
#

because that is the fucking answer

vagrant lynx
#

Do you guys also use cc.Move() on vector3 Y axis for jump ??

slender nymph
#

if you are using a charactercontroller, then you have to

raw spear
vagrant lynx
slender nymph
hidden current
#

@raw spear bro dont talk back, hes just helping u

raw spear
slender nymph
#

"nOw YoU'Re AnSwERiNg Me"
my guy, i've pointed out the answer to you multiple times. if you cannot read the answer you're gonna have a bad time

frosty hound
edgy prism
#

Seems like I chose a bad time but im bad at maths rather than a multiple of .5 how could I make this a number that always ends in .5?

case 0: // Top edge
                float randomXTop = Mathf.Round(Random.Range(-4.5f, 4.5f) * 2) / 2;
                spawnPosition = new Vector2(randomXTop, 9.5f);
                direction = Vector2.down;
                break;
polar acorn
frosty hound
frosty lantern
frosty lantern
edgy prism
frosty lantern
slender nymph
frosty lantern
#

oh cool

slender nymph
#

just note that Random.Range when used with ints is max exclusive

edgy prism
#

Welp i've only been learning to code for almost 2 years and now I find out I had the definitions for ints and floats backwards

frosty lantern
#

the more you know

edgy prism
#

Thanks for your help guys

frigid sequoia
slender nymph
frosty lantern
frigid sequoia
#

Oh, I guess that makes sense...

frosty lantern
#

and typically we exclude the max for ints because our counters run one lower for indexing because of computer stuff

#

So I'm instantiating some placeholders for the move spots, and its creating them, but it seems like each instantiate creates 2 gameobjects, so how would I prevent that?

slender nymph
#

you're calling new GameObject() as the object to create a clone of. so you create a brand new empty gameobject, then you clone it

frosty lantern
#

oh i'm dumb, thank you

#

can I instantiate an empty?

slender nymph
#

if you want an empty object just use new GameObject

#

then change its position to whatever you want on the next line

frosty lantern
#

oh so don't use instantiate cool

rich adder
#

new makes a new GameObject

slender nymph
frosty lantern
#

ok that makes sense

hidden current
#

sorry to ask again, but is there any chance anyone is checking my project on github? i think i may just file a bug. but i want to know if anyone is looking at it before i do.

summer stump
wintry quarry
#

just sharing the specific script that has an issue and explaining the specific issue would be better

hidden current
#

the problem is i dont know if something outside of the scipt is causing the issue

wintry quarry
#

You also didn't really explain the bug

#

you just said "there's a bug that happens"

#

what does that mean

hidden current
#

its in the readme on the github

#

its too long to explain how the project works here, i didnt wanna flood the chat

wintry quarry
#

Yeah I read it

#

the function name is GetSprites(), this scans every tile to check if they have sprites if we have an empty space because it was not properly filled in the DropTile() then that displays the bug.

#

This doesn't say anything about the bug

#

it just says "that displays the bug"

hidden current
#

thank you, im gonna re-read it

frosty lantern
#

I'm using CreateShapeFromPolygon, and I've added the mesh and created the shape (presumably), but the shape isn't rendering

            for (int i = 0; i < 6; i++)
        {
            float angle = Mathf.PI / i;
            uIPoints.Add(new Vector3(Mathf.Cos(angle), 0f, Mathf.Sin(angle)));
        }

            GameObject go = new GameObject();
            mesh = go.AddComponent<ProBuilderMesh>();
            mesh.CreateShapeFromPolygon(uIPoints, 0.2f, false);
#

there should be at least a wireframe of a little hexagonal prism, right?

#

yeah the meshes don't appear

smoky mauve
#

is there any way to use Mathf.Pow with a double as an arguent?

frosty lantern
rugged sail
frosty lantern
#

System.Math has a double function for pow

rugged sail
smoky mauve
#

works

frosty lantern
hidden current
#

please let me know if its still confusing @wintry quarry

#

i just edited it

ruby python
#

Hi all,

I've been thinking about this for a while and can't figure out the best way to do what I want to do.

I want to create a 'swarm missile' kind of thing (See pic for reference)

I'd like the missiles to launch one at a time in quick succession and then each one head towards a seperate target. The targetting I'm pretty sure I can do no problem, but I'm not sure how to do the flight path of each missile (I'd like for each of them to come out from the players body and then travel to their target in a smooth arc kinda thing (if that makes sense)

Anyone have any ideas?

hidden current
#

i made a couple more edits, my wording was still bad lol, im sorry

summer stump
frosty lantern
#

probably the point where you find the initial vector would be a good time to lock on a target too.

hidden current
#

@summer stump i put my readme in chatGPT and asked it to summarize in 10 words:

Automated game tile replacement glitch; incomplete tile filling after drops.

hidden current
#

it explained it well tho

summer stump
hidden current
#

im sorry if i sound snarky, im not trying to :/

summer stump
#

What does drops mean? What does tile filling mean?

hidden current
#

ok let me retry

summer stump
#

The first 5 words are completely unneeded

summer stump
hidden current
#

ok

ruby python
frosty lantern
ruby python
hidden current
#

@summer stump so i have a 2d game. it uses a tilemap. the tilemap is filled with tiles. i want to delete a random tile in the tilemap and i want to lower the tiles on top to replace the deleted tile. then i want to fill the space on top with a random tile. The problem is not all tiles are getting filled. so im left with holes where some of the deleted tiles are.

frosty lantern
ruby python
#

Yesterday I mean. lol.

summer stump
#

But yeah, I think that explains it well

hidden current
summer stump
hidden current
#

ok ty!!

ruby python
lofty sequoia
buoyant meteor
#

is it possible to hide a component like you can in the inspector, but in code?

ruby python
buoyant meteor
#

I know I can SetActive to false for a gameObject but i just need to hide a component in that gameobject

lofty sequoia
#

can't you specify a timeframe with LookAt? Guess not

rich adder
#

what do you mean Hide ? @buoyant meteor

ruby python
#

component.enabled = true/false

hexed terrace
ruby python
#

Yeah you can't hide them but you can turn them off.

buoyant meteor
hexed terrace
buoyant meteor
#

i got it

#

thanks

ruby python
hexed terrace
#

If your class doesn't have a Unity method , then the enable is pointless

buoyant meteor
#

im just using this for my inventory

#

i didnt want to disable an entire object.

rich adder
#

disabling only disables these methods

buoyant meteor
#

so toggling the canvas seems better to me.

ruby python
#

If you have public or serialized variables etc. that you want to hide, you can use [HideInInspector] (I think that's the line) to hide them.

stray wraith
#

anyone know how to add a rigidbody's force relative to another object's rotation? currently doing this but it really doesn't work propertly and I can't figure it out cs m.rigid.AddForce(Quaternion.FromToRotation(m.orientation.forward, relativeForce.normalized) * relativeForce, ForceMode.Impulse);

supple needle
#

Guys, I want to add a four way intersection to my driving game. However, I want to also add traffic to my game. So far, I've just bee using objects as waypoints for the car to follow. However, when it comes to intersections, there are various paths that the car can take.

My initial approach was setting up 3 lists for each direction of approach for a total of 12 lists. But then it seems like a lot of waypoints. I feel like this has a simpler solution. Any suggestions would be appreciated!

buoyant meteor
#

also for anyone wondering, toggling the canvas fixes the issue of having an item getting stuck on screen when disabling(closing inventory) an object while holding an item in a random location.

wintry quarry
#

Seems like you just have a bug in your code.

buoyant meteor
#

Also does anybody know how to not allow an item to center onto a item count gameobject.

#

in each of my inventory slots I have a gameobject called itemCount to store count value

#

but if i drag an item ontop of an ItemCount, it will center onto it.

hidden current
wintry quarry
#

why is a null sprite considered a bug here?

hidden current
#

because its supposed to get replaced with a actual sprite?

buoyant meteor
#

or should I simply add the itemcount to my item object?

wintry quarry
wintry quarry
buoyant meteor
#

no

hidden current
# wintry quarry and what part of your code does that?

in the TileSetter.cs file:

Vector3Int tilePos = new Vector3Int(lastPair.x, lastPair.y, 0);
tilePos = new Vector3Int(tilePos.x, tilePos.y + 1 + i, 0);
//get the tile above the stack
TileBase upperTile = tilemap.GetTile(tilePos);

tilePos = new Vector3Int(firstPair.x, firstPair.y, 0);
tilePos = new Vector3Int(tilePos.x, tilePos.y + i, 0);

//drop the tile above the stack
tilemap.SetTile(tilePos, upperTile);
hidden current
#

it is supposed to replace the tile with the null sprite, with one that has a sprite

#

i have checked and added break points to make sure that it has a sprite, and the breakpoints never get triggered

buoyant meteor
hidden current
wintry quarry
#

But I presume you're using a special GameObject tile or something here

#

because normally with tilemaps, GameObjects aren't really involved in each tile

hidden current
#

it is a ruletile

hidden current
wintry quarry
hidden current
#

hold on

buoyant meteor
#

I gotta respect @wintry quarry for helping alot of people out today, including me.

hidden current
#

i might be onto something

#

nvm

#

darn lmao

#

ok back to the question

#

@wintry quarry the breakpoint isnt in the script but if i make one and run it then it doesnt get triggered, like this

wintry quarry
#

your other code is checking ALL tiles right?

#

this code is only checking some

hidden current
#

correct, i can everywhere where i am filling the tiles, and to my understanding i am filling the tiles everywhere where i could. but if there is a special condition where im not filling them then it isnt a unity bug, but just my bad code

wintry quarry
#

yes

#

Unity is not going to do anything with this as a bug report right now

#

you'd need to show an isolated scenario in which Unity itself is clearly doing something wrong

tender stag
#

is there any way i can make this sprite fully white?

hidden current
#

the problem is, to my knowlege i dont have a special condition

wintry quarry
#

right now we have a very nebulous situation where it's most likely a problem with your code

wintry quarry
hidden current
#

but i cant prove that it is. and i need help

tender stag
#

i need to do it automatically

#

like a shader?

wintry quarry
#

why do you want it white

#

sure you could use a shader

tender stag
#

so have like a white transparent overlay

#

onto the slot

wintry quarry
hidden current
wintry quarry
#

it doesn't matter how many times you call the functions

#

which while loop are you talking about?

hidden current
#

its too big, i wanna do pastebin or something

wintry quarry
#

didn't you already posgt the github

#

just post a link to the specific part

hidden current
tender stag
#

crafting system

#

so u see those items in those cells?

#

they arent actual items

#

they just show u what items are supposed to go in what cells

wintry quarry
#

you just want a faded version

#

to show

tender stag
#

so i just need them white and a bit transparent

wintry quarry
#

use a shader, sure

tender stag
#

alright

#

someone already made it online

hidden current
#

@wintry quarry im gonna try to reproduce the bug with less moving parts. It might help.

crisp knoll
#

Hello, i have a behaviour script where at one point it should delete itself (as in the game object the script is attached to). If i say this, is that referring to the script or the game object because it's not deleting properly

hexed terrace
#

Destroy(gameObject);
Destroy(this.gameObject);

#

Destroy(this); will destroy the component, not the gameObject

crisp knoll
#

Thanks, this worked perfectly

prime cobalt
#

How can I check if a button is pressed or held? Since I think just using get button down would trigger if it's pressed briefly and I want to assign different functions to each.

summer stump
nocturne parcel
#

For new InputAction.IsPressed()

summer stump
#

And iirc wasPressedThisFrame

#

For the other

nocturne parcel
#

Highly recommend moving on to the new input system

crisp knoll
#

is there a new input system for keys too?

prime cobalt
#

I've got a lot of stuff already made with the old system so it seems like too much of a pain to switch for this project

crisp knoll
#

like something to use instead of onKeyPress

prime cobalt
frosty lantern
nocturne parcel
#

Then just check the bool

ruby python
summer stump
prime cobalt
#

Ok. Too bad.

ruby python
# frosty lantern OK cool thanks

Meshfilter needs the mesh applied, and the meshRenderer needs the material applied (I'm not sure about all the other stuff needing parameter set tbh, not something I usually do)

frosty lantern
#

Not doing too much with it

ruby python
frosty lantern
ruby python
#

lol.

frosty lantern
#

They really need to match the energy of
:)

young fossil
#

!code

eternal falconBOT
crisp knoll
#

you guys know that you can turn off the auto emoji stuff right? :)

frosty lantern
crisp knoll
#

its in settings

#

in chat

#

"Automatically convert emoticons to emojis"

ruby python
#

lol.

polar acorn
#

You can also do it with an escape character :)

ruby python
#

Sooo, having a brain freeze moment (surprise surprise).

What's the syntax to get an object to remove itself from a list at it's specific index?

polar acorn
ruby python
#

1 sec.

crisp knoll
#

Would this be the correct way to check if both colliding with a specific trigger and also the "e" key is down?

public void OnTriggerStay2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "tag")
        {
            if (Input.GetKeyDown("e"))
            {
                //random code here (not really imortant)
            }
        }
    }
crisp knoll
hexed terrace
#

collision.gameObject.CompareTag("tag") && Input.GetKeyDown(KeyCode.E)

frosty lantern
ruby python
# polar acorn Do you want it to remove itself from the list, or remove the item at a specific ...

Okay, vid for reference. public list on bottom right.

https://streamable.com/4ep9ik

at the moment I'm using

spawnManager.enemyList.RemoveAt(spawnManager.enemyList.Count - 1);

Which is fine, I guess, but I can see the 'Missing Transform' entries in the list being a problem at a future point, so I'd obviously like to remove the objects from the list 'directly' (not sure if that makes sense)

Watch "2024-04-10 20-04-22" on Streamable.

β–Ά Play video
hexed terrace
frosty lantern
#

The more you know

young fossil
#

Hey when I run the code in editor, it 50% pauses the game, 50% doesn't. The menuState is always entered, just the isPaused bool is ignored and the subscribed event does not execute.

https://gdl.space/uyagiwucej.cpp
tldr: OnGamePaused?.Invoke(value); does not execute

hexed terrace
polar acorn
#

If you want to have this object remove itself from the list, do .Remove(theObjectToRemove). Right now you're removing the last element of the list no matter what is destroyed

ruby python
#

Aaah okay, thanks, just couldn't remember the syntax πŸ™‚

crisp knoll
#

Would this be the correct way to check if both colliding with a specific trigger and also the "e" key is down?

public void OnTriggerStay2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "tag")
        {
            if (Input.GetKeyDown("e"))
            {
                //random code here (not really imortant)
            }
        }
    }
languid spire
crisp knoll
#

okay that makes sense

#

cus i was pressing e over and over again

hexed terrace
crisp knoll
#

and it seemed completely random

young fossil
crisp knoll
#

i dont want it to be held down, i want it to be where if its pressed while the red "ball" is touching the grey trigger

#

the thing on the right side is a different prefab

polar acorn
# hexed terrace ~~it's TriggerSTAY - should be fine?~~

The issue is that OnTriggerStay occurs in FixedUpdate, but GetKeyDown changes in Update. Meaning depending on your framerate, you might end up doubling up on Updates between FixedUpdate calls and that button press gets "Skipped"

hexed terrace
polar acorn
ruby python
#

It might be better to set a bool onTriggerEnter = true / false

crisp knoll
#

okay, thanks much!

young fossil
#

gdl space

whole idol
#

why cant I create a new clone in the parrelSync?

rich adder
#

apparently you're in the clone and you cannot create additional clones from clone, open original project

hexed terrace
young fossil
#

That start is unrelated it seems. The menu state logs fine, it's the bool that has a 50/50 success rate

#

And yea, the bool then has invoke, then invoke relies on events. So that's when I am lost

hexed terrace
#

I haven't used an FSM before..

When you call _gameStateFSM.TransitionTo(_gameplayState); is the case FSM.Step.Exit: in MenuState being actioned?

lofty sequoia
#

they've tried to improve unity editor execution to run similar to a built exe, but some things listen for different events, like EditorApplication.isPaused = true;

young fossil
#

If you're wondering if Exit is immediately called, it isn't.

It goes:

  1. Press play
  2. MenuState enters (calls Enter)
  3. 50% chance the property IsPaused invokes OnGamePaused event
#

So the FSM doesn't seem to be an issue from my testing

hexed terrace
#

if you comment out your (value == _isPaused) check, does it make it 100%?

whole idol
young fossil
young fossil
hexed terrace
#

I guess the backing field is getting updated at the wrong time

young fossil
#

Not mentioning anyone but someone here explicitly told me to put that there and it worked when I had it before... So glad I found it but that's really odd

hexed terrace
#

not always before it needs to

crisp knoll
#

If i have a script attached to a prefab, can I drag a pre made game object into that script still? its saying Type Mismatch and I don't know why

hexed terrace
young fossil
#

What do you mean backing field?

#

You mean the private field?

rich adder
#

_

hexed terrace
#

backing field: private static bool _isPaused = false;
property:

ublic static bool IsPaused
    {
        get => _isPaused;
        set
        {
            if (value == _isPaused) return; // Do nothing if value doesn't need changing

            _isPaused = value;
            OnGamePaused?.Invoke(value);
        }
    }```
young fossil
hexed terrace
#

Change the property to

public static bool IsPaused
    {
        get => _isPaused;
        private set
        {
            if (value == IsPaused) return; // try this, if it doesn't work, remove
            IsPaused = value;
            OnGamePaused?.Invoke(value);
        }
    }```
young fossil
crisp mountain
#

im trying to reference a script from another object, but i keep getting an error. im doing this so that i can change a variable on the gamemanager that keeps track of credits used by enemy spawners. does anybody know what might be wrong?

rich adder
#

also using Find is horrid

crisp mountain
#

it is?

rich adder
young fossil
young fossil
#

Oh sorry, thought it VS. I don't think they call vscode an IDE

rich adder
crisp mountain
#

so what else should i do?

rich adder
crisp mountain
#

yes

rich adder
#

try regen project files from the screen you just showed me (close vscode first)
then open script from Unity again. Observe the Output tab for any errors

young fossil
#

And thanks for the help i really appericate

hexed terrace
crisp mountain
#

how do i regen project files?

rich adder
rich adder
#

you cannot add scene objects into a prefab

#

unless the prefab is like in the hierarchy of said scene

hexed terrace
crisp knoll
#

okay thats what i guessed.

#

How do you suggest I go about this?

crisp mountain
rich adder
crisp mountain
#

it still says theres an error

rich adder
#

finish configure ur IDE first

crisp mountain
#

same one

rich adder
#

again you cannot use constructors on MonoB scripts

crisp mountain
#

i did???

rich adder
#

its not tho

crisp mountain
#

so what do i do??

rich adder
#

i told you like few times already and u showed me something else

crisp knoll
crisp mountain
#

ive been told to use a singleton so im gonna look that up and do that instead

young fossil
polar acorn
#

You also probably shouldn't use Find at all

rich adder
#

if you make further syntax error we cannot help

crisp mountain
#

its configured to the best of my ability. im not sure what you mean by an output tab

rich adder
#

mate i was guiding you through it and u stopped responding

#

ima go back to watching people get bit by snakes, good luck

crisp mountain
#

:(

summer stump
#

Ah, lag

hexed terrace
crisp mountain
crisp mountain
#

vscode

summer stump
#

Should be at the very bottom. If not, you can open it from the "view" menu at the top I think

crisp mountain
#

aha! thank you!

supple elbow
#

so i have a gacha code where you can pull things and it will instantiate an item in a list, which is from this first code, but i want to place it in my inventory, but im not sure how i should do that:

wintry quarry
#

Well that all depends on your inventory works

supple elbow
#

i was following a tutorial for picking objects with collisions which will enter it into the inventory, but theres not anything from like putting it into the inventory from the gacha

#

idk how to explain

ruby python
#

!code

eternal falconBOT
supple elbow
#

kk

ruby python
#

More woes with loops inside Coroutines. lol.

https://streamable.com/a1xz8g

So, you can see on the bottom right that the enemyList gets filled up correctly.

But, if you look at the debug, only 5 missiles spawn in so the loop isn't running fully and I'm not sure why.

IEnumerator PlayerShootMissiles()
{
    float missileCount = 0;
    // TODO : Swarm Missile Firing
    isFiring = true;
    missileTimeToFire = Time.time + 1 / missileRateOfFire;
    for (int i = 0; i < spawnManager.enemyList.Count; i++)
    {
        if (Time.time >= missileTimeToSpawn)
        {
            //spawn missile
            GameObject newMissile = Instantiate(playerSwarmMissile, missileFiringPoint.transform.position, missileFiringPoint.transform.rotation);
            PlayerSmartMissiles playerSmartMissile = newMissile.GetComponent<PlayerSmartMissiles>();
            playerSmartMissile.target = spawnManager.enemyList[i];

            missileCount++;
            Destroy(newMissile, 2f);

            missileTimeToSpawn = Time.time + 1 / missileSpawnRate;
        }
        yield return null;
    }
    Debug.Log("Missile Count = " + missileCount);
    isFiring = false;
}

Watch "2024-04-10 21-06-06" on Streamable.

β–Ά Play video
crisp mountain
#

this is probably a better way to do this actually

crisp knoll
#

dokomni i think i know your problem?

#

are you wanting to access a variable that is from a different script?

crisp mountain
#

yes, mainly a credits system between spawners so that they stop spawning enemies once they run out

crisp knoll
#

im having a hard time explaining this lol

#

im probably gonna make an example sorry for the wait

sage mirage
#

Hello, guys! I am trying to make the parallax effect on my 2D side scrolling game and I actually made it but I am not sure of how to stop it when my game goes over or pause?

{
    if (RoundManager.Instance.currentState != GameState.GameOver || RoundManager.Instance.currentState != GameState.Pause)
    {
        distance = distance + (Time.deltaTime * scrollSpeed) / 10f;
        mat.SetTextureOffset("_MainTex", new Vector2(distance, 0));
    }
}```
crisp mountain
#

no its alright

sage mirage
#

Here is my code

ruby python
tender stag
#

can someone help me make a shader to make these image sprites white?

polar acorn
sage mirage
crisp knoll
#

they dont need to be in the same script i just did that for easy sending

ruby python
crisp mountain
#

i see

polar acorn
hexed terrace
polar acorn
crisp knoll
crisp mountain
#

its an automatic thing in discord, you can change that in settings somewhere

polar acorn
ruby python
crisp knoll
prime cobalt
#

If I sort a list of floats can I make another list be sorted in the same way? For example if I have a list of (gameobject3, gameobject1, gameobject2) and another list of (3,1,2), can I apply the order from sorting the list of numbers in ascending order to the list of gameobjects?

polar acorn
crisp knoll
#

I have some changes to make lol. stupid coding mistakes.

ruby python
polar acorn
ruby python
hot palm
#
NullReferenceException: Object reference not set to an instance of an object
GameManager.PlsEndTheGame (System.Boolean value) (at <0d5d04fcd9354ff5925088743d7c08fa>:0)
Timer.Leave () (at <0d5d04fcd9354ff5925088743d7c08fa>:0)
Timer+<TimeIt>d__19.MoveNext () (at <0d5d04fcd9354ff5925088743d7c08fa>:0)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <00d5b91f2c49467b95ced8aa41db73be>:0)

What exactly does this mean? Am new to events and wonder why this wont work. Bcs the game manager script is on an object

#

Its even a singleton

#

(it works in the editor)

ruby python
#

You're trying to reference something that the script can't find at runtime.

polar acorn
polar acorn
ruby python
hexed terrace
polar acorn
ruby python
#

Yes.

ruby python
hot palm
#

Can it not be the same name?

tender stag
#
cellSprite.material.shader = Shader.Find("Sprites/Default");```
#

this changes every cells material shader

#

should each cell have its own material?

#

or how do i go about this

crisp mountain
#

fixed! all i needed to do was this.

polar acorn
hot palm
#

It is the line number of the environment

#

just didnt paste the whole error message

polar acorn
#

Ah, I just missed that, I see now. So it is that line, meaning Environment is null

hot palm
#

Weird bcs its assigned in the inspector

polar acorn
hot palm
#

So I may have 2 gamemanagers?

hexed terrace
polar acorn
#

But the error is stating that at the time that code runs, Environment is null on that object

hot palm
#

Interesting

#

bcs in the editor it's not

#

let me try without the environment deactivate

crisp knoll
#

how to get a child gameObject from it's name in a parent's script?

hot palm
#

oml are you kidding me environment is nulled at some point uhhhhhgg

tender stag
#
public Material material;

private void Start()
{
    material = new Material(cellSprite.material);
    cellSprite.material = material;
}```
#

why is the material not getting assigned?

scarlet skiff
#

which i dont see why that happens

#

also, if u were standing still when the ground becomes lava u dont take dmg if u keep still 🫠

#

those are the current problems and my question is why and how to fix

hexed terrace
#

I understood what your issue was

hexed terrace
# scarlet skiff i changed it to just this

What calls GroundColStay() ?
From this code, health shouldn't be reduced if the player is invincible.. so , there's probably more going on somewhere else that you haven't shown

tender stag
polar acorn
eternal falconBOT
tender stag
#

there isnt a material

#

how can i create an instance of the default one?

#

the Default UI Material

polar acorn
tender stag
#

i'll just make my own material

polar acorn
hexed terrace
#

seems pointless, how come you do that?

scarlet skiff
tender stag
scarlet skiff
scarlet skiff
#

i feel like it becoems easier to break it down into parts

tender stag
#

and line 44

polar acorn
#

The fact that you're trying to use it in the Refresh method before you set it

tender stag
#

right

#

yeah works

polar acorn
#

So next time, don't omit things you think aren't relevent because those often end up being what the problem is

tender stag
#

true

#

thanks

hexed terrace
scarlet skiff
# hexed terrace that makes sense now

sooo... what my thoguht process is that player takes 1 dmg, becoems invicnible (happens whenever player takes dmg) then cuz the player is invincible it wont take damage

#

however

#

player still takes damage

smoky niche
#

Hey there. Is there a way to set the pivot point of an object without having the make it a child of another object. In my case it also needs to happen during runtime

scarlet skiff
#

pls i legit cant think of why 😒

abstract pelican
#

how to make it so that when I pick up an object it does not move, but is fixed on a point

hexed terrace
#

your if statement has two bools, you know one is correct (player is invincible), but you don't know the other is correct - log it out

cosmic dagger
#

but the pivot is set from the 3d modeling program . . .

smoky niche
#

Yeah I haven't found any good solutions online sadly

cosmic dagger
#

those are the only solutions . . .

scarlet skiff
smoky niche
#

Yes I figured there would we a better way but aparently not...
Weird smt simple like that cant be done another way

scarlet skiff
#

i know floor is lava is true cuz also the floor changes sprite

polar acorn
queen adder
#

If a raycast hits nothing, is the corresponding RaycastHit.Distance supposed to be 0? (when maxDistance parameter of raycast is non-zero)

hexed terrace
summer stump
#

The third param is not a speed

scarlet skiff
#

i... okay one sec..

crisp mountain
#

how might i change an int value called "credits" in a script called "credit" which is referenced this way? (gets it from the "credit" script on the CreditKnower gameobject)

cosmic dagger
crisp mountain
#

oh

#

im dupid

cosmic dagger
#

create a method on the script that changes the internal credits value . . .

crisp mountain
#

on which script? the one referenceing or the one being referenced?

abstract finch
#

Whats the advantage of Slerp over Lerp for rotation? I'm looking at an example for something like a turret aiming at a target and it uses slerp. Is it less buggy?

cosmic dagger
cosmic dagger
abstract finch
#

so its just changing the speed how it smoving?

short hazel
#

Slerp is better if you need to rotate a direction vector

abstract finch
#

like an animation curve

scarlet skiff
#

basically:

crisp mountain
scarlet skiff
#

it does do what its suppsoed to to but sometimes... isInvincible doesnt catch on as quickly?

abstract finch
short hazel
#

It keeps the vector normalized (because it's spherical), and it will actually make the rotation feel linear. If you used regular Lerp, you'd see a slight acceleration towards the middle point of the lerp

hexed terrace
# scarlet skiff basically:

Because you're setting your IsInvincible depending on the animation (I wouldn't), I would look at how quickly this happens... it looks like maybe its too slow to be invincible == true, so you get damaged twice

abstract finch
#

Would you ever use Slerp for velocity movement?

sinful helm
#

anyone know why this happens, Im new to coding and have no idea

polar acorn
hexed terrace
#

Is your VS/VSC configured too? !ide

eternal falconBOT
sinful helm
polar acorn
sinful helm
hexed terrace
#

see how yours differs

polar acorn
# sinful helm
I did it exactly like the tutorial so why does theirs work and mine doesn't" counter:
Number of times it wasn't exactly like the tutorial: 156
Number of times it was exactly like the tutorial: 5
Number of times the code literally did not exist: 1
2022-07-19 to 2024-4-10
cosmic dagger
# sinful helm

oh great philosopher, look at what they typed carefully . . .

polar acorn
#

This code does not have Monobehaviour anywhere in it

scarlet skiff
sinful helm
polar acorn
sinful helm
#

The 4th line

hexed terrace
cosmic dagger
sinful helm
#

im baffled

polar acorn
hexed terrace
summer stump
cosmic dagger
#

Monobehaviour
MonoBehaviour . . .

sinful helm
#

Im slow, sorry

hexed terrace
#

1- MonoBehaviour is already present in a new script
2- Typing it should autocomplete from your IDE...

Either your IDE isn't setup, or you ignored it.. but why you changed that in the first place?

sinful helm
#

I have no idea, i just typed, i didnt know the language was cap sensitive, but now i do so thank you

hexed terrace
#

But you shouldn't have HAD to type it

#

are you using Visual Studio?

cosmic dagger
sinful helm
#

I deleted everything and followed the tutorial, I wasnt paying attention to it being there

jagged hare
#

πŸ…±οΈ is for baffled.

cosmic dagger
#

also, following a c# beginner course would have mentioned the language is case sensitive . . .

#

following a tutorial and not paying attention doesn't bode well, my friend . . .

sinful helm
#

Would brackeys have been a better idea?

hexed terrace
#

you would have made the same mistake

jagged hare
#

Brackeys is usually not a good idea, no.

radiant sail
#

im following a tutorial for an addon i just bought and he uses this line in his code SceneManager.LoadScene(0);
but it gives me an error
error CS0103: The name 'SceneManager' does not exist in the current contex
is there something i need to install for this to work

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

public class PlayerHealth : HealthManager
{
    public float health = 100f;
    public override void TakeDamage(Vector3 location, Vector3 direction, float damage, Collider bodyPart = null, GameObject origin = null)
    {
        health -= damage;
        if(health < 0)
        {
            dead = true;
            health = 0f;
            Debug.Log("DEAD");
            SceneManager.LoadScene(0);
        }
        else
        {
            Debug.Log(health);
        }
    }

}```
radiant sail
#

no

polar acorn
eternal falconBOT
hexed terrace
#

Configure your IDE correctly ^

#

It would have auto added the thing you need for it to work

tawny bolt
#

how do i set new instance of float like ("cam.senX = new float ????") what comes after float i cant seem to understand why and what

polar acorn
#

you don't create it with new

#

You just set the float to the number you want

tawny bolt
#

then how do i get a intance of a float ?

tawny bolt
polar acorn
tawny bolt
#

i am using float values across scripts

polar acorn
#

they just are

polar acorn
visual hedge
#

you have misspelled the function name. I wonder about all those people who were looking at something deeper. You call BuildPhaseToAttackPhase but your method is actualyl called BuildPhasetoAttackPhase (ouch... I guess I'm few days late to the party) sorry ))

tawny bolt
#

i dont really understand it

#

i am new

polar acorn
# tawny bolt

Something on that line is null but you're trying to use it anyway

hexed terrace
tawny bolt
#

this is the line

#

got it from here

hexed terrace
#

πŸ˜„

tawny bolt
#

nv mwrong screenshot

polar acorn
eternal falconBOT
tawny bolt
#

ok

visual hedge
tawny bolt
visual hedge
#

Reasonable. I also always rush to this channel the very second my console throws and exception. Should prolly write some api for this. As soon as exception is thrown, send a debug code to this channel

hexed terrace
polar acorn
#

cam is null

tawny bolt
polar acorn
tawny bolt
#

cam code

cosmic dagger
visual hedge
polar acorn
hexed terrace
visual hedge
#

or read anything if they do? πŸ˜„

scarlet skiff
tawny bolt
#

cam = GetComponent<PlayerCam>(); i get the component how do i assign it then ?

visual hedge
#

yeah I checked the documentation, still have no idea... wait, I had to read it all thru? Really?!

tawny bolt
#

do i public it ?

polar acorn
hexed terrace
amber spruce
#

is there a way to find instances of my code like where a certain function is called across all scrips not just the one you are currently editing

tawny bolt
#

no i dont think so how do i apply player cam script on it ?

visual hedge