#💻┃code-beginner

1 messages · Page 88 of 1

gaunt basin
#

im trying to display a text on my screen for context i already have text that shows up in game

civic aurora
#

why isnt my input going in here? Is it because its not a TMP If so how do I type it so it is? This is what the declaration looks like [SerializeField] public UnityEngine.UI.InputField inputField;

gaunt ice
#

legacy InputField is not tmp inputfield

#

what is gui?
one line of code tells us nothing

tawdry drift
steady spindle
#

Good morning, I keep coming up with a NullReferenceException when the game/app starts but I see nothing wrong.

queen adder
#

Did this originally ping me? Discord alerted me to this as a message

steady spindle
#

which is attached to GameManager

#

Not sure what gives, I see nothing null.

#

32 goes to here: currentMoneyText.text = "$" + currentMoney.ToString("#,#");

#

which that line worked before...

slender nymph
#

make sure you don't have more than one of that component in the scene where any others do not have your text objects assigned

steady spindle
#

found it, script was attached somewhere else too, must of missclicked

#

Thanks 🙂

#

this is how it started (from a tutorial on YT)

#

and this is my changes / additions

#

need to fix scrollrect, it doesnt scroll right but bleh

topaz mortar
#

So I had something really weird yesterday.
I added a version number to my API, making it not process any older versions of the game.

{
    if (version == 2)
        return true;
    return false;
}

[CloudCodeFunction("SaveCharacter")]
public string SaveCharacter(int version, string playerId, int level, int experience, int strength, int dexterity, int intelligence, int statpoints, int basehealth)
{
    // Only accepts saves from the latest version
    if (!checkVersion(version))
        return "Wrong game version.";```
But for some reason it just kept working on all the clients that did not have this version parameter yet?
Then I changed the 2 to a bigger number and then it suddenly started working (which means it stopped working for the older clients)

Any ideas? Just curious here
queen adder
#

were you getting null pointer?

topaz mortar
#

no errors or anything, it was just letting clients without version still save somehow

verbal dome
queen adder
#

Personally I'd invert the final check, much easier to check directly for currentversion and blanket all the wrong versions in an else.

steady spindle
gaunt ice
#

it is a force update that request any client update the app?
do the checking on cloud is safer

queen adder
#

Does a null bool return 0 or an error?

eternal needle
queen adder
#

I think it's some funky niche issue with partly undeclared bools being rendered as 0 then. But I'm probably very wrong.

gaunt ice
#

uninitialized bool?

eternal needle
#

also they are definitely not directly converted to 0, i believe thats just a c/c++ feature

queen adder
#

🤔

gaunt ice
#

if it is c/cpp, it will be random value
just safety feature, initialize the memory to zero

ivory bobcat
#

What's the error?

queen adder
eternal needle
queen adder
#

Also let me know if you guys crack this, I'm very curious now

eternal needle
# queen adder https://discord.com/channels/489222168727519232/497874004401586176/1181167120948...

I dont think anyone here could suggest much about that problem, because theres definitely a lot more context we are missing in it. It could be something as simple as they forgot to change the version number. Or that the older versions of the game didnt have this code and would use the cloud function regardless. And then its possible they updated it in such a way where they tested a version where the client had this code

gaunt ice
#

Just place the code in backend
If no version is provided or the version is less than supporting one, then dont process

topaz mortar
#

The code I posted is on the backend in UGS Cloud Code Modules
It's called from clients - the issue was that my last client didn't have the version parameter yet, so it was calling the cloud function without that parameter, but the could function somehow still ran and saved the character

#

only thing I can think of is it somehow converted whatever the playerid string was to the number 2 - but I don't see how

#

UGS CCM seems kinda buggy though, so maybe it just didn't save or load properly

craggy bane
#

How do I add delay to a button click, let's say 0.5f seconds

uncut holly
#

so i need help to understand this code fully

so in my input manager both the horizontal and verticle is set to the x axis but the x axis shown in the scene is sideways. while i can understand the Input.GetAxis code i do not understand both theVector3.forward and Vector3.up code cos of the direction of the x axis and unity tutorial lack of explanation. Am i able to assume Vector3.forward code just means the direction the car is facing and the Vector3.up is sideways of the x axis.

sorry for the long paragraph im really confused at the axis

south hamlet
#

does anyone know how to fix this networking issue when i'm using netcode and i've created a server and joined on a different screen but it's not showing up the character but on the other screen i can see the character so one of the character is client?

uncut holly
#

oh i forgot the 4th code is set to trasnform.rotate my bad small mistake. though im still confused about the axis

queen adder
south hamlet
#

i've been trying to figure this issue out for weeks but i can't seem to get both screen to see each other but only the other person can see and i can't see the character it's something to do with replicating the character

#

the weird thing is that the character has like two characters in the body which means the main player body is stuck to the other player but on my screen it looks perfectly fine but they can't see me but i can see them

queen adder
craggy bane
#

!code

eternal falconBOT
queen adder
craggy bane
#
using UnityEngine.UI;
using System.Collections;
using UnityEngine;

public class ButtonDelay2 : MonoBehaviour
{
    public Button button;
    public float delay = 0.5f; // adjust delay time here

    void Start()
    {
        button.onClick.AddListener(OnClickDelayed);
    }

    void OnClickDelayed()
    {
        StartCoroutine(DelayClick());
    }

    IEnumerator DelayClick()
    {
        yield return new WaitForSeconds(delay);
    
    }
}

#

debug log

#

This is my button delay script and it won't work

south hamlet
#

the movements are perfectly fine and they function normally it's just that the character's body is client on the other screen but i can see the body on the other screen which is odd

craggy bane
#

i attached it to the button and everything

queen adder
verbal dome
south hamlet
#

i'm using netcode for it

verbal dome
#

So that it waits and then runs the code

#

You didn't tell us what you want the button to do

uncut holly
craggy bane
queen adder
verbal dome
queen adder
#

can you show an example

south hamlet
craggy bane
#

disable it after click tho

verbal dome
#

@craggy bane Set button.interactable to false before the yield... line, then set it to true after

#

That is, if you want it to show but be disabled

queen adder
uncut holly
#

ah i see ... though i still have confusions with the axis, the x axis is pointing sideways yet my vertical imput is set to x axis. then when i code it in transform.forward shoudnt it travel along x axis instead?

amber spruce
#

is it possible to change the size and stuff of my players collider in code

verbal dome
#

Yes, look at the documentation for that collider and see what's available

uncut holly
#

ah lol; i saw the beginner scripting in the pinned comments how come i dont see beginner scripting in unity pathways haha

queen adder
craggy bane
# verbal dome <@262191179972476929> Set ``button.interactable`` to false before the ``yield......
using UnityEngine.UI;
using System.Collections;
using UnityEngine;

public class ButtonDelay2 : MonoBehaviour
{
    public Button button;
    public float delay = 0.5f; // adjust delay time here

    void Start()
    {
        button.onClick.AddListener(OnClickDelayed);
    }

    void OnClickDelayed()
    {
        StartCoroutine(DelayClick());
    }
   void OnEnable()
    {
        button.onClick.AddListener(() => button.interactable = false);
    }

    IEnumerator DelayClick()
    {
        yield return new WaitForSeconds(delay);
    
    }
    void OnEnable()
    {
        button.onClick.AddListener(() => button.interactable = true);
    }

}
#

the disable works

#

but enable after the delay doesn't

#

Type 'ButtonDelay2' already defines a member called 'OnEnable' with the same parameter types

#

Oh wait nvm I fixed it

verbal dome
#

That's not what I told you to do

craggy bane
verbal dome
#
    IEnumerator DelayClick()
    {
        button.interactable = false;
        yield return new WaitForSeconds(delay);
        button.interactable = true;
    }```
This is all you needed to add
#

Are you using ChatGPT? Where did this OnEnable/OnDisable stuff come from?

uncut holly
craggy bane
queen adder
craggy bane
#

Ok I got it thanks

queen adder
#

replace X with Z, or rotate the model inside of an empty parent object

raven kindle
#

I am trying to make a parallax effect in my game, i want the background to be generated again once it has moved off the screen.
My background has lots of objects, how can i attach all of this into a sprite renderer?

uncut holly
#

lol the program works just fine haha ... maybe i just need more time to understand the axis thanks for the help anyways @queen adder

raven kindle
#

Can anyone help with this?

craggy bane
#

It's only working on one right now

verbal dome
#

Add the script component to the other objects too?

craggy bane
verbal dome
#

Things work when you do it correctly

verbal dome
craggy bane
#

Tough

#

😔

verbal dome
#

So what code are you using?

craggy bane
#

Urs

verbal dome
#

And what doesn't work exactly?

craggy bane
#
using UnityEngine.UI;
using System.Collections;
using UnityEngine;
using UnityEngine.Events;

public class ButtonDelay3 : MonoBehaviour
{
    public Button button;
    public Button button2;
    public Button button3;
    public Button button4;
    public float delay = 0.5f;
    public UnityEvent enableButton;

    void Start()
    {
        button.onClick.AddListener(OnClickDelayed);
        button2.onClick.AddListener(OnClickDelayed);
        button3.onClick.AddListener(OnClickDelayed);
        button4.onClick.AddListener(OnClickDelayed);
    }

    void OnClickDelayed()
    {
        StartCoroutine(DelayClick());
    }
    

   IEnumerator DelayClick()
    {
        button.interactable = false;
        yield return new WaitForSeconds(delay);
        button.interactable = true;
    }
    IEnumerator DelayClick2()
    {
        button2.interactable = false;
        yield return new WaitForSeconds(delay);
        button2.interactable = true;
    }
    IEnumerator DelayClick3()
    {
        button3.interactable = false;
        yield return new WaitForSeconds(delay);
        button3.interactable = true;
    }
    IEnumerator DelayClick4()
    {
        button4.interactable = false;
        yield return new WaitForSeconds(delay);
        button4.interactable = true;
    }

}

#

I did this

#

now

#

Let me test this

verbal dome
#

Remove those 2-4, go back to what you had

#

Then add the script to the buttons, not some other object

craggy bane
verbal dome
#

Okay well you don't need 4 methods/button references

#

Each button takes care of itself

craggy bane
#

this one doesn't work either

craggy bane
#

YESS IT WORKED

queen adder
#

I suggest looking into for statements, indexing and lists next

#

You can turn scripts like that into modular lists where adding objects is as easy as pressing a little tick and dragging it in instead of making a unique variable for every object.

queen adder
#

Hey yall i got a question.
In my current project i have a level select screen.

I opted to make it a scroll view so the player just has to scroll up to see new levels or down to see previous levels. (Something like the candy crush level layout).
My only issue is. Im trying to save the level that the player is currently on.
Eg. If they on level 50 and they exit the game and go back into the game i want the level to show as level 50. I dont want it starting at level 1 again and then they have to scroll all the way back up to level 50.

So does anyone know how i would be able to save the position of the current level the player is on?

My levels are not prefabs. They are images that have a button script on them. And i setup my level layout (type of board, goals, etc) in a scriptable object

Sorry for the bad explanation. Im not sure how to ask this question.

Im using unity and c#

Basically i have say 100 levels.
Player is on level 50.
Player changes scenes or exits game then returns back to level select screen.
I want the current level of 50 to be shown in the centre of the screen instead of level 1. So that way the player doesnt have to scroll for 10min to find their current active level

#

PlayerPrefs should help

#

save the position to that then get and set the position in the start function

queen adder
#

I'm not sure what physically changes inside of the scroll view as I don't use it, but I think it adjusts the position of it's child object right

#

Also how to i save a position in playerprefs? 😅

raven kindle
#

Why cant i drag a prefab onto a sprite renderer?

queen adder
bold nova
#

Hi, everyone. Trying to make an enemy to shoot. Was just testing. Does anyone know why unity stopped entering the play mode after this lines of code?

#

while(true)
{
randomAttack = Random.value;
if (randomAttack > attackProbability)
{
enemyAnim.SetTrigger("EnemyAttackTrigg");
new WaitForSeconds(1);
}
}

queen adder
#

might help too

#

Thank you

raven kindle
#

Why cant i drag a prefab onto a sprite renderer?

cosmic dagger
cosmic dagger
eternal falconBOT
queen adder
raven kindle
#

How can i make it so my script is using a prefab

cosmic dagger
raven kindle
#

I am making an endless runner, i want the background to be infinite (so it keeps generating new parts)

#

my background has lots of different objects tho

queen adder
#

[SerializeField] GameObject spritePrefab;

#

There's probably better ways of doing it than instanciating a prefab tbh

raven kindle
#

How would this work?

cosmic dagger
raven kindle
#

My code rn is :

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

public class Parallex : MonoBehaviour {

    private float length, startPos;
    public GameObject cam;
    public float parallexEffect;

    void Start () {
        startPos = transform.position.x;
        length = GetComponent<SpriteRenderer>().bounds.size.x;
    }
    
    void FixedUpdate () {
        float temp = (cam.transform.position.x * (1-parallexEffect));
        float dist = (cam.transform.position.x*parallexEffect);

        transform.position = new Vector3(startPos + dist, transform.position.y, transform.position.z);

        if      (temp > startPos + length) startPos += length;
        else if (temp < startPos - length) startPos -= length;
    }
}
queen adder
#

maybe a seamless teleport?

raven kindle
#

it just moves the old part at the front

#

once it hits a certain point

queen adder
#

Did you get this online?

#

I think it's for infinite / looping backgrounds

raven kindle
#

yes it is

#

thats what i wanna make

#

but my background has lots of objects in, instead of being one sprite

#

like this

#

i have them saved as prefabs tho

queen adder
#

Yeah I'd suggest a seamless teleport to the start or spawning a 2nd copy of the prefab with Instanciate

cosmic dagger
#

then group them into a prefab and use that prefab so everything moves together . . .

raven kindle
#

and attach the prefab to the script?

rocky canyon
#

manipulate the prefab just as u would a sprite. etc

#

its jus a transform

cosmic dagger
#

or use multiple parallax scripts for each layer to move them independently from others. that works if each layer moves at different speeds . . .

raven kindle
#

i have that already

rocky canyon
#

p. p. parallax

#

i always had a rough time making parallax scrolling stuff to be perfect

raven kindle
#

But he is using assets not prefabs

#

and idk how to transform the prefab

rare basin
#

what

queen adder
#

add it as a GameObject variable

#

then modify it like you would any other object

raven kindle
#

i will try

raven kindle
queen adder
#

I'm not sure I'm getting what you're asking

raven kindle
#

or does it have to be prefabs

queen adder
#

you want the layers to come in on say the 2nd loop layer 2?

raven kindle
#

no they start from the beginning

queen adder
#

I have no idea what you mean

raven kindle
#

nevermind

rare basin
#

you should learn what prefabs are

#

@raven kindle

polar acorn
#

Show code

polar acorn
#

Rotation is a quaternion, a four dimensional normalized vector. The x, y, and z values of which have nothing to do with the x, y, and z values of normal euclidian space.

You can get a vector3 representing that orientation with .eulerAngles instead of rotation, but there's an infinite number of vector3s that can represent that quaternion, so it might not match the inspector exactly, but it will at least be a number with three values that are in degrees

raven kindle
#

What do i need to replace transform.position = new Vector3(startPos + dist, transform.position.y, transform.position.z); with to make it transform the prefab instead?

queen adder
#

you'd need to initialize a variable of the prefab, then change them to target that yummy variable

raven kindle
#

how would i do this?

queen adder
#

Do you know how to initialise a normal variable?

#

i.e. a float or boolean

raven kindle
#

yes

polar acorn
raven kindle
#

yes

#

but it doesnt move it

queen adder
#

what Gameobject specifically is it on

raven kindle
#

its on all these

polar acorn
eternal falconBOT
raven kindle
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Parallex : MonoBehaviour {

    private float length, startPos;
    public GameObject cam;
    public float parallexEffect;

    void Start () {
        startPos = transform.position.x;
        length = GetComponent<SpriteRenderer>().bounds.size.x;
    }
    
    void FixedUpdate () {
        float temp = (cam.transform.position.x * (1-parallexEffect));
        float dist = (cam.transform.position.x*parallexEffect);

        transform.position = new Vector3(startPos + dist, transform.position.y, transform.position.z);

        if      (temp > startPos + length) startPos += length;
        else if (temp < startPos - length) startPos -= length;
    }
}
wintry quarry
raven kindle
#

No errors

wintry quarry
#

You sure? Show the console window

raven kindle
polar acorn
#

While the game is playing?

raven kindle
#

it makes the objects in the back move fine,

wintry quarry
raven kindle
polar acorn
raven kindle
#

I mean, when the game is running, the objects move slowly (trees, rocks etc)

#

But when i get to the end of the background, nothing happens

#

It needs to move the old section of the background and move it to the front

#

this happens

wintry quarry
raven kindle
#

i thought i did

#

float temp = (cam.transform.position.x * (1-parallexEffect));

#
if (temp > startPos + length) startPos += length;     
else if (temp < startPos - length) startPos -= length;```
#

Doesn't this do that?

#

@wintry quarry

polar acorn
wintry quarry
#

Idk, did you test if that code is running when you expect it to?

raven kindle
#

ill try

#

when it reaches 50 it should move the background

#

startpos + length is always -1.38

#

for all objects

#

startpos doesnt change for some reason

wintry quarry
polar acorn
#

You don't change it anywhere other than inside these conditions

#

And if you're depending on it changing to enter these conditions that's not going to help much

raven kindle
#

Length is always 0. StartPos is always -1.38. Temp is changing to where the player is

#

When temp is 50, the first background should be moved

#

What do i need to change to make this work?

polar acorn
raven kindle
#

each background has a different point when it needs to be moved

#
        else if (temp < startPos - length) startPos -= length;```
#

I thought this did it ?

polar acorn
#

Okay but where did you get 50 from?

#

You said start pos and length are constant values

raven kindle
sly wasp
#

Ohh ok

polar acorn
#

So plug those in and think about what the code is doing

#

What is -1.38 + 0?

sly wasp
#

So I actually got it working, thanks

raven kindle
#

yes its -1.38

polar acorn
raven kindle
#

the same..

polar acorn
#

So how were you expecting that math to change the value of startPos

raven kindle
#

length needs to be changed?

#

its the size of the gameobject?

#

idk

#

i just followed this

polar acorn
#

Where do you set length

raven kindle
polar acorn
#

So then the size of this objects sprite is 0

raven kindle
#

but surely if temp is > than startpos+length, then startpos would change?

polar acorn
#

Which is 0

raven kindle
#

but it doesnt change

#

right

polar acorn
#

And again, what is -1.38 + 0?

raven kindle
#

yes

#

so how to fix this?

polar acorn
raven kindle
#

so make the camera start not at x=0?

polar acorn
#

What does that have to do with length

raven kindle
#

length = GetComponent<SpriteRenderer>().bounds.size.x;

#

oh

#

he sets the size to 5

#

i didnt realise

polar acorn
raven kindle
#

i dont know

#

thought it was get position

#

or something

polar acorn
#

You should read the code you write

raven kindle
#

but my camera size

#

is also 5

#

yes

#

then where can i change this value in the inspector?

polar acorn
raven kindle
#

bounds.size?

polar acorn
#

Why do you keep going back to the camera

raven kindle
#

where is that?

#

game object inspector

#

i saw size in the video

polar acorn
raven kindle
#

it has nothing to do with camera

#

but where can i change bounds.size?

polar acorn
raven kindle
#

i saw camera at the top of the picture

#

how can i change the value for this?

polar acorn
raven kindle
#

to the size setting in the sprite renderer?

#

gets the width of the sprite

polar acorn
raven kindle
#

i dont see it

#

do i need to make the draw mode tiled?

polar acorn
raven kindle
polar acorn
#

What sprite does this object use

raven kindle
#

lots of different ones

#

i still dont see width

polar acorn
#

Just pick one of your objects with this script. What sprite does it have

raven kindle
#

it has none

polar acorn
#

It's how big your image is

raven kindle
#

ohh

polar acorn
#

What is the width of nothing?

raven kindle
polar acorn
#

So that's why length is 0

raven kindle
#

right

polar acorn
#

Because the width of this object is 0

raven kindle
#

do i need to give it a sprite?

#

or how can i set the width

#

it should be 20

polar acorn
#

Either give it a sprite or don't set length to be the width of the sprite

raven kindle
#

ok

#

it works!!!

#

though when it moves the platform it looks like it skips a bit

wraith wadi
#

I am spawning one object and i have 5 scripts with different movement pattern.
i want this object to adapt 1 script movement depending upon some bool or int value or scene.
do i have to make it's prefeb 5 time and attach each script or is there a better way to do it?

timber tide
#

You can make a unique* prefab for each script if you wish, but otherwise that's fine too

polar acorn
#

transform.forward

queen adder
#

lol

wintry quarry
#

Wdym by "from a local rotation"?

#

And what is "a transform.forward"

#

If you can't explain, we can't answer 🤷‍♂️

gaunt ice
#

transform.forward is in world space
if you need the forward in local space, multiply the rotation with vec3.forward

queen adder
#

use ms paint drawings or gif recordings of strange behaviour if you're struggling to explain

wintry quarry
#

The object's forward direction in its local space is always just Vector3.forward

#

The object's forward in world space is transform.forward

queen adder
#

i thought vector3 forward was just the none relative forward direction

silk night
#

Vector3.forward is world relative
[Transform].forward is object relative

wintry quarry
#

Vector3.forward has no inherent dimensional meaning until it's used in context. It's just the vector (0, 0, 1)

regal bane
#

I'm looking for a ball that moves just like pong in a 3d world but only in the X and Z direction.
Until this point, I did not manage or found to have any good scripts that does just that. I'm getting desperate : / Even chatgpt doesnt know

polar acorn
queen adder
#

ahh, un-confused

summer stump
icy sluice
#
var targetDir = (target.transform.position - rb.position).normalized;
Vector3 forwardDir = rb.rotation * Vector3.forward;

var currentAngleX = Vector3.SignedAngle(Vector3.forward, forwardDir, Vector3.right);
var targetAngleX = Vector3.SignedAngle(Vector3.forward, targetDir, Vector3.right);

var currentAngleY = Vector3.SignedAngle(Vector3.forward, forwardDir, Vector3.up);
var targetAngleY = Vector3.SignedAngle(Vector3.forward, targetDir, Vector3.up);

var currentAngleZ = Vector3.SignedAngle(Vector3.forward, forwardDir, Vector3.up);
var targetAngleZ = Vector3.SignedAngle(Vector3.forward, targetDir, Vector3.up);

float inputX = controller.UpdateAngle(Time.fixedDeltaTime, currentAngleX, targetAngleX);
float inputY = controller.UpdateAngle(Time.fixedDeltaTime, currentAngleY, targetAngleY);
float inputZ = controller.UpdateAngle(Time.fixedDeltaTime, currentAngleZ, targetAngleZ);
Debug.Log($"{currentAngleX}  {targetAngleX}");
rb.AddTorque(new Vector3(inputX * forceAmount * 0, inputX * forceAmount, inputX * forceAmount*0));

curently having problems with angles
if anyone know how to fix it

wintry quarry
icy sluice
#

ik
i cant get SignedAngle to work properly

#

currentAngleY did manage to make it work

wintry quarry
#

I'm not sure what controller.UpdateAngle does

icy sluice
#

thats a pid controller

#

that works fine

wintry quarry
#

Something like this is what I'd do:

Vector3 dir = target.transform.position - rb.position;

// Optional, if you want to rotate only on the y axis:
dir = Vector3.ProjectOnPlane(dir, Vector3.up);

Quaternion target = Quaternion.LookRotation(dir);
Quaternion current = rb.rotation;

Quaternion diff = target * Quaternion.Inverse(current);
Vector3 eulers = diff.eulerAngles;
// plug eulers into your PID controller here if you want

// add the torque
rb.AddTorque(forceAmount * eulers);```
#

not sure how to integrate it into your pid controller

#

maybe just using eulers

#

Probably would be cleaner if it worked directly with quaternions though

icy sluice
#

i need a current angle(gameobject angle)
and target angle

#

and it does pid stuff to turn it

#

i need it for realistic missles

queen adder
#

what type of missile you modelling

icy sluice
#

dont worry about pid controller, giving input to pid controller is a problem here

queen adder
#

IR air to air style?

icy sluice
#

ye

queen adder
#

that's a lot of vector math

icy sluice
#
var currentAngleX = Vector3.SignedAngle(Vector3.forward, forwardDir, Vector3.right);
var targetAngleX = Vector3.SignedAngle(Vector3.forward, targetDir, Vector3.right);

var currentAngleY = Vector3.SignedAngle(Vector3.forward, forwardDir, Vector3.up);
var targetAngleY = Vector3.SignedAngle(Vector3.forward, targetDir, Vector3.up);

var currentAngleZ = Vector3.SignedAngle(Vector3.forward, forwardDir, Vector3.up);
var targetAngleZ = Vector3.SignedAngle(Vector3.forward, targetDir, Vector3.up);

this is the main problem

#

the SignedAngle's

gleaming wagon
#

Does anyone know why my text isn’t appearing? I tried adjusting the font size but it isn’t apearing

idle pike
#

Are you sure TextMeshPro is downloaded? I had the same problem and I removed, then added the component again and it automatically opened an install prompt.

wintry quarry
gleaming wagon
gleaming wagon
#

only this specific one it doesnt

idle pike
#

Could be the scale of a parent object that's messing with it as well. But yeah probably not coding related.

wintry quarry
#

is this a world space canvas or something else

gleaming wagon
queen adder
#

turn off autosize and try playing with the size

gleaming wagon
wintry quarry
#

you should generally not be scaling UI at all

gleaming wagon
polar acorn
#

The scale of every canvas element should be 1,1,1

gleaming wagon
idle pike
#

Change the size parameters instead (width/height)

polar acorn
gleaming wagon
#

thats the text

polar acorn
polar acorn
summer stump
near cove
#

so if i have 4 points defining 2 segments, (x1, y1) to (x2, y2), and (x3, y3) to (x4, y4)
how would i write code that calculates if those two segments intersect each other?

#

(thats for a linerenderer script btw)

gleaming wagon
#

Every UI in my canvas

#

Oh I figured it out

gleaming wagon
wintry quarry
silver salmon
#

something is broken?

#

game runs

wintry quarry
gleaming wagon
#

I have a question, can I have 2 different post processing volumes that affect different objects? Or different cameras?

silver salmon
gleaming wagon
summer stump
near cargo
#

Hello! for some reason when I run my game in the editor, the audio mixers seems to be global, but when I build the game the mixer volumes seems to reset on every scene, this is how I am writing the mixer volume. In the editor I can verify the volume stays consistent in every scene but in my builds the volume resets to 0 every time on every scene, also I can verify both Debug.Log's get called in development builds (volume doesnt stay consistent still)

public class SettingsUI : MonoBehaviour
{
    public AudioMixer audioMixer;
    public Slider effectsVolumeSlider;

    public void Start()
    {
        if (PlayerPrefs.HasKey("effectsVol"))
            effectsVolumeSlider.value = PlayerPrefs.GetFloat("effectsVol");
        else
        {
            PlayerPrefs.SetFloat("effectsVol", 1);
            effectsVolumeSlider.value = PlayerPrefs.GetFloat("effectsVol");
        }
    }

    public void SetVolume(float volume)
    {
        float debugVol;
        Debug.Log("Setting volume to " + volume);
        audioMixer.SetFloat("effectsVol", volume);
        PlayerPrefs.SetFloat("effectsVol", volume);
        audioMixer.GetFloat("effectsVol", out debugVol);
        Debug.Log("effectsVol Float Value: " + debugVol);
    }

    public void GoBack()
    {
        SceneManager.LoadScene("MainMenu");
    }
}
craggy bane
#

yo how do i add a timer on my quest script

desert elm
#

I have been advised to use Vector.Normalize by a friend, but I still do not understand how it works
Isnt a Vector value a single point? how can it have direction or lenght?

craggy bane
#

!code

eternal falconBOT
fossil tree
#

hi i have maybe a dumb question but can i take every single composent of this picture with unity if yes how?

craggy bane
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class QuestGiver : MonoBehaviour
{


    public Quest quest;

    public Player player;

    public float timerDuration;
    
    

    public GameObject questWindow;
    public Text titleText;
    public Text descriptionText;
    public Text RepText;
    public Text OctoSnackText;
    public Text TimerText;

    public void OpenQuestWindow()
    {
        questWindow.SetActive(true);
        titleText.text = quest.title;
        descriptionText.text = quest.description;
        RepText.text = quest.RepReward.ToString();
        OctoSnackText.text = quest.OctoSnackReward.ToString();
        TimerText.text = quest.Timer.ToString();


    }

    public void AcceptQuest()
    {
        questWindow.SetActive(false);
        quest.isActive = true;
        player.quest = quest;
    }
    
    public void DeclineQuest()
    {
        questWindow.SetActive(false);
        quest.isActive = true;
    }

   public void OnTimerFinish()
    {
        StartCoroutine(TimerRoutine());
    }

    IEnumerator TimerRoutine()

    {

        yield return new WaitForSeconds(timerDuration);
        quest.OnTimerFinish();
        Debug.Log("Timer Finished");
    }


}
#

quest.OnTimerFinish();

#

'Quest' does not contain a definition for 'OnTimerFinish' and no accessible extension method 'OnTimerFinish' accepting a first argument of type 'Quest' could be found (are you missing a using directive or an assembly reference?)

#

How do I fix this issue

craggy bane
#

I'm trying to make a timer on a quest script

fossil tree
rich adder
polar acorn
verbal dome
#

Why are you crying

craggy bane
#

NEOM

rich adder
#

how could you be using something that dont exist

polar acorn
craggy bane
#

I'm sorry cuh

#

i just fixed it

#

thanks

#

dawg now its saying The type 'QuestGiver' already contains a definition for 'OnTimerFinish'

wintry quarry
#

Probably a duplicate script

polar acorn
#

Or two functions in one class

wintry quarry
fossil drum
# desert elm I have been advised to use Vector.Normalize by a friend, but I still do not unde...

A Vector3 is 3 floats. So for example transform.forward is 0, 0, 1.
So its a vector3 of length 1, that points forward. You can also have 0, 0, 500 of course.
That's a vector3 of length 500 that also points forward.
Lets say you move left and forward, so you press A and W, and force that into a vector, which is -1, 0, 1.
You want to normalize this, because you don't want the vector to be longer then 1, then you get ~-0.71, 0, 0.71. This is also the reason why old games move faster diagonally, because they don't normalize the input vector.

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

[System.Serializable]
public class Quest
{
    public bool isActive;

    public string title;
    public string description;
    public int RepReward;
    public int OctoSnackReward;
    public int Timer;
    

}
#

this is the quest script

craggy bane
polar acorn
wintry quarry
craggy bane
#

it goes here as int or what

polar acorn
#

Or "Method" I guess if you wanna be technical

craggy bane
#

how am i being tehnical gang

#

technical

polar acorn
#

That was a comment towards anyone else who felt like correcting my terminology

polar acorn
#

Because technically C# doesn't have functions, it has methods

craggy bane
#

👍

#

so ontimerfinish goes in quest script

#

gotcha

polar acorn
#

I thought you said you fixed it

craggy bane
#

i fixed it then it gave me this

#

(51,9): error CS0102: The type 'QuestGiver' already contains a definition for 'OnTimerFinish'

polar acorn
#

So where's the function

craggy bane
#

its been 6 minutes just explain to me like im a baby learning his alphabet

polar acorn
craggy bane
#

and where will this ontimerfinish exist

#

and what will it exist as

polar acorn
#

Where do you want it and what do you want it to do

craggy bane
polar acorn
desert elm
craggy bane
polar acorn
ivory bobcat
polar acorn
#

If you want to do that, it has to exist

#

So, why are you trying to call Quest's function if you wanted it to be on the quest giver

craggy bane
#

do I need to make like a seperate quest script with the name quest time

polar acorn
fossil drum
polar acorn
#

it has to exist

#

that's it

craggy bane
#

ok bro

#

thanks for the advice

ivory bobcat
#

What're you trying to do on that line?

craggy bane
#

have a good day bro

polar acorn
#

You're calling a function OnTimerFinish on the Quest object. Quest does not have a function OnTimerFinish

craggy bane
#

Yes cuz someone told me to gang

polar acorn
#

So, instead of trying to call a function that doesn't exist

craggy bane
#

forget that

fossil drum
craggy bane
#

so just call it on questgiver

polar acorn
#

Either
A) make it exist
or
B) don't call it

desert elm
fossil drum
desert elm
#

something like this
ab is the centre of the circle, x, y is the random point created by the first modification

fossil drum
desert elm
#

oh
thank you!

silver salmon
#
Debug.Log("Welcome to the");
fossil drum
#

And sure you could do what your friend told you.
Just have an random x value, random y value between -1 and 1, make a vector 2 out of it, normalize it and multiply that vector with a random value.
Then add your original a, b to that.

desert elm
#

Okay, that helps me a lot- could I just
then create the random point, then add a, b to it?

fossil drum
desert elm
#

yep, thats it, thanks

desert elm
fossil drum
silver salmon
#

!vc

eternal falconBOT
#
Using version control in Unity

Unity Version Control

git Git

Get the latest .gitignore file from here. It should be placed at the root of your Unity project directory.

vast vessel
#

hi lads, i have something weird going on, i have a physics.raycast that hits a big collider, but it returns the collider on its parent game object, even though im shooting at the smaller collider, any way i can fix this?

#

here ive sent the hirearchy of the gameobjects, their colliders, my code and the debug resaults

#

i know it looks overwhelming but its not a lot trust me

#

in short : raycast hits object B, returns object A. object B is a collider that is a child of object A

verbal dome
vast vessel
#

whats the diffrance?

verbal dome
#

hit.transform and hit.rigidbody refer to the object that has the rigidbody

vast vessel
#

why would transform give me the rigidbody?

#

that seems weird

polar acorn
#

A rigidbody sort of "claims" all colliders on it or child objects. This allows a rigidbody to have complex shapes without needing a high fidelity mesh collider, and gives you a way to differentiate parts of the object

verbal dome
#

It doesn't give you a rigidbody, just the transform of thet object that has it

polar acorn
#

If an object has a rigidbody, it becomes responsible for handling raycasts and other physics queries

#

for example, if you have a headshot hitbox, you still want the player's rigidbody to be the one that reports the hit, so you can call a function on that player

pulsar lodge
#

https://gdl.space/rijopuqahi.cs Can anyone help me, I am trying to load different backgrounds based off of the scene my character was previously in, I've tested and the SceneIndex is getting passed correctly through my scriptable object. My issue is when the battle starts the background is all white, i'm guessing it cannot find the refence image.

#

I have tried the full file path but thats not working

polar acorn
wraith wadi
pulsar lodge
polar acorn
# pulsar lodge Thats probably my issue then, its not in the resources folder.
Unity Learn

This is a series of articles that provides an in-depth discussion of Assets and resource management in the Unity engine. It seeks to provide expert developers with deep, source-level knowledge of Unity's Asset and serialization systems. PLEASE NOTE: this tutorial has now been deprecated. We now recommend using Addressables for your projects and ...

pulsar lodge
#

So i have them in there now,

minor roost
#

i have a tetris game but when a piece is at the bottom it can still move side to side

eternal falconBOT
minor roost
#

piece system here

minor roost
rich adder
minor roost
#

no?

polar acorn
#

and moveTime is only ever changed if valid is true

#

So see if that's being read as true when you don't expect

minor roost
#

huh

rich adder
minor roost
#

dam

#

so what do i change

minor roost
#

ty

steel forge
#

https://pastebin.com/GNFPqzAP
It doesn't register collisions and idk why. I have a spike set to trigger and a triggerbox around my character. At the beginning of the scene (When I start it) it registers the first debug log, but never again. Neither when colliding with smth that is a trigger or wehn colliding with smth. that isn't.

rigid kite
#

Hello, Im trying to save my game with binnary. I followed a tutorial about it and i tried to not change anything.


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


[System.Serializable]
public class DersData
{
    public bool[] dersDurumu;

    public DersData()
    {
        dersDurumu = new bool[10];
    }
}



public static class SaveSystem
{
    
    public static void Save(DersData ders)
    {
        BinaryFormatter formatter = new BinaryFormatter();
        FileStream fs = new FileStream(GetPath(), FileMode.Create);
        formatter.Serialize(fs, ders);
        fs.Close();
    }
    public static DersData Load()
    {
        if (File.Exists(GetPath()))
        {
            BinaryFormatter formatter = new BinaryFormatter();
            FileStream stream = new FileStream(GetPath(), FileMode.Open);
            DersData data = formatter.Deserialize(stream) as DersData;
            stream.Close();

            return data;
        }
        else
        {
            Debug.LogError("Save file not found in" + GetPath());
            return null;
        }
    }

    private static string GetPath()
    {
        return Application.persistentDataPath + "/dersData.qnd";
    }
}



using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DerslerScript : MonoBehaviour
{
    [SerializeField] List<Button> dersler;

    public DersData data;

    
    private void Awake()
    {
        data = SaveSystem.Load();
        print(data);

    }

    public void YaptiYapmadi(int index)
    {
        if (dersler[index].image.color == Color.red)
        {
            dersler[index].image.color = Color.green;
            data.dersDurumu[index] = true;
        }
        else
        {
            dersler[index].image.color = Color.red;
            data.dersDurumu[index] = false;
        }
    }
}


#

When I save the game there is no problem. But when I try to load i get this error:

SerializationException: End of Stream encountered before parsing was completed.

calm coral
#

What tutorial did you watch? From like 1995 ?

rigid kite
#

No like 2021

#

I'll build to android

#

I tried to watch a tutorial for PC too but I don't know if it's can be used to android. so i just found a new tutorial.

solemn fractal
#

hey guys, any tips on how to do that movement with my enemy? like passing by the player next to it, and going outside the view, and coming back other sice, almost in a straight line? not in a circle.

calm coral
rigid kite
#

Thanks I'll try it.

steel forge
solemn fractal
steel forge
# steel forge https://pastebin.com/GNFPqzAP It doesn't register collisions and idk why. I have...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Die2Piks : MonoBehaviour
{
    // Start is called before the first frame update
    public GameObject Player;
    public Vector3 Startposition;
    // Update is called once per frame
    private movement Moving; 
    void Awake(){
         Moving = GetComponentInParent<movement>();
    }    
    private void OnTriggerEnter(Collider other)
    {
        Debug.Log("Ded Trigger 1");
        if (other.gameObject.CompareTag("Death"))
        {
        Debug.Log("Ded Trigger 2");
        Moving.enabled = false;
        Debug.Log("Ded Trigger 3");
        Player.transform.position = Startposition;
        Debug.Log("Ded Trigger 4");
        StartCoroutine(enable());
        }
    }
    IEnumerator enable()
    {
        yield return new WaitForSeconds(1);
        Debug.Log("Ded Trigger 5");
        Moving.enabled = true;
    }
}```
easier to read if you can help
wraith wadi
#

is there a YouTube tutorial that explains or teaches working with lights and glow for absolute beginners? or a document?

verbal dome
#

Light flares exist also

steel forge
cosmic dagger
polar acorn
solemn fractal
steel forge
polar acorn
verbal dome
steel forge
steel forge
#

no, only a player controller

polar acorn
steel forge
polar acorn
steel forge
polar acorn
ivory bobcat
#
Debug.Log($"{name} was triggered by {other.name}", this);```
steel forge
verbal dome
steel forge
steel forge
polar acorn
faint sluice
#

Commandments are eternal

steel forge
#

thx

winter cedar
#

its giving me null

rich adder
#

If not You have a copy somewhere

#

either output doesn't have a textmeshpro on it

#

you 're probably looking for a TMP_Text, You have to show more context

winter cedar
#

someone know how to fix this?

polar acorn
eternal falconBOT
winter cedar
#
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class ReadInput : MonoBehaviour
{
    public string input;
    public Button gameb;
    
    public void Readstringinput(string s)
    {
        
        input = s;
        Debug.Log(input);
       
    }
}
winter cedar
#

yup

polar acorn
#

Run it again

winter cedar
#

ok

#

so its not giving me a error but its not showing the text I put in the input field

polar acorn
winter cedar
#

ohh ok\

rich adder
#

what about the Log?

chrome storm
#

hello i used a code from chatgpt and theres an error that says "the type namespace "IEnumerator" caannot be found"

#

ive never heard of a IEnumerator what is that

foggy void
#

show code

#

put in code block please 🙂

chrome storm
#

😅 k

#

i feel like your disapointed that i used chatgpt..

rich adder
#

yes because it probably didn't mention about namespaces

muted wadi
#

chatgpt sucks at coding

rich adder
#

its spam generator

muted wadi
#

yup

chrome storm
#

i just wanted to see what it does

muted wadi
#

even when you ask it to explain what parts of code do, it can still get it wrong

chrome storm
#

because i failed

#

XD

rich adder
rich adder
chrome storm
#

alright scrap chatgpt

muted wadi
#

you can make it work if you want to quickly solve some very small beginner queries, but anything more is impossible for chatgpt

rich adder
#

just goes iterates through a collection

#

but unity did some black magic and made it some async thing

chrome storm
#

the code i did yesterday i believe it work its the "inspector bar" thats wrong but i dont get what

muted wadi
#

question: is starting a coroutine within a coroutine a good idea?

muted wadi
#

ok good, i thought maybe it's really expensive to run

#

or just really inefficient

rich adder
#

but its pretty normal to StartCoroutine from another coroutine

muted wadi
#

yeah one of my teachers advised me to be careful about how many updates i use and how to be more efficient

foggy void
#

Very useful, if you are a student in highschool I highly reccomend it. (Dont use it as a tool, use it as a friend to ask questions and learn 🙂 )

rich adder
eternal needle
muted wadi
foggy void
#

Alongside with a shit ton of other benefits

muted wadi
#

im in uni but i dont think our campus has copilot as a free thing

#

hell they barely even have adobe

foggy void
#

Doesn't matter if your campus does it or not

rich adder
#

you can probably get it still thru Github

foggy void
#

Github regardless of if campus agrees allows you to signup

#

Just need some form of POE (proof of education)

#

like student id works

muted wadi
#

oh interesting

foggy void
#

(best thing is student id)

rich adder
#

abuse it while you can

foggy void
#

others are hard to get in with

chrome storm
#

rq

muted wadi
#

it felt kind of cheaty though

chrome storm
#

i think it is

muted wadi
#

using chatgpt

foggy void
#

It is cheaty using ai, that's why I use it as a friend not a tool. Don't get addicted to it, learn off of it.

chrome storm
eternal needle
foggy void
#

does it compile? probably

foggy void
rich adder
#

just like cheating you won't learn anything

#

then you have to fake it to make it your whole life

muted wadi
#

i never want to cheat my way through with chatgpt because its so short sighted, learning it yourself is much more fulfilling

foggy void
#

thats why you limit yourself and dont ask it straightforward questions

near cove
#

for some reason i cant get this oncollisionenter to work

#

can someone help troubleshoot

foggy void
#

Okay well that is oncollisionexit..

#

not enter

near cove
#

i mean collision exit

timber tide
#

case closed

near cove
#

it doesnt work still

foggy void
#

case closed

#

done

#

thats a wrap

near cove
#

bro no its a collision exit and it doesnt work. when my object leaves the other collider its doesnt reload the scene

short hazel
#

Place a log in that, does it execute?

near cove
#

imma try

#

no logs

short hazel
#

It's weird how the method name is a bit grayed out, but maybe it's just the analyzer reporting incorrectly

foggy void
# near cove no logs

Check in 3d view that they are actually going to touch? Does that matter? I don't know

polar acorn
near cove
#

yeah it says "unused method"

#

object1 has polygon collider

#

object 2 has a collider and a rigibody

#

dont see whats wrong tbh

polar acorn
#

Show the full !code

eternal falconBOT
muted wadi
#

im trying to make a coroutine where an object moves to the positions of game objects inside a list until it reaches the end. This is what I have so far but im not sure if im on the right track. The way I think this is working is that for every object inside hitList a coroutine is being started in which the object will move to that position and once it has reached close enough to that position, a boolean will be returned which tells the previous coroutine to do the same for the next object. Is this correct or am I wrong?

{
    for (int i = 0; i < hitList.Count; i++)
    {
        cr = StartCoroutine(MoveToEnemyPositions(i));

        yield return cr;
    }
}

IEnumerator MoveToEnemyPositions(int currentPos)
{
    

    yield return null;
}```
rich adder
near cove
polar acorn
muted wadi
rich adder
muted wadi
#

so I shouldn't use the second coroutine for this?

rich adder
#

don't see a purpose for it

muted wadi
#

i had a problem earlier where the objects were moving so vector3 didn't work, but i changed the object so this shouldn't an issue anymore

muted wadi
#

sorry im rambling

rich adder
#

that would be the first step

muted wadi
rich adder
muted wadi
rich adder
#

are you controlling multiple objects?

muted wadi
#

no just one, think of it as a ball

rich adder
#

ok so it doesn't need for loop

muted wadi
#

im confused

#

my impression is that when the coroutine starts, the ball will do a thing for each item within the list

rich adder
#

rinse and repeat

muted wadi
#

the problem is that i dont know how many points will be in the list when the coroutine is started

rich adder
#

its not the only ofc you can literally just give it a list of tasks to do , there are many ways to do something

muted wadi
#

would it be okay if i explained what im trying to do a bit more so there's no confusion?

rich adder
#

lets make a thread

muted wadi
#

sure

alpine wraith
#

can someone explain the following error to me?
Main Camera: 1 camera overlay no longer exists and will be removed from the camera stack.
I was using 2 overlay cameras (screenshot 1), and as soon as I enter play mode one of them is gone... (screenshot 2)

#

the error comes from the "Universal Additional Camera Data" script in line 462. (not written by me but added to cam automatically)

north kiln
#

Is it an error

#

Or is it just a log saying that it removed the camera from the stack? Presumably because you're Destroying it somehow

modest barn
#

I've been struggling for weeks with MonoBehaviour instantiation but I've always just ended up finding workarounds, but now I'd really just like to use new() to create a new object of a script, but I can't because that script inherits from MB. Can someone just really quickly guide me through how I can imitate this exact behaviour but with AddComponent() or whatever other method I need to use?

polar acorn
north kiln
polar acorn
#

Add the component to the object you want to

covert cairn
#

I'm trying to instantiate a prefab from a scriptableObject but for some reason it's giving a NullReferenceException. I have everything assigned in the inspector so I'm having a hard time figuring out where it's going null.
The line that instantiates it but throws an error is: Instantiate(weapon.equipment);
and the class it pulls from is written like this:
public class EnemyWeapons : ScriptableObject
{
public GameObject equipment;
public Vector3 weaponPos;
public float fireRate;
public int bulletsPerShot;
}

modest barn
polar acorn
timber tide
modest barn
#

Would it, in that case, matter where I put the component?

modest barn
#

It is so that I can do this

polar acorn
#

why are you trying to add it to another object?

covert cairn
modest barn
#

I don't want to add it to another object I just want to grab a public variable from inside it (non-static) for which I of course need an object reference

polar acorn
#

if you don't want to add it to another object

modest barn
#

I just wanted to use new() to create an instance to get that variable

#

Literally all I want to do is get that variable from the other script

polar acorn
#

you have an instance

#

use that

modest barn
#

Sorry, I'm new to Unity. Does having the script as a component on an object instantiate it?

rich adder
#

of the script

modest barn
#

Oh

#

How do I access that instance?

rich adder
#

GetComponent usually

modest barn
#

Serialize the Main gameobject?

rich adder
#

yeah when possible always make fields in the inspector, and assign that way

modest barn
timber tide
#

in that order

modest barn
#

So let's say I'm going to [SerializeField] GameObject main (that's how I would do it, right?), how would I access the script that is a component of that GameObject?

rich adder
polar acorn
rich adder
#

^ this. Every Monobehaviour has access to their own gameObject& transform already

covert cairn
polar acorn
summer stump
covert cairn
polar acorn
covert cairn
#

but weapon.equipment isn't null

modest barn
#

So I have a GameObject, which has a component that is a script, that contains a public variable that I need to access. How would I [SerializeField] a component of a GameObject? I didn't know that was possible.

covert cairn
#

that's why I'm confused

timber tide
#

Don't always trust the inspector. Always debug your values

north kiln
#

That screenshot doesn't show weapon

polar acorn
covert cairn
summer stump
covert cairn
#

this does

polar acorn
rich adder
polar acorn
#

It does not show that every instance of this script does

#

log it

modest barn
#

Got it, thank you. I didn't even know you could drag and drop components from the Inspector! I have a loooot to learn 🤦 Thank you all for the help

covert cairn
polar acorn
#

Log it

summer stump
polar acorn
#
Debug.Log($"{gameObject.name}'s weapon is {weapon}",this);
#

Log it

covert cairn
polar acorn
covert cairn
#

omg

#

i'm so dumb

#

I dragged it onto my canvas at some point

#

💀

#

i'm offically quitting gamedev

polar acorn
#

This is why you always check

#

The errors can not lie. If it says you have one of these scripts with weapon null, then you do. It's up to you to find out where

covert cairn
#

Fair enough I just assumed I had perfect knowledge of my scene

#

I guess I just accidentally dragged it to the wrong thing at some point

#

ok thx

alpine wraith
boreal tangle
#
private bool isGrounded()
    {
        RaycastHit2D hit = Physics2D.BoxCast(coll.bounds.center, coll.bounds.size, 0f, Vector2.down, 0.1f);



        Debug.Log(hit.collider.gameObject);

        return hit.collider != null;
       
    }
#

does someone know why the boxcast hits the player instead of the ground

north kiln
boreal tangle
#

but I directioned the cast down so it should it the ground

muted wadi
#

i keep getting this error but I have no idea why, can anyone help me understand what might be causing it? Full script here https://hastebin.com/share/azizoyikuw.csharp

#

everything in the coroutine has a reference to my understanding, really stumped

north kiln
#

Check the values and see which one is null

muted wadi
#

how do i do that?

north kiln
#

Using the debugger, or logging

muted wadi
#

which value should i be checking exactly?

strong path
#

im trying to make an animation start thru collision of a box collider and the animation just won't play

#

could it be a code problem?

north kiln
muted wadi
#

so everything in the coroutine that can be null?

north kiln
#

If you're confused, go through the resource I linked

strong path
# strong path could it be a code problem?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AnimTrigger : MonoBehaviour
{
    [SerializeField] public GameObject player;
    [SerializeField] private Animator anim;

    void OnTriggerEnter(Collider col)
    {
        if (col.gameObject == player)
            anim.Play("LiamWalk");
    }
}```
muted wadi
strong path
#

wdym

muted wadi
#

so the object that has this script should have a collider component

north kiln
muted wadi
#

is the option "IsTrigger" on that component ticked?

strong path
strong path
north kiln
#

Go through the physics message debugging resource that is pinned to this channel

#

it should become clear pretty quickly what you've done wrong

strong path
muted wadi
#

@north kiln im trying to debug stuff but i dont really know what im doing even after reading the thing you sent

strong path
#

OH MY GOD

#

IT WASNT 2D

#

THANK YOU

fathom ether
#

Whats the best way to implement a messages log box with a max amount of messages?
Something similar to the picture is what im looking for

muted wadi
#

how do i know what thing i should be debugging?

north kiln
muted wadi
strong path
#

LETS GO

muted wadi
#

apparently thats the method

muted wadi
#

lockOn is the class

rich adder
#

MoveNext, sounds like a coroutine

north kiln
strong path
# strong path LETS GO

only problem is he still starts his animation on his own automatically even though "Play Automatically" is ticked off, what do i do

muted wadi
#

and then BailiffMove is the coroutine, but i dont have MoveNext anywhere in my code

muted wadi
muted wadi
north kiln
#

if (Vector3.Distance(throwB.newBall.transform.position, hitList[currentHit].transform.position) < 0.8f)

#

You have changed your code since that error

muted wadi
north kiln
#

throwB throwB.newBall hitList hitList[currentHit], one of these is null at some point

rich adder
#

where did you assign throwB

muted wadi
#

throwB is a reference to a class, its at the very top of the script

muted wadi
north kiln
#

That's a declaration, not a reference

muted wadi
#

oh sorry

rich adder
#

where did you assign

muted wadi
#

im not sure i understand

north kiln
#

Though, I have no idea how it got to line 40, surely DiscThrow is a struct if it got there?

muted wadi
#

let me send the discThrow script too

rich adder
muted wadi
rich adder
#

ok so where did you do that

#

for throwB

muted wadi
rich adder
#

🤔

muted wadi
#

oh wait

#

is it because its private

rich adder
#

you just said = assigns something, this isn't assigning

muted wadi
#

christ im dumb

rich adder
muted wadi
strong path
muted wadi
#

surely it just needs to be declared and thats all?

rich adder
#

DiscoThrow is meerly a blueprint

muted wadi
polar acorn
rich adder
#

there can be 1 or 0 or millions, it makes no difference to the computer

#

it wants to know which one of these you wanna get/set this variable from

#

it would be kinda counterproductive if it magically plugged itself in

muted wadi
#

okay lets assume that its newBall because an object is being instantiated there

#

how would I specify which newBall i want to reference?

rich adder
#

you're assigning a new ball to an object that doesn't exist

#

maybe brush up on what an actual instance is

muted wadi
#

am i misunderstanding what an instance is?

rich adder
#

you're probably confusing it with Unity's Instantiate which is somewhat similiar

muted wadi
#

what is the difference between Instantiate and an instance?

#

i thought they were linked

rich adder
#

In regular cSharp you have to create an object from the blueprint (class) you defined

#

thats an instance

#

MyClass foo = new()

foo.Something()
foo is the instance itself

#

in unity a script is a component which creates an instance when its on a gameobject

#

so you can't new() monobehavior classes

muted wadi
#

i understand a script is a component

#

but how does it create an instance when its on a gameobject?

rich adder
muted wadi
#

i think i understand monoBehaviour, its inheriting values from another class called monoBehaviour

rich adder
muted wadi
#

yeah

rich adder
#

yea : inheriting

muted wadi
#

my lockOn class is inheriting certain values from MonoBehaviour

rich adder
#

properties and methods

muted wadi
#

right

rich adder
#

so whoever has LockOn script on they have that instance

strong path
#

do animations always start by themselves

#

no matter what i do

rich adder
strong path
#

i need my sprite to stop animating as soon as i start the game

muted wadi
#

so then i dont understand, why am i getting an error for newBall even though it hasn't been instantiated yet?

strong path
#

but i have no clue what im doing wrong

rich adder
rich adder
strong path
rich adder
strong path
#

is my animation tree the problem

rich adder
#

that component has a mind of its own lol

muted wadi
rich adder
#

you need to make states inside your Animator

strong path
#

oh

rich adder
#

they're just blueprints to an object

strong path
#

or bool?

rich adder
#

follow some beginnner courses on animator

muted wadi
# rich adder Scripts are not objects

im really confused. The way I see it, the newBall variable in the DiscThrow script is being assigned the discPrefab object. What doesn't work there?

rich adder
muted wadi
rich adder
#

you have to understand the difference between references and declaring

polar acorn
muted wadi
polar acorn
summer stump
rich adder
#

is throwB throwing null btw

polar acorn
#

Actually yeah

muted wadi
polar acorn
#

Where is throwB being assigned

muted wadi
#
{
    public GameObject discPrefab, newBall;```
rich adder
#

they know that assigning is = but somwhow this is missing the spot

summer stump
#

That is a declaration, not assignment. Just to be clear

polar acorn
muted wadi
polar acorn
summer stump
polar acorn
rich adder
summer stump
rich adder
#

you literally have to do the same thing except that Unity has option to also use inspector, but not if the field isn't serialized to expose it and assign it there.. @muted wadi

muted wadi
#

okay so

#

i think im going insane

polar acorn
summer stump
#

Just show the inspector for the object already

rich adder
#

like telling someone I have a have a party at my House and guest ask where is your house, and you reply.. "House"

polar acorn
#

Where do you tell the code which GameObject throwB is

muted wadi
polar acorn
#

What object is in it

teal viper
#

Time to go learning some C#/unity basics!🪄