#💻┃code-beginner

1 messages · Page 44 of 1

slender nymph
#

alternatively, if you just want to check if something is in that space and don't need access to the colliders just use a CheckBox instead of OverlapBox

lusty socket
#

Does any object in the array have any part of its bounding box intersect with the bounding box of the given box?

#

i think thats right

wintry quarry
#

you're asking if there are any intersecting colliders.
The function you're using returns an array of intersecting colliders.

A Collider[] is not a true/false (aka bool)

lusty socket
# polar acorn

so its just asking is any other colliders overlapping?

#

with the box

wintry quarry
#

no it's asking which colliders are overlapping

#

and gives you an array containing all such colliders

lusty socket
#

so what do i need to add to this line of code in that respect then?

wintry quarry
#

think about it

wintry quarry
#

how do you go from an array of colliders to an answer to your question "are there any colliders"?

#

what would that array look like if there are no such colliders?

#

what would it look like if there is at least one collider?

short hazel
#

Alternative:
Use Physics.CheckBox() if you don't care about which colliders it detected, just if it detected anything. Returns a bool, so should be compatible with your method.

lusty socket
#

I understand the second question being no and the third question being yes, but the first question is just kinda going over my head

wintry quarry
lusty socket
wintry quarry
#

I'm asking how you would write code to determine that

#

and yes SPR2 is correct and you should be using that instead, but if that didn't exist, you should be able to figure out how to use OverlapBox

lusty socket
summer stump
#

How would compare the integer value to turn it into a bool?

#

Arrays have a length property to see how many elements are in it btw, if that is the part you are struggling with

green copper
#

do I need to do something special to make it "remember" the variable from the previous loop?

wintry quarry
#

you'll need to account for the case when selectedObject was not assigned yet, yes

green copper
#

Ohhh DUH

#

oops

wintry quarry
#

the variable already remembers from the previous execution, that's the point of the variable

green copper
#

sorry

lusty socket
#

return Physics2D.OverlapBox(coll.bounds.center, coll.bounds.size, 0f, jumpableground); so is that right? as there is 0

wintry quarry
#

you can't interchange them

lusty socket
#

sorry i didnt mean to add the 2d id just hit the wrong one, i meant Physics

#

return Physics.OverlapBox(coll.bounds.center, coll.bounds.size, 0f, jumpableground);

#

that is what i meant

wintry quarry
summer stump
wintry quarry
#

think about what OverlapBox returns

lusty socket
wintry quarry
summer stump
#

Damn, too slow

wintry quarry
#

I'm not even really sure which Vector2 you're talking about, but it doesn't matter much

wintry quarry
lusty socket
#

i thought thats the issue because when changing boxcast to overlap box the error was cant convert vector2 to int

wintry quarry
#

This was the error

#

Cannot convert Collider[] to bool

autumn briar
#

Does Unity require .NET framework?

summer stump
lusty socket
summer stump
#

How would you turn that into a bool

#

What comparison would you make?

lusty socket
#

is there any colliders in the box

summer stump
#

Yeah... and what comparison operator would you use?

lusty socket
#

= 0

wintry quarry
#

and what things would you actually be comparing?

#

what do you want to compare to 0?

summer stump
lusty socket
#

the integer value and the bool is what we are comparing

wintry quarry
lusty socket
#

how many colliders are in the box

wintry quarry
#

there's an array of colliders

wintry quarry
#

we have an array of colliders

lusty socket
#

i think thats throwing me

wintry quarry
#

but it's also completely irrelevant

#

ignore what's inside there

#
bool MyFunction() {
  Collider[] colliders = Physics.OverlapBox(/*stuff that doesn't matter*/);
  return ??? // << what goes here?
}```
lusty socket
#

i see

wintry quarry
#

what do we put in place of the ???

#

we have an array of colliders called colliders, which contains all of the colliders that are in the box

#

we want to know if there was something or nothing in the box

#

what do we do?

lusty socket
#

collider length

wintry quarry
#

Good!

lusty socket
#

needs to me more then 0?

wintry quarry
#

yes!

lusty socket
#

return colliders.Length > 0;

#

so itd look like that

wintry quarry
#

yes!

#

that will return true if there are colliders in the box

#

false if there are no colliders in the box

lusty socket
#

private bool IsGrounded()
{
Collider[] colliders = Physics.OverlapBox(coll.bounds.center, coll.bounds.size, 0f, jumpableground);
return colliders.Length > 0; // << what goes here?
}

#

so this should be correct?

summer stump
#

Should be, try it

lusty socket
#

Argument 3: cannot convert from 'float' to 'UnityEngine.Quaternion'

#

i get that errpr from the 0f

polar acorn
lusty socket
#

do i need to change that to Quaternion.identity

polar acorn
#

I sent you the documentation for OverlapBox that shows what parameters it expects and in what order

lusty socket
#

or am i on a completely different track

summer stump
lusty socket
#

doesnt even react to the space bar being pressed and loops the jump animatio from srat to finish

#

added a debug to the jump and its like the jump isnt even being registered anymore

weary crystal
#

Why does my pc crashes when I save a script in Visual Studio? My whole pc like hangs and crashes.

#

It doesn't happens everytime but most of the time, yes.

#

And also my Unity runs as an administrator everytime, I've checked properties and everything. Is there anything I can do instead of create a new standard user account?

dense palm
#

Hi! Is there a way to use Rigidbody2D physics system, but make velocity completely static?

uneven pendant
#

Is there any way to share code from a .net 6 project with my unity project?
my server and client need to share code but my server is .net 6

summer stump
muted wadi
#

is it possible to reference "other" from outside of an OnTriggerEnter method?

summer stump
#

Otherwise no, it is locally scoped

muted wadi
#

how would I save it to a variable?

summer stump
#

Make a variable of that type, and use an equals sign

muted wadi
#

just set one beforehand and inside the method assign other to that variable?

muted wadi
#

oh ok

#

so I am doing it right

#

in that case how can I make a variable inside ontriggerenter update even if the method isn't called?

summer stump
#

You would also have to check if it's null before using it because of what you said

weary crystal
#

Um guys can anyone help me why my camera ain't following the player SMOOTHLY? It is following "smoothly" but it's like SHAKING a lot so I don't think we can call it "smooth".

muted wadi
weary crystal
# summer stump Show code

public class smoothCameraFollow : MonoBehaviour
{
    public Transform target; // The object the camera will follow
    public float smoothSpeed = 0.125f; // The speed at which the camera follows the target
    public Vector3 offset; // Offset from the target's position

    void LateUpdate()
    {
        if (target != null)
        {
            Vector3 desiredPosition = target.position + offset;
            Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
            transform.position = smoothedPosition;
        }
    }
}```
muted wadi
summer stump
muted wadi
#

im trying to track the distance from the center of trigger object and the center of the object that has triggered it

wintry quarry
#

but anyway you'd just make distFromCenter a property - so it gets calculated whenever you use it:

float distFromCenter {
  get {
    return Vector3.Distance(mostRecentNote.transform.position, hitCollider.transform.position);
  }
}``` and save the note in a variable called mostRecentNote
muted wadi
wintry quarry
muted wadi
#

oh

wintry quarry
#

it actually does better than that - it's updated whenever you read it

azure zenith
#

What is a popular error detection extension for Visual Studio?

summer stump
polar acorn
#

It detects its own errors

#

The extension is itself

azure zenith
#

Weird

azure zenith
#

I don't get any red zig zags

wintry quarry
polar acorn
#

!ide

eternal falconBOT
wintry quarry
#

does !vs not work now? Did it ever work? Am I going crazy?

polar acorn
#

Does !vscode?

#

Nope

wintry quarry
#

!vsc

polar acorn
#

Welp, it's all in the general IDE one at least

summer stump
#

Looks like the #854851968446365696 commands haven't been updated to reflect the changes yet either

flat slate
#

i have a question

#

how do i make my character to hide then wait 1sec and then show again and play an animation

wintry quarry
#

or bake all of that into an animation

flat slate
#

but the problem is that i cant use a coroutine when the character hides

#

or can i?

wintry quarry
#

you can use a coroutine whenever you want

#

I guess you're saying if the coroutine is on the character and you are deactivating the character object? No, but you get around that in many ways:

  • only disabling the renderer, not deactivating the whole object
  • putting the renderer on a chilkd object and deactivating that
  • running the coroutine on a separate object entirely
flat slate
#

thank you

lusty socket
weary crystal
#

How can I design levels the quick and easy way in Unity 3D? By creating new sprites, Duplicating and replacing is hard and it takes time. Is there anything else I can do to create objects?

summer stump
#

I'm wondering if using the exact size of the collider is making it so it doesn't reach the ground

lusty socket
#

what code do i use specifically i only know how to debug.log and say something

calm osprey
#

does anyone understand how to make navmesh stuff work? every video tells me to download specific components but I assume these old videos only have links for stuff that won't work with my unity version

summer stump
#

Capital L, sorry

lusty socket
#

or update i meant

summer stump
#

Do it in IsGrounded

#

You can't access colliders outside of IsGrounded

#

It's a locally scoped variable

lusty socket
#

okay i meant update anyways i thought that would tell you for every frame

lusty socket
summer stump
#

Since you call that method in update

summer stump
# lusty socket ohhh i didnt know that thasnkyou

Anytime you declare a variable, it will have a scope. If you do it in a method, its scope is that method. If you declare it in a class, its scope is that class (but in that case you can use access modifiers to change the scope it can be accessed in)

lusty socket
#

should i worry about the error?

summer stump
#

It is saying the debug can litterally never be accessed or run

#

You return from the method the line before it

#

So it will NEVER run

lusty socket
#

how do i fix that?

summer stump
lusty socket
#

so i need to remove the return before colliders length/

eager elm
#

a return ends the function

summer stump
#

No no no

#

Just simply move the debug lol

lusty socket
#

i got you

#

so just inbetween the lines of code is fine?

eager elm
#

Select with your mouse the Debug.Log() line and press ALT + UpArrow

summer stump
lusty socket
#

when pressing play

summer stump
#

Move it down

weary crystal
#

Umm how do I duplicate tilemap objects...?

lusty socket
# summer stump Move it down

ive moved it so it is as on the ground as it can be and even in the ground so when hitting play it bring it up to the ground but no change

summer stump
#

Hopefully not the player?

lusty socket
summer stump
#

Offset the position downwards

#

You use coll.bounds.center

#

And the size

#

But the colliders prevent it from going into the ground..

#

Also, can you show a screenshot of the inspector of the ground

wintry quarry
lusty socket
#

so i just add down to the end of the coll.bounds.centre and coll.bounds.size or am i wrong

#

ignore me

#

theres inspector of the ground + the new code to size down and move down, but still no change @summer stump

summer stump
#

Also... just to make sure... show the layermask field

lusty socket
summer stump
#

Also, why have a GroundLayer and jumpableGround?

lusty socket
summer stump
#

Is _Idle_0 your player?

#

And I wanted the layermask expanded, but it shows Ground so that should be fine

lusty socket
#

i had an old way to do the ground check involving a ground layer so when it is detecting the ground then i can jump, if no ground is detected then the player jumping is true but i replaced it with the new one and forgot to delete the old layermask

weary crystal
#

Is this the right way to do what I'm trying to do?

{
    rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
}```

I forgot what I had to write and searching the web will take a while...

I hope you understand the code, I don't know how to explain rn :/
lusty socket
summer stump
summer stump
lusty socket
#

yes size is as it was before moving it down and making it smaller

summer stump
#

Like, the debug still shows 0?

lusty socket
#

yeah still just stuck in jump animation and debug saying 0

#

if it helps its also showing the debug a second time every time i press the space bar, aswell as ever frame

summer stump
#

But I dunno if that is strictly necessary

#

Can't check, as I'm on my phone

lusty socket
sturdy lintel
#

What I am trying to achieve is this:
I have a linePrefab to which LineController script is attached. Similarly I have a TravellingBallPrefab to which the TravellingBalls script is attached. The balls are spawned after every "interval" & travel along the line with "speed", & have "lifeSpan". These speed, interval, lifeSpan are controlled via SlidersWithEcho script which has the sliders.

The issue I am facing is this:
Except for speed, the interval & lifeSpan for the balls prefab is not being controlled properly. I wanted every ball to have it's own speed, lifeSpan & interval I think can be common because after every interval new ball is spawned. How can I properly use sliders to manipulate the lifeSpan & interval after which ball will be spawned?

LineController.cs https://pastebin.com/HG27K34S
TravellingBalls.cs https://pastebin.com/wuVGV36H
SlidersWithEcho.cs https://pastebin.com/hkzNA7EX

summer stump
#

You would assign it to an int instead

lusty socket
ashen ferry
#

got some issues trying to flatten my 2d array and just noticed this, how is this wrong size? [2,3] is right one not [3,3] or [2,2] why it differs lol

odd shale
#

Can someone tell me what's wrong with it?

polar acorn
weary crystal
#

lmao

wintry quarry
#

but yes please share screenshots in the future

odd shale
#

Okay thanks

wintry quarry
#

you have only 2 sets of 3

polar acorn
ashen ferry
#

oh bruh

weary crystal
#

Ok I need serious help right now, I'm trying to make a game in which you're a square trying to avoid touching the top, bottom and the objects that'll appear in your path, the thing is I'm adding the force to move up(The only thing you can do is move up, the square will go down because of the rigidbody) adding the force make square go up too fast or too slow and I'm confused what to do here :/ It's 2D game btw

Here's the code if needed:

using UnityEngine;
using UnityEngine.SceneManagement;

public class playerMovement : MonoBehaviour
{
    public float movementSpeed;
    public float jumpForce = 10f;
    private Rigidbody2D rb;
    public string sceneName;

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

    void Update()
    {
        if (Input.GetMouseButton(0) || Input.touchCount > 0)
        {
            rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
        }


        transform.Translate(Vector2.right * movementSpeed * Time.deltaTime);
    }

    void OnCollisionEnter2D(Collision2D collision)
    {
        SceneManager.LoadScene(sceneName);
    }
}

Sorry for writing a long ass message btw

polar acorn
#

That's going to wreak havoc on your momentum.

#

If you're using physics, don't move with translate

lusty socket
weary crystal
#

That makes my game 10 times more harder

polar acorn
#

If you want the speed to instantly change to a fixed amount, modify velocity instead of using AddForce

wintry quarry
#

if you used FixedUpdate and/or GetButtonDown it would work more consistently

#

never add force in Update

weary crystal
weary crystal
weary crystal
muted wadi
#

my particle system won't play even though my script says partSys.Play()

polar acorn
weary crystal
#

Here's the code:

using UnityEngine.SceneManagement;

public class playerMovement : MonoBehaviour
{
    public float movementSpeed;
    public float jumpForce = 10f;
    private Rigidbody2D rb;
    public string sceneName;

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

    void FixedUpdate()
    {
        if (Input.GetMouseButton(0) || Input.touchCount > 0)
        {
            rb.velocity = new Vector2(rb.velocity.x, jumpForce);
        }

        rb.velocity = new Vector2(rb.velocity.x, movementSpeed);
    }

    void OnCollisionEnter2D(Collision2D collision)
    {
        SceneManager.LoadScene(sceneName);
    }
}
polar acorn
polar acorn
weary crystal
polar acorn
weary crystal
#

It's velocity.x

polar acorn
#

You're setting the y velocity to movementSpeed

#

The jump force one is correct, that one should be y

weary crystal
muted wadi
#

does anyone know how to play a particle system, i dont get this 😭

polar acorn
weary crystal
muted wadi
polar acorn
muted wadi
#
 {
     Destroy(note.gameObject);
     AddScore(1);
     notesReady = false;
     print("Good Hit");
     partSys.Play();``` my script should be playing the particle system along with executing all that other stuff, but it doesn't. I have the particle system saved as a prefab
muted wadi
#

reference to the particle system

polar acorn
muted wadi
#

the prefab of a particle system in the editor

polar acorn
#

The prefab that is not in the scene and thus cannot be observed by anything

hidden bone
#

https://www.youtube.com/watch?v=1OOWHB-BOAY I followed this tutorial but it does not seem to be working. When launching, the program gets stuck in a constant loop and instantiates infinite text gameobjects that contain the string from the .txt file im reading from.
I want the program to read from the .txt file and change the text gameobject under Input Field to whatever it reads from the .txt file

In this Unity Tutorial, i'll show you how to display information in a text file!

https://youtu.be/iFJeg9AzN2Y (How to write to a text file)

*Note, a vertical layout group and content size fitter was placed on the content window to allow the text objects to display one after another and scroll properly.

Twitch https://www.Twitch.tv/PrefixWiz
...

▶ Play video
muted wadi
#

thats weird

polar acorn
polar acorn
# muted wadi thats weird

How is it weird? Lighting the schematic of a firework on fire won't make a spectacular light show it's just gonna burn up a piece of paper

eternal falconBOT
muted wadi
#

or can it be played on the transform im calling from

polar acorn
tiny leaf
#

I want to make my enemies stop following the player after leaving a trigger zone. The thing is there will be multiple trigger zones and the enemies will be instantiated to respective zones. How can I tell enemies what trigger zone they are “linked”to (the ontriggerexit/enter is on the player)

polar acorn
tiny leaf
#

okay

muted wadi
polar acorn
hidden bone
muted wadi
polar acorn
polar acorn
muted wadi
#

thanks so much

polar acorn
hidden bone
#

yeah, the script

polar acorn
# hidden bone yeah, the script

So, for every line in your text file, you are spawning an object that will look through every line in your text file to spawn an object that will look through every line in your text file to spawn an object that will look through every line in your text file to spawn an object that will~~

hidden bone
#

Yes i see the problem. I dont want to instantiate anything though, i just want the text gameobject under input field to change to whatever is written in the .txt file and i have no idea how

tiny leaf
#

Do I need to use a unique tag for every unique reference to a trigger?

polar acorn
polar acorn
hidden bone
#

I followed the tutorial hoping to get at least similar results to what i wanted and then change it

tiny leaf
#
private void SpawnShip()
    {
        GameObject enemyShip1 = Instantiate(_enemyShip1PF, transform.position, Quaternion.identity);
        enemyShip1.GetComponent<EnemyShipPathfinding>().SetTriggerZone(???);
    }

I'm not sure what kind of reference I should be adding here

calm osprey
#

bruh why is the documentation website so slow

polar acorn
tiny leaf
#

I was thinking I can assign some kind of reference in the enemyspawner object with a serializedfield so I can reuse the same script for every unique zone

hidden bone
#
        {
            Instantiate(TheText);
            TheText.GetComponent<Text>().text = line;
        }```  how can turn this into just changing the text under input field instead of instantiating?
polar acorn
hidden bone
#

yes but what do i write

tiny leaf
#

the functionality I'm trying to get is:
Make it so when the player leaves a zone, the enemies from that respective zone that are linked to it will no longer follow you

hidden bone
#

i dont know any syntax for this

polar acorn
weary crystal
#

Why the variable ain't showing in the inspector? Yes, it is a public gameobject variable.

polar acorn
weary crystal
#

public GameObject tapToPlayText;

polar acorn
weary crystal
polar acorn
weary crystal
#

public class GameController : MonoBehaviour
{
    public GameObject tapToPlayText;
    private bool gamePaused = true;

    void Start()
    {
        Time.timeScale = 0f; // Pause the game initially
    }

    void Update()
    {
        if (gamePaused)
        {
            if (Input.GetMouseButtonDown(0) || Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
            {
                StartGame();
            }
        }
    }

    void StartGame()
    {
        tapToPlayText.SetActive(false);
        gamePaused = false;
        Time.timeScale = 0.1f; // Slow down the game
        Invoke("ResumeNormalSpeed", 1f); // Resume normal speed after 1 second
    }

    void ResumeNormalSpeed()
    {
        Time.timeScale = 1f; // Set normal speed
    }
}
polar acorn
#

Show a screenshot of your unity console

weary crystal
#

Imma try recompiling

#

Wait how do we do it?

polar acorn
# weary crystal

Try reimporting the script, or changing something and saving it again

weary crystal
#

Alright it works now, thanks.

buoyant knot
#

If I have List<Monobehaviour>, is there a way for me to produce a simple IList<GameObject> defined based on monobehaviour => monobehaviour.gameObject, without actually making a whole list?

polar acorn
buoyant knot
#

I think that is useful, but maybe not exactly what I'm looking for

#

I'm thinking about which is the type I should return, to give access to that list as though it were an IList<GameObject>

#

IEnumerable is good to enumerate, but I'm wondering if I could maintain the info of Count by giving an IList

#

ok, Linq Select is the way to go. ty lol

weary crystal
#

Um so in my player code I added an OnCollisionEnter that'll show me the lose game scene but I've made an OnTriggerEnter that I want it to show the win game scene but uh it does the same as OnCollisionEnter, what can do I to fix this? I don't want the change scene on collision script to every object that'll make me lose the game if we collide with it...

#

Because there are like thousand of them and I'll have to add the script to every single one of them, is there anything I can do without changing those objects?

acoustic arch
#

can someone lead me in a direction to making my inventory have drag and drop

muted wadi
#

what does this error mean?

polar acorn
# muted wadi what does this error mean?

You cannot both get and set .color in the same line, because it's a property, not a variable. You would need to store the color in a variable, modify that variable, then set the text's color back to that

muted wadi
#

gotcha

polar acorn
polar acorn
# weary crystal Yes

Show code, show the inspectors of this object and the thing you are trying to collide with that isn't doing what you want

weary crystal
# polar acorn Show code, show the inspectors of this object and the thing you are trying to co...
using UnityEngine.SceneManagement;

public class playerMovement : MonoBehaviour
{
    public float movementSpeed;
    public float jumpForce = 10f;
    private Rigidbody2D rb;
    public string sceneName;

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

    void FixedUpdate()
    {
        if (Input.GetMouseButton(0) || Input.touchCount > 0)
        {
            rb.velocity = new Vector2(rb.velocity.x, jumpForce);
        }

        rb.velocity = new Vector2(movementSpeed, rb.velocity.y);
    }

    void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.CompareTag("FUCK"))
        {
            SceneManager.LoadScene(sceneName);
        }
    }



    void OnTriggerEnter2D(Collider2D collision)
    {
        SceneManager.LoadScene(sceneName);
    }
}

(Ignore the tag name plzz)

polar acorn
#

I don't know why you expected them to do anything different

weary crystal
#

huh

#

Wait-

#

My god I need sleep bruhh sorryyyy

crisp token
#

Am I stupid,

#

Why is this function not resulting in the camera not returning to the position it started, I understand why it might be off by a little but it's like not even moving back at all: https://hastebin.com/share/ebekajiser.csharp

polar acorn
crisp token
polar acorn
#

Do you get both logs?

crisp token
#

yeah

#

they're different values tho which is weird

#

oh actually it makes sense y theyre differnt

polar acorn
#

Log the position before the first loop, between loops, and at the end. Give them each a different prefix so you know which is which. Debug.Log($"Before: {transform.position}"); and then the same for middle and end

crisp token
#

Here its only off my one tick which makes sense, but sometimes its a lot worse, let me see if I can get an example

#

I have a feeling the issue is coming from a different script

polar acorn
#

You're going to be off by one or two on occasion. You said it wasn't moving back at all which is a different problem

crisp token
#

omg i just relized the issue

polar acorn
#

The number of time steps to make 0.3 seconds is not going to be consistent

crisp token
#

I never reset the timer lmao

#

sorry

polar acorn
#

It looks reset in the snippet you sent 🤔

#

Oh, wait

crisp token
#

yeah lol

polar acorn
#

you mean you don't reset it between coroutines

#

Yeah, that's a problem

crisp token
#

yeah there's no way you couldve known that just by looking at it

buoyant knot
#

if I want to implement IEnumerable<T>, why do I need to implement both IEnumerator IEnumerable.GetEnumerator() and public IEnumerator<TStored> GetEnumerator()? Isn't it a bit redundant?

muted wadi
#

is there a function in unity like CrossFadeAlpha but for the size of a text element instead of alpha?

sweet zenith
#

DOTween is pretty popular

muted wadi
#

What is a tweening library?

sweet zenith
#

It's a library for changing one value to another over time

muted wadi
#

Ah

sweet zenith
#

Like moving an element around, or resizing, shaking etc

#

But if you want to do it manually you can too

muted wadi
#

That sounds like exactly what I need

sweet zenith
#

I would recommend trying out DOTween

#

Actually there's another one on the asset store that's meant to be way better...

muted wadi
#

Is it not a standard unity asset that comes with every project?

sweet zenith
#

PrimeTween

#

No, they're third party

muted wadi
#

Because this sounds really good, I'm just not sure if I'm gonna be able to use them since they're a third party addon

sweet zenith
#

Or because it's a school project/

#

Most ppl add a tweening lib to their unity projects

#

But if you can't, you can write your own

muted wadi
sweet zenith
#
static IEnumerator TweenLocalScale(Transform transform, Vector3 to, float duration) {
  var from = transform.localScale;
  var startTime = Time.time;
  var endTime = startTime + duration;
  while (Time.time < endTime) {
    var t = Mathf.InverseLerp(startTime, endTime, Time.time);
    transform.localScale = Vector3.Lerp(from, to, t);
    yield return null;
  }
  transform.localScale = to;
}

//

StartCoroutine(TweenLocalScale(someTransform, Vector3(1, 2, 3), 1f));
muted wadi
#

Now that I think about it I should be fine considering it's just a library, unity has plenty that we already use

sweet zenith
#

So long as the library isn't doing the core thing you're being assessed on

#

Just ask your teacher

#

I would definitely recommend using a library over writing it yourself

#

It's a good tool to know

muted wadi
#

Oh nah I just want to cut down the time spent programming tiny cosmetic changes, the core stuff is all me

muted wadi
queen adder
#

Hey guys I was following someone's tutorial where they gave a ragdoll a 3rd person camera controller: https://hatebin.com/fwidzztlpp but after following their steps and applying the component, the camera moves left and right when you move your mouse up and down, similar to in real life when you tilt your head from left to right, side by side. Could anyone help me with this?

acoustic arch
#

how could i make a slot be able to hold up to 160 of the item thats inside it?

#

i already have item data for each item to have a stackable bool

#

but im not sure how id make stacking in the actual slot

teal viper
teal viper
#

Then I don't get the question

acoustic arch
#

nvm i was confused

acoustic arch
#

if its a stackable item it should instead go to the ItemStack class instead of the slot class?

#

or both and the slot just holds data but not like the amount

teal viper
#

I'd just make all slots hold Stacks and the stacks would have a reference to the item definition and item instances list. If it's a non stackable item, it would just have 1 instance of an item in the list.

acoustic arch
#

oh well

teal viper
#

But if you really want to differentiate, you could make a stack inherit from an item instance so that you can pass them to the slot as an item instance.
ItemStack: ItemInstance

acoustic arch
#

i could just make them all a stack and limit the non stackable items to 1

#

which sounds simpler

#

like you said

teal viper
acoustic arch
#

ya

acoustic arch
teal viper
#

Yes. Instead of ItemData, it should be ItemStack

acoustic arch
queen adder
teal viper
silk night
#

https://img.sidia.net/ZEyI5/MiTizOfu11.mp4/raw

So thanks to your help here I got the new Inputsystem for local multiplayer running perfectly, the only problem I have now:

How can I allow the first player to navigate down to the start button? Currently both of the added players are contained in their little button test structure at the top but i'd like the first player to be able to break out of it and press start, any way to make that possible?

I attached a screenshot of how the "button container" prefab has the containment per-player configured

acoustic arch
#

how do you get the amount of data inside of a list

buoyant knot
#

myList.Count

slender nymph
#

Do you mean the number of elements? if so, lists have a Count property

acoustic arch
#

thanks anyway

acoustic arch
#

im getting a null error for my scriptable objects bool whenever its unchecked on the object in the inspector

teal viper
#

bools can't be null

timid gale
#

Might be a silly question but, can you make a TMP_Text button, move you to a new scene?

I've been trying but, can't seem to get it to work..... 😅

teal viper
timid gale
#

I do have that script but, it's not working.....

#

Is there anything wrong with this code??
I'm not getting any prompts from the console......

using UnityEngine;
using UnityEngine.SceneManagement;

public class Go2GameMode_Scene : MonoBehaviour
{
public void LoadGameModeScene()
{
SceneManager.LoadScene("GameMode_Scene");
}
}

#

The scene I want to go to is called GameMode_Scene

swift stag
#

I'm trying to create my build, this is intended to be rendered under HDRP. However, it says that it's also rendering the Universal Pipeline as well

teal viper
teal viper
spring coral
#

real quick wondering, how do people achieve tabs like this? I cant imagine them having a sprite for each tab

cosmic dagger
#

the same 9-sliced sprite would be used for all of them . . .

spring coral
#

well heres the tricky part for it

#

i want to do tabs a bit like this

#

where the gradient of the tab follows the ui color

#

i was thinking maybe a mask for the highlighted tab or something could maybe work?

#

hard to say

eternal needle
#

try a ui channel, this is a code channel

cosmic dagger
spring coral
#

fair enough, and ill try that out, thanks

desert elm
#

Hello, I am quite new to coding in of itself, and I would like to ask-
I have a script to select units written by a friend, and I would like to ask- what does it actually do? I would like to understand unity more instead of just constantly asking other people to help.

public class Unit : MonoBehaviour

{
public InputManager inputManager;
void OnMouseDown()
{
inputManager.UnitSelected(this);
}


public class InputManager : MonoBehaviour
{

public Unit selectedUnit;
public void UnitSelected(Unit unit)
{
    selectedUnit = unit;
}
slender nymph
#

first: !code
second: it uses the OnMouseDown method on the MonoBehaviour class which detects clicks on that object. when a click has been detected on that object is calls the UnitSelected method on the instance of the InputManager class that it has a reference to and passes itself. The InputManager's UnitSelected method just assigns the reference that was passed to it to a field on that class.

eternal falconBOT
rare basin
#

hey could anyone help me identify the problem? im getting null reference exception in this line
var collectionSlot = unitsCollectionController.collectionSlots.First(c => c.unitData.objectType == unitSlots[index].assignedUnit.objectType);

#

unitsCollectionController is assigned

slender nymph
#

unfold the Unit Slots collection there and make sure that it actually contains non-null elements

rare basin
#

well there are null elements, because the fill based on what units i choose

#

so for example right now in the deck i have 2 units, digger and north assasin

#

and if i add another it fills the [2] index

candid oyster
#

Hey, I have a bunch of blocks which each have a script (the same script _containing some variables. Now how do I get the information from a certain block into a different script? Im doing the inspector link method but it only allows me to manually select which block it takes the script from in the inspector. How can I make is so that I can just pick which gameobject does it take the information from? I hope that I wrote that clearly

rare basin
#

sorry wrong screenshot

verbal dome
#

It has null assignedUnits

rare basin
#

everything in the collectionSlots list is referenced, theere are no empty elements

verbal dome
#

Yeah but things inside those slots vould be null

rare basin
#

the unitDatas might be unll

verbal dome
#

And your Linq is trying to use those

rare basin
#

in the collectionSlots?

verbal dome
#

Anything there could be null

#

So yeah start by checking that

candid oyster
rare basin
#

everything looks good here

#

the unit data is referenced

#

and that's the only thing im using

#
var collectionSlot = unitsCollectionController.collectionSlots.First(c => c.unitData.objectType == unitSlots[index].assignedUnit.objectType);
#

objectType is an enum

slender nymph
#

there are so many objects on that line that could potentially be null

rare basin
#

unitsCollectionController is referenced

#

collectionSlots is a list with no empty elements

slender nymph
#

how have you verified that any of this not null

rare basin
#

unitDatas are referenced inside the elements

slender nymph
#

and just looking at the inspector isn't really enough

rare basin
#

wdym i can see it's referenced

slender nymph
#

what have you done to verify your assumptions

rare basin
#

i can see it's referenced in the inspector

#

unitData for each unit

verbal dome
slender nymph
#

well then i guess everything is fine and your issue is solved

rare basin
#

and collectionSlots list doesnt contain any empty elements inside

rare basin
#
    public void UpdateUnitUI(int index)
    {
        unitSlots[index].isAssigned = true;
        unitSlots[index].assignedUnit = PlayerDeck.Instance.unitSlots[index].assignedUnit;
        unitSlots[index].slotImage.gameObject.SetActive(true);
        unitSlots[index].slotImage.enabled = true;
        unitSlots[index].slotImage.sprite = unitSlots[index].assignedUnit.unitSlotSprite;
        unitSlots[index].plusEmptyImage.enabled = false;

        var collectionSlot = unitsCollectionController.collectionSlots.First(c => c.unitData.objectType == unitSlots[index].assignedUnit.objectType);
        if (collectionSlot != null)
            collectionSlot.hasBeenAdded = true;

        unitsCollectionController.RefreshCollection(index);
        UnitDeckPreviewController.Instance.AddUnitToPreview(index, unitSlots[index].assignedUnit);
    }
#

this is entire function

#

i have a UI preview of my current deck

#
PlayerDeck.Instance.OnUnitAdded.AddListener(UpdateUnitUI);
#

and im triggering this function everytime i add a unit at specific slot index

#
        Debug.Log(unitSlots[index].assignedUnit);

        var collectionSlot = unitsCollectionController.collectionSlots.First(c => c.unitData.objectType == unitSlots[index].assignedUnit.objectType);
        if (collectionSlot != null)
            collectionSlot.hasBeenAdded = true;
slender nymph
# rare basin

instead of using linq you should write a loop and do the check manually so that you can null check the relevant objects instead of just assuming that they are not null

rare basin
verbal dome
#

How do we know that PlayerDeck.Instance.unitSlots[index].assignedUnit is not null?

#

I agree that a loop will make it more debuggable

rare basin
#

Debug.Log(unitSlots[index].assignedUnit);

#

prints correct value

#

unitSlots[index].assignedUnit = PlayerDeck.Instance.unitSlots[index].assignedUnit;

#

and before debug log im doing this

#

so if PlayerDeck.Instance.unitSlots[index].assignedUnit; would be null

slender nymph
#

don't make assumptions. actually verify what is happening

rare basin
#

the debug.log would be null aswell

rare basin
slender nymph
#

well you're clearly not reading what i've written

rare basin
#

how is that an assumption?

#

PlayerDeck.Instance.unitSlots[index].assignedUnit; is not null

#

otherwise the Debug.Log will print null

verbal dome
#

What about unitsCollectionController or unitsCollectionController.collectionSlots or c...

slender nymph
#

now what about the individual elements of the list and the objects you access on those elements?

#

stop making assumptions that they aren't null when there is at least one or more null object

rare basin
#

the only element that im checking i unitData which is SO and unitSlots[index].assignedUnit

#

and both aren't null and this is not an assumption xd

slender nymph
#

oh my mistake, here i was thinking you were using the First method from linq which will loop through the collection. i guess you aren't doing anything at all that could end up with a null object

rare basin
#

no reason to be passive agressive ;p

#

i've verified that nothing is null

verbal dome
#

Well you are being a bit defensive

slender nymph
rare basin
#
        Debug.Log(unitsCollectionController);
        Debug.Log(unitsCollectionController.collectionSlots);
        Debug.Log(unitSlots[index].assignedUnit.objectType);

        foreach(var c in unitsCollectionController.collectionSlots)
        {
            Debug.Log(c.unitData.objectType);
        }
#

nothing of that

#

prints null

#

nothing else can be null

#

in this line
var collectionSlot = unitsCollectionController.collectionSlots.First(c => c.unitData.objectType == unitSlots[index].assignedUnit.objectType);

verbal dome
#

Do you have a duplicate of this script in the scene?

rare basin
#

no

solemn fractal
#

Hey guys, creating a very simple ship game, 2D, where i shoot and destroy 1 enemy.. i dont know what could be wrong with my scripts.. have like 2 c# scripts 1 for enemy 1 for player, with just few lines, but i feel like when I am moving the ship sometimes there is a LAG on the input and even tho i already released the keys it continues to move for half a second like if it was a lag or something, any potencial reasons for that?

slender nymph
# rare basin no

try this and see if it prints any errors. if it doesn't then the issue does not lie here.

CollectionSlot collectionSlot; //obviously change this object's type to whatever it's correct type is
var collection = unitsCollectionController.collectionSlots;
for(int i = 0; i < collection .Count; i++)
{
  var slot = collection[i];
  Debug.Assert(slot != null, $"Element {i} is null on {name}", gameObject);
  var unitData = collection[i].unitData;
  Debug.Assert(unitData != null, $"Element {i} contains a null unitData on {name}", gameObject);
  if(unitData.objectType == unitSlots[index].assignedUnit.objectType)
  {
    collectionSlot = slot;
    break;
  }
}
eternal falconBOT
solemn fractal
#
        // Getting the Input to use A,D,W,S
        float horizontalInput = Input.GetAxis("Horizontal");
        float verticalInput = Input.GetAxis("Vertical");

        transform.Translate(Vector3.right * _speed * horizontalInput * Time.deltaTime);
        transform.Translate(Vector3.up * _speed * verticalInput * Time.deltaTime);
        } ```
#

I call it on void update

#

it works, but sometimes it just moves with a lag, and its so simple script.. imagine a complex one.. 😦

slender nymph
#

are you sure that it is actually lagging though? and not perhaps something just being stuttery, perhaps camera movement being stuttery?

#

if you think it is actually lag then you need to use the profiler to determine the source of any performance issues

muted wadi
#

does the ++ operator just add 1 to the current value?

slender nymph
#

yes

muted wadi
#

thanks

gaunt ice
#

i++ is
int temp=i;
i=i+1;
return temp;

slender nymph
muted wadi
slender nymph
muted wadi
#

microsoft documentation is pretty confusing for me too so I appreciate that the people here answer questions so concisely and in a way that's easy to understand

frosty hound
#

It even highlights the answer 🤷‍♂️

quaint thicket
#

I'm not sure what this is called. I want to have a function which takes some C# code, creates another new function, and sets this new function to a variable. For instance ```cs
public object Action;

public void CreateNewFunction(object action)
{
Action = action;
}

CreateNewFunction(Some code here);```

copper pumice
quaint thicket
#

For now it's just at runtime but both in the longterm.

copper pumice
#

Hmm, so like the player can type the code or?

slender nymph
quaint thicket
#

Right now I just want to create some functions at runtime by setting them via a code-block instead of directly to functions. Later I'll do the playercode thing.

copper pumice
#

So basically you want a input field and then the text becomes code yeah?

#

Or did i missunderstand?

quaint thicket
teal viper
#

So you want a runtime interpreter.

#

It's a pretty advanced topic. Are you sure you can handle it?

quaint thicket
slender nymph
#

you may need to provide more details about exactly what you are trying to do

copper pumice
slender nymph
#

because there are multiple interpretations for the vague description you've given

solemn fractal
#

Hello guys, I am following an Udemy Unity course, still at the begining of the course but now I started to encounter a prob that even having EXACTLY the same code and setting as the teacher, he doesnt have a prob I have that SEEMS like its a LAG but not sure what could it be as sometimes when I am moving my ship and relase the key it continues to move in some direction or half a second.

Scripts:

Player: https://paste.ofcode.org/8G2N8UCrpJbHqDfjQyTR3T
Enemy: https://paste.ofcode.org/KQmAc5uHadHpAVLtw4XrR6
Laser: https://paste.ofcode.org/38jdzhzbSjuZfjSfZ9AUcfB
PowerUps: https://paste.ofcode.org/yLzhbPpfE3hNTjGgPhE9jg

Also checked the profiler and all seems to be fine.
Thank you in advance.

quaint thicket
slender nymph
#

well you've not really described it in a way that gives a definitive answer

slender nymph
teal viper
solemn fractal
quaint thicket
copper pumice
slender nymph
solemn fractal
#

but I changed bat to GetAxisRaw

quaint thicket
#

I use the new input system, it detects a input action, and then I want it to run some function. The idea is that instead of making a function ahead of time, I'd put the functions code as part of a parameter, save it to a variable, and then run the variable-function instead of a normal function.

slender nymph
#

that's a delegate

quaint thicket
#

I'll look that up. thanks everyone

solemn fractal
copper pumice
slender nymph
slender nymph
solemn fractal
#

also there is another prob.. when i limited the SHIP to not pass the lower border of the screen. sometimes RANDONLY and sometimes jut once.. it sticks there and wont get out for like some seconds.. what also doesnt happen with the teacher. and could be a lag also or whatever it is.. as A beginner see a code so small and game so small like that already having a prob that is hard to see where the prob is, damn.. imagine trying to create something a bit bigger.

slender nymph
#

the code you are using is fairly naive when it comes to ensuring the object stays within the bounds. it's very probable that the issue you just described also happened to the course instructor but they just didn't show when it happened

#

you'll probably also notice that your objects can move through colliders pretty easily and the instructor probably won't show that either. but that's because you are effectively teleporting the objects to specific places instead of moving them in a way that will automatically react to collisions like with physics

solemn fractal
# slender nymph the code you are using is fairly naive when it comes to ensuring the object stay...

yeah its a super beginer course.. so I imagine if he fixes everything if really there is a prob me as a beginer would be overwhelmed. Not sure if that would be the case. But all the tests he did I didnt see him having the prob at all. But could be just that he is hiding that as you say, no idea. Any ways its impossible for me to learn all now and I need to focus in some stuff. So for now maybe is just better to forget about this prob.. and focus on other stuff to learn that might be more important as a beginer.

solemn fractal
slender nymph
#

well if you can get a recording of what is actually happening like was suggested a bit ago by dlich that would be incredibly helpful for determining the cause

solemn fractal
slender nymph
#

you can build the game from the Build Settings menu

solemn fractal
solemn fractal
#

if I want to send that game to someone I need to send all that folder? or just the .exe?

slender nymph
#

you can use the profiler to profile the editor to see if it is actually causing a performance issue

solemn fractal
slender nymph
#

the only exception would be if you were using Burst, it would create a folder that specifically says not to ship it

solemn fractal
#

Thank you for the help and time.

silent obsidian
#

If i want to move my character by using rigidbody velocity, should i put the logic inside the Update method or FixedUpdate? Currently this is my script, but it is really buggy in regards to jumping

[SerializeField] private Transform groundCheckTransform = null; 
    [SerializeField] private LayerMask groundMask;
    [SerializeField] private float speed = 10f;
    [SerializeField] private float jumpSpeed = 10f;
    [SerializeField] private float turnSpeed = 10f;
    private Animator animator;
    private bool jumpKeyWasPressed;
    private float hzInput;
    private Rigidbody rb;
    private bool isGrounded;

    private void Awake() {
        rb = GetComponent<Rigidbody>();
        animator = GetComponentInChildren<Animator>();
    }

    void Update()
    {
        hzInput = Input.GetAxis("Horizontal");

        if (Input.GetKeyDown(KeyCode.Space))
        {
            jumpKeyWasPressed = true;
        }

    }
    private void FixedUpdate() {
        rb.velocity = new Vector3 (hzInput * speed, rb.velocity.y, 0);
        animator.SetFloat("Speed", rb.velocity.magnitude);
        transform.Rotate(Vector3.up, hzInput * turnSpeed);

        isGrounded = Physics.CheckSphere(groundCheckTransform.position, .3f, groundMask);
        Debug.Log(isGrounded);
        
        if (jumpKeyWasPressed && isGrounded) {
            rb.velocity = new Vector3 (rb.velocity.x, rb.velocity.magnitude, 0);
            jumpKeyWasPressed = false;
        }

    }
slender nymph
#

typically you would get your input in Update and apply physics inside of FixedUpdate

#

as for why it is buggy for your jump, why are you using the magnitude of the velocity for the Y velocity of your jump? that doesn't make a lot of sense

silent obsidian
#

Actually, I don't really know lol. would rb.velocity.y + jumpSpeed make more sense?

slender nymph
#

or just jumpSpeed

#

though i would personally use AddForce to apply the jump

silent obsidian
#

Okey, I see, it feels better with AddForce. Thanks!

buoyant knot
#

is there a way to check == true null?

cosmic dagger
#

huh?

#

which one: check true or null?

buoyant knot
#

like actual null null

#

not "destroyed object is null" null

cosmic dagger
#

it's still null . . .

buoyant knot
#

Would ReferenceEquals(obj, null) work?

cosmic dagger
#

☝️ that will work for c# objects . . .

buoyant knot
#

if you destroy a unity object, you can still plug it into a dictionary as a key

#

not the same as actual null, if that makes sense

cosmic dagger
#

unity does a bunch of internal checks for null on unity objects, so you have to use == null . . .

#

you can't use any of the c# null checks . . .

buoyant knot
#

well, I'm assigning null to represent actual nothing in this case

static cedar
buoyant knot
#

correct

#

I just wanted a way to distinguish

static cedar
cosmic dagger
static cedar
#

Is it because you can't really manually dispose a c# object?

buoyant knot
#

hold on, so obj is null, is different from == null?

#

trippy

buoyant knot
#

anyway, I made my first public git repo class

cosmic dagger
# buoyant knot I just wanted a way to distinguish

It's hard to distinguish between fake null and real null. You can have a bool on a MonoBehaviour class that marks it as destroyed but you can't access it if/when the UnityObject does become null . . .

cosmic dagger
static cedar
#

I guess that's a pretty annoying limitation for cases like that. UnityChanThink

teal viper
#

For all intents and purposes, a destroyed object should be considered as null. There isn't really a need to make distinction.

buoyant knot
cosmic dagger
#

I'd just check for null and call it a day. It's considered null when destroyed anyway . . .

buoyant knot
static cedar
#

Btw, casting a unity object to an interface and then comparing it is a foot gun ye? UnityChanThink

buoyant knot
#

uhhh.... maybe lol

#

because the interface wouldn't have == overridden

static cedar
#

Yeah.

static cedar
buoyant knot
#

wdym weak references?

static cedar
slender nymph
#

WeakReference wouldn't account for destroyed objects though

static cedar
#

Yeah sadly.

shell zephyr
#

Hello! I have 2 questions, let's start with the first one. My unity engine just locked my cursor, so I can't make colide boxes or choosing items on the screen with my mouse anymore. It can be fixing by just creating a new project, but I would like to continue with my existing one. is there anything I could do to fix it? Thank you before hand blushie

slender nymph
#

it still wouldn't become null until the object has been GCd which could be a while after destruction

slender nymph
static cedar
#

They can get randomly gced too i guess. UnityChanPanicWork

slender nymph
#

yes

shell zephyr
#

nop I'm not

slender nymph
#

somehow i doubt that

#

if your cursor is actually getting locked, then some code somewhere in your project is locking it via the Cursor.lockState property

static cedar
#

U can try global word search on ur IDE. UnityChanThink

shell zephyr
#

Yes, but I can use it to choose assets in project or inspector, but not on screen

#

That's weird :(

slender nymph
#

is the cursor locked or not?

#

keep in mind that it being locked is not the same as it being visible but not able to click anything

buoyant knot
shell zephyr
slender nymph
#

so it's just affecting Game view? is it that you cannot click on buttons and other UI objects?

shell zephyr
#

Nop, I'ts no affecting the game. but it's not allowing me to add any coliders or move any objects

slender nymph
#

what? you just said you can click on things in your inspector and scene, no?

#

can you record a video of whatever is happening? because you can't seem to describe what is actually happening without contradicting yourself

#

also is this even code related?

shell zephyr
#

Pink area isn't working 👀

cosmic dagger
slender nymph
shell zephyr
#

ohhhh, I see. Thank you!

#

My first time using Unity XD

cosmic dagger
static cedar
#

You know? I question why there is no System delegate called Meth for Method. UnityChanThink

silent obsidian
#

How would you guys handle a character rotation based on the horizontal input?

    private void FixedUpdate() {
        rb.velocity = new Vector3 (hzInput * speed, rb.velocity.y, 0);
        animator.SetFloat("Speed", rb.velocity.magnitude);

        Quaternion startRotation = transform.rotation;
        Quaternion targetRotation = transform.rotation * Quaternion.Euler(0, hzInput * turnSpeed * -1, 0);
        
        // pseudocode ?
        // if (transform.rotation.y < 90 || transform.rotation.y > -90) {
            transform.rotation = Quaternion.Slerp(startRotation, targetRotation, .5f);
        // }

I managed to get my character to rotate but I'm struggling to find a way to only let it rotate if rotation.y < 90 || rotation.y > -90

slender nymph
#

search "clamp rotation" or "clamp camera" for examples of how you can clamp it.

#

but basically you keep a float that you add/subtract to when you want to rotate the object. clamp that, then apply that using Quaternion.Euler to construct a quaternion from your angles and assign it to the object's rotation

#

do not attempt to clamp the transform.rotation values as they are not in degrees, nor the transform.eulerAngles values as they are interpreted from the quaternion at the time you access them and may not be exactly what you would expect them to be

silent obsidian
buoyant knot
cosmic dagger
bitter carbon
#

public TMP_Text textDisplay;

is this a good way to assign tmp text objects cuz ik there is another way and this was isnt seeming to work for me?

polar acorn
#

That's a good way to assign any variable. Setting it directly is always going to be faster than getting it some other way

slender nymph
#

in what way is that not working?

gaunt ice
#

you probably trying to assign a TextMeshProUGUI to it then it doesnt work

cosmic dagger
bitter carbon
slender nymph
slender nymph
gaunt ice
#

doesnt know that before

polar acorn
bitter carbon
bitter carbon
polar acorn
# bitter carbon nope,\

Then you're going to have to say what doesn't work. You shouldn't need someone else to tell you that, it's the reason you asked the question in the first place

bitter carbon
teal viper
cosmic dagger
shell zephyr
#

Hello! It's asking me to add something there, but I don't understand what exactly Unity wants. I tried with scripts and animations, but It's not accepting them

#

🥺

young warren
#

Like, an Animator controller. Not a script. Not an animation

cosmic dagger
young warren
#

Animator

#

It's a component

shell zephyr
static cedar
#

You can think of it as an Animation Manager or smth.

young warren
#

You can look it up. There's plenty of tutorials on it

shell zephyr
#

Never tried it before sobaka_plaka

static cedar
young warren
#

Well that's the way you control what animations you play

shell zephyr
#

I believed creating animations was enough XD 🥺

cosmic dagger
#

are you following a tutorial?

sudden glacier
#

I have an if event, and want to play a Sound before restarting the Scene. Problem is that the Scene restarts directly without playin the Sound. How to fix that?

if (hit.gameObject.tag == "Deadly")
        {
            deadAudioSource.Play();
            Respawn();
        }
#

Yes, i configured everything.

shell zephyr
#

I followed a tutorial, but it never shown anything about animations, It's just "worked" for them

cosmic dagger
slender nymph
shell zephyr
#

Thank you! cute_heart

topaz mortar
#

I have ItemSO which is a Scriptable Object, got multiple of them, for example: sword, axe, ...
Can I do if (item.ItemSO == itemSO)
to check if item is a sword?

cosmic dagger
shell zephyr
topaz mortar
silver timber
shell zephyr
cosmic dagger
young warren
shell zephyr
#

Armatere | openclose has motion, while empty ones don't, that's why I have a feeling I'm not doing it correctly

silver timber
#

Idk the whole context. But yea the orange box is the state that will be entered by default. You might(?) not technically need it, since you could transition to a non default state from the Any State node based on some condition - but idk how an animator behaves whose controller doesn’t have an active state

#

I’ve never not had a default state

shell zephyr
#

Thank you! I will just try and see if it works, althrough I have a pre feeling it won't XD

Thank you for helping me guys wave

topaz mortar
signal tide
#

!ide

eternal falconBOT
flat slate
#

i need help

#

i want my button to just appear when the player touches the Npc

#

but it doesnt shows again

silk night
#

Show your code

flat slate
#

i can tick the setactive manually when the player is in the collider from the Npc

flat slate
silk night
#

!code

eternal falconBOT
flat slate
#

its the istouched function

#

and the on triggerfunctions

silk night
#

Please post your code as written in the guide above, screenshotted code does not really help

flat slate
#

should i just copy it?

silk night
ivory bobcat
eternal falconBOT
flat slate
#

i dont understand

summer stump
#

Copy your code there

#

Click save

flat slate
#

okay

summer stump
#

Copy the url and paste it here

ivory bobcat
#

Show an image of the console tab in the Unity Editor as well

flat slate
#

wait

#

the only thing that isnt working is the "show" thing

final kestrel
#
 private void Move()
    {
        Vector3 forward = transform.forward;
        float currentYVel = _rb.velocity.y;
        Vector3 newVelocity = transform.forward * _moveSpeed;
        newVelocity.y = currentYVel;
        _rb.velocity = newVelocity;
        //_rb.velocity = transform.forward * _moveSpeed;
    }

Hey all. I have this move method. My game starts paused so I need to zero only the forward velocity. Since these are local variables. I could not seperate them and use individual axis. Can someone help me out

ivory bobcat
flat slate
#

it also hides when i tick the setactive and walk away

ivory bobcat
flat slate
#

there isnt any prefab

ivory bobcat
#

All objects shown in scene were always active

flat slate
#

no

#

the speechbubble which the button should activate isnt

#

the others are active

#

i even restarted unity because i thought its a bugg

#

but it isnt

timid gale
flat slate
#

its in the button

#

wait

ivory bobcat
#

If it's important, show us/yourself.

flat slate
#

the button is Startconpriester

ivory bobcat
# flat slate

Try more useful logging instead:cs Debug.Log($"{name} was touched by {trigger.name}", this);

flat slate
#

instead of?

ivory bobcat
#

Instead of what you had prior

flat slate
#

instead of the log: hide, show, or istoched, isnttouched?

flat slate
#

these are all logs

flat slate
#

ye i know but what do i have to replace with that?

#

which log code

ivory bobcat
flat slate
#

ok

swift crag
#

the example Dalphat gave you says "was touched by", so..

ivory bobcat
flat slate
#

ye

#

ok

#

it even says that it touches

#

but the button doesnt show up anyways

ivory bobcat
#

What becomes highlighted when touch occurs?

#

Something should become yellow when you click the log message

flat slate
#

wait

#

the player

#

as it should

ivory bobcat
#

So this part is working fine.

flat slate
#

ye

#

the problem is in the "gameObject.setActive(true);"

#

but i dont know why

ivory bobcat
#

Meaning the fault has to do with your IsTouched script/object

flat slate
#

so what should i do

ivory bobcat
#

Does "Show" ever print?

flat slate
#

no

#

and hide does just 1time

#

so just in the start not when the player doesnt collides anymore

ivory bobcat
#

If not, it doesn't ever think "the player" it's referencing is ever touched.

flat slate
#

ye

#

wait

ivory bobcat
#

Meaning "the player" it thinks is the player, isn't the one being touched

#

Or IsTouched is never called again

#

Since the code shown are excerpts, we aren't able to know the behavior that you've designed for it - the more important stuff.

flat slate
#

wait

#

i can try soemthing

ivory bobcat
#

It's likely possible that it's one of the two above or that you may have secretly set to the bool to false elsewhere prior to checking etc

#

The issue isn't related to the code shown above - we weren't given enough info.

flat slate
#

i can look for it

#

maybe the problem is with the function itself

ivory bobcat
flat slate
#

but there is just one player

#

istouched have to be called again bcs its in the update method

ivory bobcat
flat slate
#

ye i know

#

but what should i do then

ivory bobcat
#

Is the console spamming hide/show?

flat slate
#

no

#

just in the start it says 1time "hide"

ivory bobcat
#

Make it spam it or occur once with properties etc?

#

Spam would be referring to the method being called in Update - apparently it's not according to the video

flat slate
#

ye it is

ivory bobcat
#

It wasn't prior

flat slate
#

in the video the "hide" method is being called 1 time

ivory bobcat
flat slate
#

ye i know

#

but it doesnt

#

but why

ivory bobcat
#

So that means it isn't being called in Update

flat slate
#

but it is

buoyant knot
flat slate
ivory bobcat
flat slate
#

wait

#

!code

eternal falconBOT
flat slate
#

this is the whole script

ivory bobcat
#

Is it spamming the console now?

flat slate
#

no

polar acorn
# flat slate no

Then either:

  1. You have an error
  2. This object is destroyed or disabled
    or 3. It is
ivory bobcat
#

If not, did you save the script? Are there any compilation errors? Are you not using the script (implies you've got backup scripts and aren't using the correct script)?

flat slate
#

wait

ivory bobcat
#

Is the script on an inactive object?

#

Update isn't called on inactive objects.

flat slate
#

yes its inactive

#

okay i know the problem thanks

buoyant knot
#

just a side note: SCREAM_CASE is only normally used for consts

#

if I read PLAYER, I assume that is a const, but it isn’t. It’s a field

flat slate
#

now it works haha

heady nimbus
#

Not necessarily a coding question, but I like you guys better than the other channels:

Doing a platform adventure game with zone transitions back and forth.

Right now I only have a few, I'm setting up each full zone as a prefab that I instantiate at a pre-defined point.

My question is what's the best way to handle instantiating each new zone? Should I lay it out as one big world, each zone with its own point to spawn in when needed?

Should I alternate between a few points? Loading and unloading?

fluid remnant
#

Hello fellow devs.
How can I prevent diagonal movement?

 private void Update()
    {
        inputMove.x = Input.GetAxis(c_horizontal);
        inputMove.y = Input.GetAxis(c_vertical);

        if (inputMove != Vector2.zero && moveRoutine == null)
        {
            var dir = new Vector3(inputMove.x, 0, inputMove.y).normalized;
            Debug.Log(dir);
            moveRoutine = StartCoroutine(LerpPosition(dir, duration));
        }
}```
cosmic dagger
fluid remnant
polar acorn
heady nimbus
#

Yea, I'm trying to find examples, but I don't really know what I'm looking for yet.

I'm thinking alternating between 2 spawn points might work best as that keeps the overall size of the map down, but might be tricky with different sized zones

cosmic dagger
fluid remnant
fluid remnant
ivory bobcat
polar acorn
#

Check if your X value is nonzero. If it is, set dir to that X value.
If it's zero, set dir to that Y value.

#

Or vice-versa

finite meadow
#

where can i start learning code

#

havent learnt anything

#

i have 0 knowladge

polar acorn
eternal falconBOT
#

:teacher: Unity Learn

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

fluid remnant
# polar acorn You're still using two values for `dir`

something like this?

var horz = inputMove.x > 0 || inputMove.x < 0;
        var vert = inputMove.y > 0 || inputMove.y < 0;

        if (inputMove != Vector2.zero && moveRoutine == null)
        {
            var dir = new Vector2();

            if (horz && moveRoutine == null)
            {
                dir = new Vector3(inputMove.x, 0, 0).normalized;
            }
            else if (vert && moveRoutine == null)
            {
                dir = new Vector3(0, 0, inputMove.y).normalized;
            }
            moveRoutine = StartCoroutine(LerpPosition(dir, duration));
        }```
It works for left / right but doesn't work up and down for some reason
#

Oh wait. I wrote Vector2 intead of Vector3

#

I think it works

#

thanks for the push in the correct direction @polar acorn & @cosmic dagger

quiet dune
#

Hello, can someone tell me whether/how i can implement gizmos in one script that i can toggle individually (preferably from the unity editors gizmo menu)?

quiet dune
uncut dune
#

bounce a 2d object with a OnTriggerEnter2D?

cosmic dagger
uncut dune
#

like getting the same effect as a gameobject with rigidbody2d and collider2d with a bouncy material atached

#

but instead I want to replicate this behaviour on script with a trigger collider

#

I have done this in the past with a OnCollisionEnter2D but I cant seem to figure it out with trigger

#

bouncing off a wall btw

fluid remnant
#

just use raycasts

uncut dune
#

something like this

uncut dune
ivory bobcat
#

What's your actual question?

#

Vector 3 reflect

fluid remnant
cosmic dagger
quiet dune
uncut dune
fluid remnant
#

with raycast

uncut dune
#

ohhh alr

#

okay let me try

#

ty btw

quiet dune
#

@cosmic dagger Thanks!

uncut dune
# fluid remnant with raycast

can I just create the raycast itself when the object gets triggered by the wall or should I call it every frame checking if it is hitting the wall

cosmic dagger
ivory bobcat
#

If you're using physics trigger, you should be able to just create your direction given the difference in position of the two object and find the necessary normal thereafter

uncut dune
#

not sure if it would work

ivory bobcat
#

Convert coordinates to the appropriate space 🤷‍♂️

uncut dune
#

and I did something like this

#

but how would I find the trigger coordinates

ivory bobcat
#

I'm assuming you meant collision info etc

uncut dune
#

I guess so

ivory bobcat
#

Whereas this time you're only given info about the collider and have to use some math to obtain the direction yourself

weary crystal
#

Why building my game's stuck at "Finished" I'm building a game for Android, it's a small game everything else was done in 2 minutes but it's stuck on "Finished" from over 5 minutes...

uncut dune
#

collisionCoordinates - transform.position

#

now what do I do with it

#

because from what Ive seen I cant even find the collision coordinates with trigger

ivory bobcat
#

If you're wanting the normal to some surface, consider raycasting for ease of life on the trigger event

uncut dune
#

yup thats what I was talking about, so I can know to where the object should actually go

#

isnt raycast expensive tho?

ivory bobcat
ivory bobcat
uncut dune
#

alright, I'll try them

#

ty

weary crystal
#

I have a question, It is supposed to be in #💻┃unity-talk but I'm afraid nobody's active there right now, so I want to build the game for iOS, how can I build so my friend can install and play it?

#

For Android it's simple, you just install the apk and play.

uncut dune