#💻┃code-beginner

1 messages · Page 170 of 1

polar acorn
#

Just putting something in there to show that you can use x

cunning locust
#
if (realAge is int)
``` ?
polar acorn
#

you can check and cast at the same time

timid hinge
#

anyone know how can i put the same color on the background?

polar acorn
earnest atlas
#

React tranform. 3 dots on the right. Reset?

polar acorn
slender nymph
#
switch(age)
{
  case int x:
    //do int things
    break;
  case float y:
    //do float things
    break;
}
#

you almost never need to use the actual System.Type object for type checking something

polar acorn
earnest atlas
#

nor that u need to check for type

#

user input always must be checked and sterialized

#

Amount of crashes I had when I worked with user imput not being checked is a lot

timid hinge
slender nymph
earnest atlas
#

Im pretty sure compiler gonna complain

cinder spruce
#

@ebon robin i think i need to find a way to prevent the attack animations from playing when the enemy is moving

earnest atlas
#

wont best way be adding a variable that saves the gamestate and then check it?

polar acorn
earnest atlas
#

Like make attack bool variable and have if (attack) return;

timid hinge
polar acorn
timid hinge
#

where bro ?

#

sorry im slow

polar acorn
earnest atlas
cinder spruce
polar acorn
# earnest atlas

Oh right, on a non-URP project it's just right there. In URP it's in Environment but it's still there

timid hinge
#

thank you my man

terse yacht
#

how do i fix my code so when i look at a game object and click e it rotates/spins my thorw and change size ones work?

earnest atlas
#

dont call rigidbody rigidbody

#

cant you just tranfrom its rotation

polar acorn
earnest atlas
#

is it 3d or 2d?

terse yacht
#

3d

earnest atlas
#

float angle = rotationSpeed * Time.deltaTime;
transform.rotation *= Quaternion.AngleAxis(angle, Vector3.forward);

This is spat out by chatgpt. Looks somewhat legit

terse yacht
#

its for school so they having me do stuff weridly

tepid summit
#

a prefab can do close to anything a gameobject can

terse yacht
#

i been trying to put what they want me to do then work off that

tepid summit
#

my script is still broken can i get som ehelp

late bobcat
#

yeye i actually did it from the playercontrollerscript in the end @tepid summit but it was not working cause i didn't put a capital letter on "IsDashing" parameter in my script

tepid summit
#

oh lol

#

hate when that happens

late bobcat
#

it was like animator.SetBool("isDashing") instead of ("IsDashing")

tepid summit
#

yeah

#

or what about when you miss a ";" and dont realise

#

absolute pain

terse yacht
earnest atlas
#

Better yet when you named a variable and instantly forgot it

polar acorn
polar acorn
#

it's not an error, but it's an annoying warning

tepid summit
#

yeah

earnest atlas
#

they can tell whatever calling rigidbody rigidbody even compiler complains

terse yacht
tepid summit
#

same honestly

#

most yellow warning come from packages anyways

polar acorn
tepid summit
#

so i couldnt fix them if i tried

tepid summit
#

jesus

earnest atlas
#

Its just calling things what they are next time you will try to call Rigidbody you will call your variable

tepid summit
#

what

#

ok

#

great website

polar acorn
#

It's incredibly rude to come to a help forum and expect people to commit to solving your problem before you've even said what it is

earnest atlas
#

with chatgpt today its quite convinent

#

You can have no idea what u want and feed wall of text to it

#

And it might spit it out

tepid summit
#

iwas asking

#

its a perspective thing

earnest atlas
#

If it knows the code bad it hallucinates tho

#

I worked with Paradox script and it constantly messed up

polar acorn
# earnest atlas with chatgpt today its quite convinent

until it just straight up invents a new function that doesn't exist and then you post the question here and swear up and down the function exists because the spambot told you it did and you don't understand any of the code anyway because you let the chat robot do it for you

earnest atlas
#

Yeah it loves doing that

slender nymph
# tepid summit iwas asking

mate if you're asking for help before even providing any info about the issue, then yes, you are in fact asking someone to commit to helping you

earnest atlas
#

Its a tool

late bobcat
#

you can tell chat gpt that 2 + 2 is 5 and it'll say that you're correct and apologize for the inconvenient

terse yacht
earnest atlas
#

I remember feeding it 2 lists of names, I was trying to filter out list of mods I had repeated to update a collection.

It couldnt do it...

tepid summit
#

chatgpt is the smartest invention of the internet

#

im lying

earnest atlas
#

Ive spent 20 minutes telling him REMOVE repeated entries

#

It just spat me filtered list...

tepid summit
earnest atlas
#

Tho it instantly gave me pyton code to filter them myself

tepid summit
#

yeah

earnest atlas
#

Its getting lazy

tepid summit
#

because python is usually simple/easy

late bobcat
#

i'd say that gpt can give you a structure but most of the times you need to adjust it

tepid summit
earnest atlas
#

Before it was much better

#

At some point it got really bad

#

like you feed him part of function it calls something wrong in it and gives you back THE SAME function

tepid summit
#
    {
        RaycastHit hit;
        if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity))
        {
            if (Input.GetMouseButtonDown(0))
            {
             Destroy(RaycastHit.transform.gameObject ; GameObject);
            }
        }
    }```
polar acorn
tepid summit
#

one time i got it to make a pretty ok terrain generator

slender nymph
tepid summit
#

read the channel name

earnest atlas
#

Lmao wtat

tepid summit
#

of course my codes gonna be bad

polar acorn
#

Like what language is that even

slender nymph
#

also what happened to "that's not my issue anymore"

tepid summit
#

the error changed

slender nymph
#

yeah because you didn't know how to correctly do the thing you were trying to do

polar acorn
tepid summit
#

fine

#

ill do it myself

slender nymph
#

seriously, go through some basic c# courses and maybe you'll actually have a chance at succeeding when attempting to do it yourself (again)

terse yacht
earnest atlas
#

even chatgpt cant fix that

#

what u event want to do with this?

#

Normally hits are counted with OnTrigger or

#

with function

slender nymph
#

they want to destroy a gameobject hit by a raycast

earnest atlas
#

what is raycast?

terse yacht
earnest atlas
#

Yeah as I though

#

Its a line

#

Are you shooting a laser?

terse yacht
#

so i have my raycast code so when i look at object i can interact with E and it can do things if i make scripts for it like i have that kick it accros room and one to change size i still need roataion and 2 more

tepid summit
#

changed the function entirely

   public GameObject Tile;
    void FixedUpdate()
    {
        RaycastHit hit;
        if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity))
        {
            if (Input.GetMouseButtonDown(0))
            {
             if(hit.transform.tag == "tiles")
                {
                Tile = hit.gameObject;
                }
                else 
                {
                Tile = null;
                }
            }
        }
    }```
terse yacht
#

this is what i got

late bobcat
terse yacht
#

the instruction i was given and my error and raycast

polar acorn
terse yacht
#

then how do i fix it cause it say left right up forward down backwards are all not viable so i tried .one and it also said the error

slender nymph
#

none of those are methods. those are all properties. what are you expecting them to do?

polar acorn
cunning locust
#
string name = "Bob";
int length = name.Length;

Since 'B' is at the index of 0, shouldn't i put name.Length-1?

cuz u know, "Bob" length would be 3 letters, while 'b' at the end is at the index of 2.

polar acorn
#

This is just assigning two variables

cunning locust
#

Typewritter effect, just an example here

slender nymph
cunning locust
#

This might be unity related tho, how can u know

polar acorn
terse yacht
earnest atlas
#

Leave something to us people who more or less know C# but are dealing with unity and bored

slender nymph
rocky canyon
#

thats basic C# code, thats simple code u can run standalone.. theres nothing Unity related to it

earnest atlas
slender nymph
cunning locust
polar acorn
autumn schooner
#

Now, when I sync the script with the game object after rendering the line, I get this error. Can anyone help me with this?

terse yacht
slender nymph
earnest atlas
#

what you mean by neat an clean?

polar acorn
rocky canyon
terse yacht
slender nymph
terse yacht
#

those are my instruction

polar acorn
terse yacht
slender nymph
#

so you just guessed? or was it code given to you by an AI? we're trying to understand the thought process behind the choice to write that

rocky canyon
#

Vector3.left is just a Vector.. (1,0,0);

terse yacht
rocky canyon
#

atleast ur honest

terse yacht
polar acorn
#

Or you could use Google and actually learn something instead of just trusting the spam generator

earnest atlas
#

Im just dealing with background rn

terse yacht
#

ya but i dont think it follows my rules/ instructions

earnest atlas
#

And I dont understand vectors really well

slender nymph
#

it is against server rules to answer questions using AI generated responses

earnest atlas
#

oh sorry didnt know

rocky canyon
#

it says create a script to rotate an object

#

it doesnt specify how u must do it

terse yacht
rocky canyon
#

its one of those first fundamental things u learn, shouldnt be hard to find a solution that works

terse yacht
#

🤦‍♂️ i should have read insted of skim

#

wait

#

no

#

thats the name of the code

earnest atlas
#

wait what did you thought it was?

rocky canyon
#

ya, thats all it tells u

#

to name it that..

#

then u can do w/e u want inside of

#

as long as it rotates an object b/c of a player interaction

#

and those are also just examples it says

#

lol

polar acorn
#

please learn how C# works

terse yacht
#

🤦‍♂️ god i hate this course thanks

earnest atlas
#

what is even that course?

rocky canyon
#

highschool game-dev

terse yacht
#

mastery coding | unity 1

earnest atlas
#

We got thrown from 2d to 3d back to 2d

terse yacht
#

i go to tech school

#

so i get certifed for it when i pass exam

rocky canyon
#

there ya go, its a course written up by his professor, its not an online course

earnest atlas
#

I have a suspition it was written long ago

rocky canyon
#

you know how schools are 😄

#

recycling the same workbooks for decades

earnest atlas
#

I had a teacher that reused same exam for like 12 years

terse yacht
rocky canyon
terse yacht
#

tbh he dosnt do much

rocky canyon
#

like mathmatics dont change much.. so why make a new exam/

earnest atlas
#

I mean everyone had a copy of it

rocky canyon
#

ohh, lol

earnest atlas
#

yeah

rocky canyon
#

let me buy a copy of that exam u took last year pal

earnest atlas
#

For last 12 years XD

#

How to save scene in play mode. I edited few things and want to save it on place they are

rocky canyon
#

u copy the values of the things u changed and paste them in when ur not in playmode 😄

swift crag
#

There are add-ons for doing that. It's not something Unity provides.

earnest atlas
#

I dont think thats possible to copy

swift crag
#

well, Cinemachine has some code for remembering vcam modifications

rocky canyon
#

ya all changes in playmode revert back to defualt when u quit

#

yea some components keep their values

#

but not most

earnest atlas
#

Yeah it makes sence, but when you want to change something :C

rocky canyon
#

i keep a notepad next to me to jot down new values for that exact reason

rocky canyon
#

best method ive found so far.

earnest atlas
#

Yeah I know that I just moved a lot of things

rocky canyon
#

ohh well gl 😄

charred spoke
swift crag
#

yeah, that's just what it's used for

#

I've never tried using it anywhere else

rocky canyon
charred spoke
#

[SaveDuringPlay]

#

Its part of cinemachine

rocky canyon
#

ive only ever glanced at cinemachines internal code

#

thats good to know

charred spoke
#

Im still torn of adding to our package but we use cinemachine for every project so….

tepid summit
#

ive looked actually in the four corners of the universe

#

i went to the 3rd page oif google

rocky canyon
#

the third page.. wOOooo

#

just kidden, theres usually not much past that tbh 😄

terse yacht
#

well i tried my way and idk why thats not vaild

rocky canyon
#

ur class doesn't have a variable called objectTransform

#

and update() is wrong.. its actually Update()

#

transform.Rotate <-- this would rotate the transform thats attached to the script

#

but if u want to use objectTransform u need to declare and assign it

terse yacht
#

... ight ill try againg ty

tepid summit
#

HOLY SHIT

#

IM A GENIUS

earnest atlas
#

what?

terse yacht
earnest atlas
#

Where did clouds go??

rocky canyon
#

idk click them in the hiearchy and find out

earnest atlas
#

They are in the scene.

#

Thats the same thing but one is in Game other is scene

#

they jsut gone?

rocky canyon
#

i know.. CLICK THE OBJECT in the hiearchy and look at the gizmos in teh scene (while the game is playing)

earnest atlas
rocky canyon
#

it'll have a gizmo on top of em (itll show where it is)

terse yacht
#

lol it spins but not when i interact with it it dose right off start

earnest atlas
#

Because you made it just spin al time I belive

#

yeah your toogle turnin does nithing in that code

#

you need
if(IsTurning) your code

terse yacht
#

ohh ya its in update not a if isturning true

rocky canyon
earnest atlas
#

if you want you can make something like this

rocky canyon
#

it will snap to it.. and then you'll atleast know where it is

honest haven
#

using if and if else do i need to end on an else? or can i just use if else

rocky canyon
#

@terse yacht the assignment actually says to use Player interaction.. so u need more than just spinning.. u need to check for inputs (from the player) and then make hte thing spin

earnest atlas
#

private IEnumerator rotate()
{
while (true)
{
while (isRotating)
{
//rotate object
}
}
}

terse yacht
#

ya ik thats what i been tempting i have my raycast code so when i look at object and tap E it runs the code it works for my throwing and change size

terse yacht
#

i just need to fin out how to make my if statement be ran when the interaction happens cause i looked at my other ones i have and tbh i dont have a single clue even how they do run

candid gorge
#

hey everyone, could someone help me please? I'm making a character controller with the input system and I'm having some troubles with interactions.
When I press E it seems that the button sends multiple actions.
Here in the video you can see that 3 cubes get created instead of 1 and I get damaged three times instead of one too

#

I think the problem is within this code

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

public class Iteractor : MonoBehaviour
{
    public GameObject cam;
    public float reachDistance = 8.0f;
    public LayerMask layerMask;

    private PlayerUI playerUI;

    private void Start()
    {
        playerUI = GetComponent<PlayerUI>();
        playerUI.UpdateText(string.Empty);
    }

    public void OnInteract(InputAction.CallbackContext context)
    {
        Interact();
    }

    private void Update()
    {
        playerUI.UpdateText(string.Empty);
    }

    public void Interact()
    {
        playerUI.UpdateText(string.Empty);

        Ray ray = new Ray();
        ray.direction = cam.transform.TransformDirection(Vector3.forward);
        ray.origin = cam.transform.position;

        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, reachDistance, layerMask))
        {
            hit.collider.gameObject.GetComponent<IUseable>().BaseUse();

            if (hit.collider.gameObject.GetComponent<IUseable>() != null)
                playerUI.UpdateText(hit.collider.gameObject.GetComponent<IUseable>().promptMessage);


        }

        Debug.DrawRay(ray.origin, ray.direction, Color.red);
    }
}```
rocky canyon
#

ur probably using GetKey

#

and not GetKeyDown

candid gorge
#

im not using the old input system

#

is the new one

rocky canyon
#

or ya its the way its set up in the input manager

candid gorge
#

its set up like this

earnest atlas
#

You can make discord read that code as C# by just writing it like this
/``C#
Code
```

candid gorge
#

oh oke thx

eternal falconBOT
earnest atlas
#

Yes at all

#
int variable
rocky canyon
earnest atlas
#

hmmm what will happen with cs

int variable = 1f
#

kinda same

rocky canyon
#

not sure how to get to this menu as i dont use that system, but that thread should point u the right way

earnest atlas
#

Yeah its same as C# of CS to mark code as C sharp

rocky canyon
#

u can set the key to be a single press if u want..

candid gorge
earnest atlas
#

Should I add objects I want as Public or find them from parent object?

rocky canyon
#

if u can assign them in the inspector

wintry quarry
rocky canyon
#

public GameObject ^ that
or

meager steeple
#

when making code for onclick on a button should i put the code in start() or update()

rocky canyon
#

but u'll know whether or not u need public or private variables

wintry quarry
terse yacht
#

im so lost idk how in any way my other two scripts even interact on E with raycast

earnest atlas
#

I mean its app as asigment so I dont think it really matters that its not protected

terse yacht
#

stg going to lose it

meager steeple
candid gorge
signal bronze
#

I need to create a jumpscare, like when both of the hitboxes collide, the video appears and when the video ends the lvl restart, im new and this is taking me a lot of time and im not able to do it, can somene give me a hand please? (I want that when the enemy catches u, the video appears like a jumpscare and then restart the scene)

#

Ping me if u know how to do it, because im lost

modest dust
#

Break it down into steps and tell us where you're stuck at

eternal needle
signal bronze
#

just the part where the hitbox collide and the video appears to restart the level

rocky canyon
#

the video part is easy, use a video player, and play a clip

signal bronze
eternal needle
#

That again is multiple problems in 1. Break it down further
First try to detect collision, then do something based on that collision.
Then learn to play video. Then learn how to know when the video ends

earnest atlas
#

restart deletes all object so be sure you do it after video finishes

#

he can start coruitine with wait time as of video leight

signal bronze
modest dust
rocky canyon
earnest atlas
eternal needle
terse yacht
cosmic quail
teal mantle
#

Hello guys I have a problem with animations. I have an Idle Animation and a running animation. When i stop running, the sprite looks like the last frame of the run but the idle animation continues. Can i send a video her to show that?

meager steeple
#

can i do that? its circled and grey so im not sure if its meant to be called something specific..

#

but like surely you can name it anything you want

polar acorn
earnest atlas
#

For some reason my visual studio cant detect unity Update, Start, etc

#

So probably correct but same issue

meager steeple
earnest atlas
#

no

polar acorn
terse yacht
#

im so lost idk how in any way my other two scripts even interact on E with raycast

rocky canyon
#

#💻┃code-beginner message
#💻┃code-beginner message

i posted yesterday on how to use events.. the same thing would kinda apply to ur event.. in the script doing the check it would have the event.. u fire that event off when u click or w/e and then in ur other scripts they'd be subscribed to that event.. and when the event goes offf anything listening will act on it

signal bronze
teal mantle
rocky canyon
#

u would want to wait for the video to be over.. b4 u did any of that

teal mantle
#

The characters eyes glitching around. The Idle Animation dont have a bigger eye to blink so i dont even know how it can blink xD

signal bronze
rocky canyon
#

then ur collision isnt working correctly.. and u shoulda stopped there and figured out that problem. b4 u added in all the other nonsense

#

but ChatGPT be like that

terse yacht
#

they do apply to what im doing but i just cant grasp how my change size and my throw scripts can be use with the interact raycast beside when in unity you drag the code to he raycast and then select what event to happen but my issue still resides with when i start my game objects are spinning instead of when i tell them by looking at them and pressing E @rocky canyon

cosmic quail
#

if u dont have any triggers

rocky canyon
cosmic quail
#

and remove the Time.timeScale part and everything works

signal bronze
terse yacht
#

they do apply to what im doing but i just cant grasp how my change size and my throw scripts can be use with the interact raycast beside when in unity you drag the code to he raycast and then select what event to happen but my issue still resides with when i start my game objects are spinning instead of when i tell them by looking at them and pressing E @rocky canyon

rocky canyon
#

wrap ur stuff in a boolean... if(youShouldRotate){//rotateCode}

#

in the event u can toggle it on.. youShouldRotate = true;

#

its probably easier just to use WASD keys, (Input.GetAxis) and rotate based on the input ur giving.. but idk

terse yacht
#

i do most likely not correctly

rocky canyon
#

ya thats nonsense

#

if(isTurning == true) <-- thats a proper conditional check

terse yacht
rocky canyon
#

u declare it as a float elsewehre.. like in the header of ur script

signal bronze
#

Like this @cosmic quail ?

rocky canyon
#

just to say ur gonna be using one..

bool isTurning = false;

cosmic quail
signal bronze
#

okay

rocky canyon
#

get that working first.. and then add the event..

#

then make sure the event is working..

#

then.....

cosmic quail
rocky canyon
#

u have like 8 scripts all jumbled together.. makes anyone trying to debug with u difficult

terse yacht
polar acorn
meager steeple
#

how do i test if my button for quitting the game works?

rocky canyon
#

instead of adding to and removing stuff... watch some material on Events first..

#

until u feel u understand it completely

#

then return

#

building off of a system u never understood is bound to end badly

slender nymph
terse yacht
#

well i do i just dont understand how they connect ot the ray cast ik when i done making them i can go to unity and attach the code to the ray cast then play and it work i just dont understand how the turn one wont work i can attach it to the ray cast just it spins off the start instead when i look and press e

rocky canyon
#

the raycast is its own thing.. u would use it to invoke the event..

meager steeple
rocky canyon
#

it COULD possible do anything

#

so figure out how the raycast works first.. and then move foward

signal bronze
#

This appeared before i did nothing @cosmic quail

cosmic quail
tough lagoon
eternal falconBOT
wintry quarry
terse yacht
cosmic quail
#

void OnCollisionEnter(Collision other)

#

@signal bronze

signal bronze
polar acorn
wintry quarry
signal bronze
rocky canyon
#
 Ray ray = Camera.main.ScreenPointToRay(pos);
 RaycastHit hit;

if (Physics.Raycast(ray, out hit, distanceOfRay))
{
  // We hit something
  // now check if its the thing we want to hit
  // if it is invoke the event
}
else
{
  // we hit nothing
}```
#

a simple raycast running in update would be ALL u need for the raycast.. and then the event..

#

u reference that script in ur main script (the one meant to be listening) and subscribe to the event

#

then when the raycast triggers the true condition AND the hit the right object condition.. ur event just works

signal bronze
rocky canyon
#

i could write out ur system for you. but that wouldn't be benificial to you at all.

#

besides just getting the assignment finished

terse yacht
rocky canyon
#

they need to know about the script that has the original event in it

#

so they can subscribe to it

terse yacht
#

but shuld'nt they know what it is casue this

rocky canyon
#
public class EventListenerScript : MonoBehaviour
{
    private void Start()
    {
        ShootingScript.OnRaycastHit += HandleRaycastHit;
    }

    private void HandleRaycastHit()
    {
        // Do something when the raycast hits
        Debug.Log("Raycast hit!");
    }
}```
#

^ has ShootingScript (the raycast) -> has access to the Event (OnRaycastHit) += (calls this scripts HandleRaycastHit)

#

when the event gets invoked in teh raycast script.. this script will run its own respective function (that we set to be HandleRaycastHit(); )

#
    void ShootRaycast()
    {
        // Raycast hit something, trigger the event
        if (hit.collider != null)
        {
            OnRaycastHit?.Invoke();
        }
    }```
#

the raycast script would then invoke if it exists which is what the ? represents

terse yacht
#

okay i understand that but how to my other scrpits know becasue i want it to be like them and they dont do this method

rocky canyon
terse yacht
#

this is one that works

rocky canyon
#

u give them a reference to the script with the raycast and the event

terse yacht
#

where?

rocky canyon
#

[SerializedField] private ShootingScript myShootingScriptReference;

#

in the script that needs to know about the event

marble trout
#

Im Trying to make a Tower Defence Game and right now I have the issue that the turret doesnt shoot and recognize the Zombies spawned in spawner. I need help and im new to c#/unity

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

public class Tower : MonoBehaviour
{
    public float range = 10f;
    public float fireRate = 1f;
    public GameObject projectilePrefab;
    public Transform firePoint;

    private Transform target;
    private float fireCooldown = 0f;

    void Update()
    {
        if (fireCooldown > 0)
        {
            fireCooldown -= Time.deltaTime;
        }

        if (target == null || Vector3.Distance(transform.position, target.position) > range)
        {
            // No target in range, find a new target
            FindNewTarget();
        }

        if (target != null && fireCooldown <= 0)
        {
            // Fire at the target
            Shoot();
        }
    }

    void FindNewTarget()
    {
        Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, range);
        float closestDistance = float.MaxValue;

        foreach (Collider2D collider in colliders)
        {
            if (collider.CompareTag("Zombie"))
            {
                float distance = Vector3.Distance(transform.position, collider.transform.position);
                if (distance < closestDistance)
                {
                    closestDistance = distance;
                    target = collider.transform;
                }
            }
        }
    }

#
    void Shoot()
    {
        fireCooldown = 1f / fireRate;

        // Instantiate the projectile and set its direction
        GameObject projectile = Instantiate(projectilePrefab, firePoint.position, firePoint.rotation);

        // Calculate direction to the target
        Vector3 direction = (target.position - firePoint.position).normalized;

        // Move the projectile towards the target
        Rigidbody projectileRb = projectile.GetComponent<Rigidbody>();
        projectileRb.AddForce(direction * 10f, ForceMode.Impulse);
    }
}
meager steeple
#

why is it when i click exit game that button stops highlighting when i hover over it but none of the other buttons stop

rocky canyon
#

b/c that button is now in a different state..

meager steeple
#

but why is nothing else

rocky canyon
#

its been selected and will remain selected until u either unselect it with ur code.. or click a different button

#

b/c u didnt click any of the other ones??

meager steeple
#

ah

rocky canyon
#

same would happen to any other button u click first

meager steeple
#

no but its not the selected colour its highlighted colour

rocky canyon
#

ya, selected color would be the color it is while ur holding down on it

#

once u release it has been selected

#

it would be one of those other colors farther down

swift crag
#

I believe the "selected" color beats the "hover" color

rocky canyon
#

^ trial and error for me.. i always have to play around with the buttons

swift crag
#

Your exit button does nothing in the editor, so you're just noticing that it's now selected

rocky canyon
#

^ if the scene were to change u wouldnt notice 😄

swift crag
#

I imagine your other buttons cause something to happen that makes the button go away

rocky canyon
#

b/c u couldnt continue to hover it

swift crag
#

so you haven't noticed this before

#

try clicking down on a button, then moving the mouse off before you release

#

you should see the same behavior

rocky canyon
#

^ yup yup

meager steeple
#

idk what im doing wrong its not logging it ;-;

rocky canyon
#

it doesnt appear to ever be called

short hazel
#

"0 references"

swift crag
#

does that reference counter have any idea about unity events though

rocky canyon
#

^ ohh lmao definitely then

swift crag
#

show us the inspector for the Button component, including the "On Click" event

meager raptor
#
public void HandleUnitMovement() {
    // Checks if left mouse button is clicked on the unit
    if(Input.GetMouseButtonDown(0)) {

        // Create a ray from the camera to the mouse position
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        // Perform a raycast to detect if the mouse is pointing to an object
        if (Physics.Raycast(ray, out hit)) {

            // Get the layer of the object hit by the ray
            LayerMask layerHit = hit.transform.gameObject.layer;

            // Check the layer value using a switch statement
            switch (layerHit.value) {
                case 8: // Case 8: The object belongs to layer 8 (Assumed to be units)
                    SelectUnit(hit.transform, Input.GetKey(KeyCode.LeftShift));
                    break;
                default: // Default case: Deselect all units for layers other than 8
                    DeselectUnit();
                    break;
            }
        }
    }
}
private void SelectUnit(Transform unit, bool canMultiSelect = false) { // Method to select units
    if (!canMultiSelect) { // Deselect all units if multi-selection is not allowed
        DeselectUnit();
    }
    selectedUnits.Add(unit); // Add the selected unit to the list
    unit.Find("Highlight").gameObject.SetActive(true); // Activate the "Highlight" game object
    Debug.Log("Highlighting Unit");
}```

purpose: when selecting unit, there should be a circle beneath the unit that indicates
problem: this circle doesn't show. the debug log doesnt appear in the console, i have a layer named Units in the 8th layer, any help would be appreciated
rocky canyon
#

its private

#

it wont appear in the button

short hazel
#

Unity events can reach private methods? wtf if true
They can't seem to program anything properly

signal bronze
#

@cosmic quail When the monster touches me, the lvl restart but the video is nowhere to be seen

terse yacht
#

@rocky canyon omg u should be proud i found my issue i dont need a if statement i need a public void then i named turn(bool isTurning)

meager steeple
terse yacht
#

then i was able to set a toggle

swift crag
#

You must select a public method from the dropdown. Make that method public

terse yacht
#

and now is kinda works it turns via every clikc of e .25

rocky canyon
#

unit.Find("Highlight").gameObject.SetActive(true); // Activate the "Highlight" game object debug this value and see if it find a "Highlight"

swift crag
meager steeple
#

ahhhh

swift crag
#

Unity won't just call random functions (:

static bay
meager steeple
#

dum dum

swift crag
signal bronze
swift crag
#

although apparently they might not be sticking around because of some glitchiness? i dunno

meager raptor
rocky canyon
# meager raptor Nice 👌

not sure how u want to do it.. ```cs
public void Deselect()
{
selected = false;
enabledGraphics.SetActive(false);
AudioManager.Instance.PlayClip(deselect_Clip,7.5f);
}

public void Select()
{
    selected = true;
    enabledGraphics.SetActive(true);
    AudioManager.Instance.PlayClip(select_Clip,7.5f);
}```

but i enable and disable my selection graphics from the unit itself

signal bronze
rocky canyon
#

i have a list.. and if the unit isnt already in that list.. i call Select();

#

if it is already in the list i call Deselect();

meager raptor
rocky canyon
#

it takes care of its own graphics.. (b/c the graphics are already on that unit)

#

and its assigned in the inspector.. (this avoids any issue of having to hunt down those graphics)

swift crag
#

mmm, RTS selection mechanics

#

i had a ball figuring that out a while ago

rocky canyon
signal bronze
#

ok ill try

rocky canyon
#

if(videoIsPlaying) <-- turn this on once the video starts...

meager raptor
rocky canyon
#

and then inside that ifstatement u can check if its finished plyaing

meager raptor
rocky canyon
#

if it didnt find anything it still should have printed something i think

#

its disabled bro

#

how is it supposed to find it?

meager raptor
#

Yeah then I enable it by clciking it

rocky canyon
#

ya but the FIND method wont find it

#

so how u gonna enable it?

meager raptor
#

Okay I'll try that sorry am lil new to this stuff

rocky canyon
terse yacht
rocky canyon
#

we've all been there

signal bronze
slender nymph
eternal falconBOT
slender nymph
#

there are also several things wrong with that, but having configured tools is a requirement to get help here #854851968446365696

signal bronze
slender nymph
#

because you do not have intellisense, error highlighting, or even proper syntax highlighting

polar acorn
#

Why should we waste our time checking your spelling when you could literally prevent those errors from ever happening by configuring your IDE

signal bronze
#

okay, so i click in Visual Studio (Installed via Unity Hub)?

polar acorn
meager raptor
# rocky canyon

still aint working, do u know whether it's a code error or something else

signal bronze
#

nope, installef from microsoft web

polar acorn
signal bronze
#

thats a good question

#

i know the answer

#

because im stupid as fck

teal mantle
ivory bobcat
#

I've got no audio. Was there an actual question and is it related to coding?

teal mantle
#

Ah yes, my bad. The problem is that after i run it wont get back to the idle animation or infact it does but the animation is glitched. The eyes look different after the run but still are animated

rocky canyon
signal bronze
rocky canyon
#

best thing to do is have it already assigned somewhere

meager steeple
#

idk what im doing wrong ive tried alot of things and i still cant select my script from the drop down for the onclick function

meager raptor
signal bronze
slender nymph
#

several things are wrong here. first, that path is not going to work outside of the editor

#

second, you load the scene immediately after playing the video so the video does not have time to play before the scene is destroyed

signal bronze
#

shit

polar acorn
signal bronze
meager steeple
polar acorn
#

you were just told this

meager steeple
#

i set it public and still same thing

polar acorn
slender nymph
# signal bronze how do i change both of the things u just said?

for the first, instead of loading the video like that, you should create a prefab that already has a VideoPlayer component with the correct video assigned to it, or just have it in the scene somewhere and just spawn/reference it here then call Play.
for the second, you should start a coroutine or something that waits until the video has finished playing then loads the scene

signal bronze
#

ok

#

ill try

meager steeple
polar acorn
#

not the text file

swift crag
#

You've dragged the actual script asset -- the thing Unity uses to keep track of where your code is

meager steeple
#

ffs

#

usually it doesnt let me move a script in there if it wouldnt work

swift crag
meager steeple
#

you prolly think im waffling

swift crag
#

that's why you see such an enormous pile of options if you open the "Select" window

#

i should figure out where all of these empty-named objects are coming from...

slender nymph
polar acorn
#

But you don't want to change any properties of the script file

swift crag
polar acorn
#

you want to access a function on an instance of the script

swift crag
#

compare that to, say, a GameObject field

#

which is very particular: it wants a game object, and nothing else

signal bronze
slender nymph
#

i explained what you should do. if you do not know how to do that, then you should start with the basics by going through the pathways on the unity !learn site

eternal falconBOT
#

:teacher: Unity Learn ↗

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

meager steeple
#

i dont understand so i'll just stick to this

#

debug works

#

thank you

swift crag
meager steeple
#

adding the script to a game object and using that

polar acorn
#

There isn't really an alternative

swift crag
# meager steeple adding the script to a game object and using that

Right.

When you dragged the exitGame script asset from the Project window into the On Click event, you were telling Unity that you wanted to do something to the script asset.

When you add the exitGame component to a game object, you're creating an instance of the class that script contains. It's stored on the game object.

#

So when you dragged that game object into the On Click event, you were telling Unity you wanted to do something to that object (or that object's components)

meager steeple
#

ahhh

swift crag
#

When you attach a component, Unity writes down the unique ID of the script asset

#

(which is why you can rename the class and the script file without existing components breaking)

#

(it only cares about that ID)

meager steeple
#

mhm

swift crag
#

you can literally just replace it with another script's ID and the component will suddenly be another type. I've done that a few times before for...reasons

#

but yeah -- if you see MonoScript, you've got something wrong

meager steeple
#

ok

#

thank you

polar acorn
#

So you can create a Modding API without having to include the entire game's scripts

swift crag
#

That's clever.

#

I've been thinking about how you'd actually...make a modding interface

#

I hadn't considered that idea at all though

polar acorn
#

Yeah I felt pretty clever when I came up with that.

Never finished the project of course but it was a pretty cool system

swift crag
#

😅

signal bronze
#

@slender nymph I created a video player, whith the video i want, but how do i modify the script to select tha video player? And right now the video actually plays, but only the sound when i start the scene

swift crag
#

I'm having enough fun with serialization right now

#

i'm not even going to think about modding..

slender nymph
meager steeple
#

@swift crag would it be possible to add the script to the button itself and then select itself for the onclick function

#

just to save memory or whatever not making too many objects

rocky canyon
#

if the button is active in the scene.. then why wouldn't it?

#

u can add as many script/ components as u want.. to any object

#

except a few edge-cases, which the editor just wont allow u and will show u a popup error as to why

meager steeple
#

👍

#

that makes it easier

rocky canyon
swift crag
#

Don't worry about making too many objects.

rocky canyon
#

organization may be more important

swift crag
#

In fact, you should worry about not making enough objects!

rocky canyon
#

^ id make it its own object

#

ButtonController or something

swift crag
#

making things neat and tidy will make your life easier

swift crag
#

these could absolutely all be mashed onto one object

meager steeple
#

is there any way i can "optimise" it?

swift crag
signal bronze
rocky canyon
swift crag
#

If this is an Exit Button, it makes sense to have the "Exit Game" component on the Exit Button

rocky canyon
#

😈

oak flame
#

hello, is there any help channel? or can i ask for help here

swift crag
signal bronze
swift crag
#

In that case, it'd probably go on something more like a "game controller"

signal bronze
slender nymph
#

remember how i said you need to get a reference to the VideoPlayer

meager steeple
#

what would be the best way to for example open a settings menu, would it be better to just hide all the other objects and show the new ones, or create a new scene for it?

earnest atlas
#

Scene load deletes everything from previus scene

slender nymph
earnest atlas
#

https://www.youtube.com/watch?v=YOaYQrN1oYQ

same guy who did 2d guide kekw

Learn how to make an in-game options menu using Unity!

● Sign up for the Devdog Christmas Calender: http://bit.ly/DevdogGiveaway
● START MENU in Unity: https://youtu.be/zc8ac_qUXQY
● Ultimate Game UI: https://www.assetstore.unity3d.com/#!/content/53973?aid=1101lPGj

♥ Support Brackeys on Patreon: http://patreon.com/brackeys/

··················...

▶ Play video
slender nymph
earnest atlas
#

Oh, I know only LoadScene atm

slender nymph
#

well yes, that's how you load a scene. but you can do so additively

meager steeple
slender nymph
#

you'd really just have to profile it if you have performance concerns

meager steeple
#

what does that mean?

slender nymph
meager steeple
#

thank you

rocky canyon
#

you can see that my Master Scene always sticks around.. it loads in a Level scene and unloads the main menu

#

all in the same (place)

earnest atlas
#

Are corutines async?

Like in Android?

slender nymph
#

yes and no. they are not async as in the technical meaning with the async modifier. but they are async as in they do not have to fully complete immediately and are evaluated at specific parts of the frame to determine if execution should continue

earnest atlas
#

what happens if one corutine is called multiple times. It creates multiple instances of such running in parrarel?

slender nymph
#

yes

rocky canyon
#

thats how come we can use StopCoroutine() and pass in a certain coroutine

#

or StopAllCoroutines() setc

earnest atlas
#

and how do we find specific corutines?

rocky canyon
#

u cache them b4 u start it

earnest atlas
#

Oh, I see

rocky canyon
#

or while u start it rather

slender nymph
#

you don't "find" them. you keep a reference to the coroutine returned by StartCoroutine if you need to stop a specific one

earnest atlas
#

Yeah I got it

#

Do they auto cleanup when finished if they were saved in the list

#

or I need to run check for nulls to clean up the list

rocky canyon
#
    private void Start()
    {
        // Start the coroutine and cache the reference
        myCoroutine = StartCoroutine(MyCoroutine());
    }```
#

like so

earnest atlas
#

Yeah I know that, I more or less know C# shenanigans

rocky canyon
#

cool cool, never kno around here

earnest atlas
#

yeah

#

move player left

#

XD

rocky canyon
#

but im not sure what u mean by needing to cleanup after they're finished.. im not that advanced

slender nymph
earnest atlas
#

I mean when corutine stops running but you still have the pointer to them in the list, does it delete itself or pointer becomes null adding need in cleaning them up

slender nymph
#

neither of those things happen

earnest atlas
#

What does then happen? It eats memory?

slender nymph
#

because, again, normal objects do not magically become null.

#

c# does not have the concept of "destroyed" like unity does. if something references an object it will stay in memory until sometime after it is no longer referenced by anything when it will get garbage collected

rocky canyon
#

The Coroutine object still exists, but it represents a completed coroutine.

earnest atlas
#

is there a way to find out if corutine is completed?

rocky canyon
#

.isRunning()

#

i think

earnest atlas
#

isnt that with animations?

#

or animations are corutines in trenchcoat?

rocky canyon
#

lol, nvm there is no isRunning

earnest atlas
#

probably isAlive

rocky canyon
#

i dont think.. let me check.. come to think of it

#

how do you/

#

ahh, ud need to implement that

slender nymph
#

you don't. you would typically assign null to the variable holding its reference at the end of the coroutine

rocky canyon
#

    IEnumerator MyCoroutine()
    {
        isCoroutineRunning = true;

        yield return new WaitForSeconds(3f);

        isCoroutineRunning = false;
    }```
#

this would work, i think

eternal needle
#

Store the coroutine and check if its null

earnest atlas
#

how would you find out corutine variable from the list?

rocky canyon
#

Coroutine firstCoroutine = runningCoroutines[0];

earnest atlas
#

If its not first.

rocky canyon
#

same way ud find any type in a list i think

eternal needle
rocky canyon
#

ud search thru the list using ur cached coroutine?

rocky canyon
eternal needle
#

It sounds odd that you have a list of coroutines and need to find a specific one

earnest atlas
#

Lets imagine we have list of corutines, we have corutine 5 that has finished.

we want it removed

slender nymph
#

why would you have a list of coroutines though

earnest atlas
#

Only pointer to it is the same list

#

Its just theory

#

If corutine is just another object we can temporaly hold a variable in it that consist of its position in the list

#

and use it to just remove itself

#

issue comes with other lists that now have outdated position list

rocky canyon
#
        if (runningCoroutines.Count > 0)
        {
            Coroutine firstCoroutine = runningCoroutines[0];
            if (firstCoroutine != null)
            {
                // still running
            }
            else
            {
                runningCoroutines.RemoveAt(0);
            }
        }```
#

this thread im reading seems to imply it does go to null

#

after it finishes 🤔

slender nymph
#

Coroutine does not just become null though

rocky canyon
#

yea.. hold up.. let me read farther

earnest atlas
#

Once the coroutine is finshed, Unity will no longer hold reference internally to the Coroutine or the IEnumerator as it is done with it. However when you hold that instance in your own variable, it would stay there useless forever. Your variable can only become null when you set it to null.

#

In unity discussions

rocky canyon
#

ohhhh thats probably what they mean ^

earnest atlas
#

They say same thing box did

#

When you store them they are there forever

rocky canyon
#

can u link the thread ur lookin at?

earnest atlas
#

Just chilling

#
rocky canyon
#

thanks!

#

i need to list up some coroutines just for fun..

#

ive never stored more than a single reference to a coroutine

slender nymph
#

Coroutine inherits from YieldInstruction which does not inherit from anything else. neither of which have an overloaded == operator that checks against a fake null like UnityEngine.Object has so it has no way to turn null on its own like UnityEngine.Objects

rocky canyon
#

kinda vague on how any of that works tbh

swift crag
#

The vital thing to understand is that no reference "becomes null", ever

rocky canyon
#

unless u manually set it to null

swift crag
#

Destroyed Unity objects just compare true against null

eternal needle
#

Having a list of coroutines that you need to care about in general already sounds like a shit design tbh. It's not like they would be acting all on their own variables

earnest atlas
#

So basically never to hold corutines in a list if you dont want to write 1000 lines to handle it

swift crag
#

i.e. foo == null is true when foo is a destroyed Unity object.

swift crag
#

There is no magic. Unity can't set your variable to null behind your back.

polar acorn
eternal needle
rocky canyon
slender nymph
earnest atlas
#

If its simple how would u manage it xD

polar acorn
#

So technically it doesn't become null, it's just no longer referenced and will get GC'd

swift crag
rocky canyon
swift crag
#

so I just made a List<IEnumerator> and wrote a bit of logic to manage the "coroutines" myself

slender nymph
eternal needle
#

I think it would make more sense to pass the actual coroutine reference if things are being removed from the list

earnest atlas
#

Issue is that if you do that your next corutine in list will get broken cause list now is 1 space shorter after you clean up the null

slender nymph
earnest atlas
#

Here I have a leg and Im gonna pass the same leg to that leg

rocky canyon
#

soo, since we're speaking on null's is this fine for its purpose? if i have a lookTarget we look at it.. if not we dont..
i wrote it this way so i could have the same script on things that look and dont look, i just leave the inspector blank for the ones that dont

slender nymph
#

you could technically pass a delegate that captures that local variable though

signal bronze
eternal needle
#

Yea it does get tedious I guess

rocky canyon
#

why are u still setting ur game over b4 the video finishes?

earnest atlas
#

Ah is playing

#

Yeah had same issue

rocky canyon
#

why not set that in the coroutine?

earnest atlas
#

Just use PlayTime something

slender nymph
signal bronze
earnest atlas
#

.length probably will do

rocky canyon
signal bronze
#

like, it doesnt show up

rocky canyon
#

i guess thats just a bool to keep the CollisionEnter() from starting the video over and over

earnest atlas
#

yield return new WaitForSeconds(animation.lenght);

swift crag
#

which was annoying for testing purposes

slender nymph
rocky canyon
earnest atlas
#

The while is playing didnt work for me too

rocky canyon
#

u could also put the Video somewhere out in the middle of no where, with its own camera focused on it..

#

swap the camera, start the film 🍿

astral urchin
#

I followed this sphere deform tutorial but instead I was using a plane, and the object shoots a ray down to the mesh to deform it, it says it hits the mesh but it doesn't deform, I'm new so idk what I need to do. This is the script attached to the grid for the deform

slender nymph
#

you need to get your !IDE configured

eternal falconBOT
signal bronze
slender nymph
#

and you are referencing the videoplayer in the scene and not perhaps a prefab?

signal bronze
#

this is what i have in the editor

slender nymph
#

that doesn't answer the question. that just shows you have a gameobject called VideoPlayer in the scene

signal bronze
#

this what u asking for?

slender nymph
#

well that shows that you are referencing an object called Video Player with a VideoPlayer component on it. but again, are you certain that is the one that is in the scene? ||hint: you can click it and it will highlight the object||

scarlet skiff
#

i have animation that is set to false but even then none of the other animations can be played even if their conditions are true, its just stuck o nthe last animation

signal bronze
#

this?

rocky canyon
#
public class EnemyCollisionHandler : MonoBehaviour
{
    public string restartSceneName = "Juego";
    public GameObject player;
    public VideoPlayer videoPlayer;
    private bool isGameOver = false;

    void OnCollisionEnter(Collision other)
    {
        if (other.gameObject == player && !isGameOver)
        {
            isGameOver = true;
            videoPlayer.Play(); // Play the video
            StartCoroutine(WaitForVideoAndRestartCoroutine(videoPlayer));
        }
    }

    IEnumerator WaitForVideoAndRestartCoroutine(VideoPlayer videoPlayer)
    {
        while (videoPlayer.isPlaying)
        {
            yield return null;
        }

        Time.timeScale = 1f;
        SceneManager.LoadScene(restartSceneName);
    }
}```
code seems fine,
slender nymph
signal bronze
#

well

#

what do I do now

slender nymph
#

show the actual video player component

signal bronze
#

this? @slender nymph

rocky canyon
#
    void OnCollisionEnter(Collision other)
    {
        if (other.gameObject == player && !isGameOver)
        {
            isGameOver = true;

            // Play the video
            videoPlayer.Play();
            Debug.Log("Video started playing. Duration: " + videoPlayer.clip.length);

            StartCoroutine(WaitForVideoAndRestartCoroutine(videoPlayer));
        }
    }

    IEnumerator WaitForVideoAndRestartCoroutine(VideoPlayer videoPlayer)
    {
        while (videoPlayer.isPlaying)
        {
            Debug.Log("Video is still playing...");
            yield return null;
        }

        Debug.Log("Video finished playing. Restarting the scene.");

        Time.timeScale = 1f;
        SceneManager.LoadScene(restartSceneName);
    }``` heres some debug values
#

have u tested the video w/o the code??

signal bronze
rocky canyon
#

its set to camera near plane..

#

are u sure its visible in teh camera?

signal bronze
slender nymph
rocky canyon
#

never said u did.. just make an observation

signal bronze
rocky canyon
#

use the code i sent to see if u get any debugs

#

u should get all 3.. but many of the Video is still playing..

slender nymph
rocky canyon
signal bronze
#

i changed the code for the new one u gave me

rocky canyon
#

and, whats it log?

meager raptor
#

error says: NullReferenceException: Object reference not set to an instance of an object
Player.PlayerManager.Update () (at Assets/_Scripts/PlayerManager.cs:17)

signal bronze
#

nothing changed i think

#

like, its the same

rocky canyon
#

u have to open the console to see the errors..

#

/debugs

signal bronze
rocky canyon
#

well, i think we found a piece of the puzzle

slender nymph
#

you have 10 errors. what are they

rocky canyon
#

bro's been ignoring his console this entire time

meager raptor
signal bronze
signal bronze
rocky canyon
#

this is not from the Slenderman assets

signal bronze
#

fuck

#

didint see that

rocky canyon
#

thast from your JumpscareController script

signal bronze
#

might need glaasses

polar acorn
rocky canyon
#

if ur script errors out like that it may stop running completely

#

and you wouldnt know if the video part even worked

slender nymph
#

also if it is loading the scene even with that OnCollisionEnter method never being called, then something else is loading it or something else is starting that coroutine

signal bronze
#

so, what do i do now

slender nymph
#

move those methods outside of whatever method they are nested in

signal bronze
#

easier terms, dont now what nested means, im not english srry

rocky canyon
#

yea, OnCollision has to be outside of any functions u wrote

slender nymph
#

wait, they weren't before. what the fuck happened

#

share the full !code

eternal falconBOT
rocky canyon
slender nymph
#

ah yeah probably so no logs but the code still works because they didn't remove their own code

signal bronze
#

yeah i copy paste ur code

#

xd

polar acorn
#

like the class part

rocky canyon
#

lol, well ur missing the entire class wrapper

signal bronze
rocky canyon
#

ur class isnt a class anymore

polar acorn
signal bronze
#

where is the class thing ur talking abt

polar acorn
# signal bronze what u talking abt?

you should probably learn literally the first thing about how code works instead of just smooshing random words together like a goddamn caveman

polar acorn
rocky canyon
rocky canyon
#

u deleted all ur important stuff such as 👇

polar acorn
# signal bronze chill man

there are plenty of resources for you to learn how basic C# syntax works instead of getting a half dozen people here to write your code for you one line at a time

rocky canyon
#

well tbf to him he had all of it written out. originally

signal bronze
scarlet skiff
#

https://paste.mod.gg/snzyxafmybej/1

can someone please tell me why after PlayerCrouchHit, the game wont stop playing the animatio neven if its set to false.

i have an animation event at the end of the PlayerCrouchHit that goes like this:
public void HitAnimationFalse()
{
hitWhileShielded = false;
}

hitWhileShielded has to be true to set the bool parameter for PlayerCrouchHit to true'

rocky canyon
#

he just made a mistake and pasted over his class header and stuff when he went to introduce the debug logs

slender nymph
scarlet skiff
scarlet skiff
slender nymph
#

well i'm not digging into all of that. use the debugger in your IDE to figure out what is happening

scarlet skiff
#

i used debug and it shows that hitWhileShielded is set to false correctly yet animation still plays

rocky canyon
#

then its an issue with the Animator

scarlet skiff
rocky canyon
#

if ur code is working but the animations are not

#

not really.. probably a transition from clip to clip..

scarlet skiff
#

how do i tackle this problem

rocky canyon
#

inspect ur animator as the game is playing..

#

u can see the transitions and stuff light up

#

u can figure out whats not doing what supposed to be doing

scarlet skiff
#

but idk what to do about that

rocky canyon
#

just open the animator window.. click the gameobject that has the animator and debug

scarlet skiff
#

thats what i did it lights up even when false

rocky canyon
#

we couldn't say w/o looking thru ur animator and knowing everything that u know about ur project

#

then check that transition..

#

make sure that the conditions when it goes off are correctly set up

scarlet skiff
rocky canyon
#

ohhh, well then it has to be ur script then doesn't it?

scarlet skiff
#

i will try to record a clip

scarlet skiff
rocky canyon
#

lol, its a hefty class..

#

yea a video would be helpful. but provide context with it.. tell us what we're seeing whats we're supposed to be seeing etc..

#

a clip w/o context is gonna be just as bad as that big ole class

rocky canyon
#

also, I'd say use breakpoints but i dont know how those work.. so i wont lol

unique furnace
scarlet skiff
#

idk what a a break point is 😭

timid hinge
#

hi did someone know how this characters are called?

#

like the style

scarlet skiff
rocky canyon
#

lol, thast what i do 😄

unique furnace
#

when following this tutorial i found that the colors of the code im writing and the code of the example are different and the suggestions are not the same.

timid hinge
#

with just legs moving

unique furnace
#

can someone helpe with this i believe it is causing issues with adding the script properly

scarlet skiff
#

while video loads imma try one more debvug thingie

unique furnace
#

I have set the external script editor to visualstudio but this didnt help

gilded verge
#

can someone tell me why the shadows are acting weird? and why does also do that in game? and how do i fix it?

signal bronze
eternal falconBOT
timid hinge
scarlet skiff
#

ok yea...with more bebugging, the animations parameter is literally false but animation is still playing

signal bronze
slender nymph
#

what do the logs print

signal bronze
slender nymph
#

what do the logs from the script print

signal bronze
#

how can i find the script related ones

slender nymph
#

well you start by clearing the console then you go into play mode and make your code run

signal bronze
scarlet skiff
signal bronze
slender nymph
signal bronze
#

nothing

#

only that

slender nymph
#

then that code is not running

signal bronze
#

there is nothing about the script in the console

slender nymph
#

again, if you do not see the logs printed to the console then your code is literally not running

unique furnace
# polar acorn !ide

I have read this page many times and not found a fix for the issue...

Intellisense makes predictions sometimes and then other times it doesnt.. but the code color lens isnt working for any color but blue...

Is this a VisulStudio issue or a unity issue?

slender nymph
#

your screenshot still shows an unconfigured IDE

#

are you sure you have completed all of the steps?

signal bronze
#

this is what happens when i run the game

slender nymph
#

start by removing one of the two audio listeners so that you can actually see your logs when/if they happen

#

and of course you need to actually address then 100+ errors

scarlet skiff
signal bronze
#

this is the only red error that appears

slender nymph
#

fix both of those things

signal bronze
#

and this the other yellow one

slender nymph
#

then you might even be able to see your own logs in the console

signal bronze
slender nymph
#

do you know how to read?

signal bronze
#

yes sorry

slender nymph
#

great! then literally just read what those messages say and do it

signal bronze
#

i left the audio listener only in the camera

#

this shows up

eternal needle
#

Well the logs arent lying to you for fun, at some point you had 2 audio listeners.

signal bronze
#

yeah i now

slender nymph
# signal bronze this shows up

great! so we see that it thinks the video is done playing immediately. this is probably due to the player not being ready to actually start playing yet and so it hasn't actually started before you start checking if it is playing or not

signal bronze
#

and how do i fix that

#

because that sounds like its difficult

slender nymph
#

start by checking the docs for the VideoPlayer and see if there is anything useful you could possibly do there

signal bronze
#

closed the tab, can u send it again

slender nymph
#

!docs

eternal falconBOT
stuck palm
#

i have a strange issue where sometimes my scene will just load into itself when calling change scene. after like 2 or 3 tries it works and idk why

clear seal
#

is it possible to transform a OnTriggerEnter into an IEnumerator?

#

i wanna make a canon where you only need to go on the trigger

#

and it shoots

slender nymph
clear seal
slender nymph
#

i didn't mean turn OnTriggerEnter into a coroutine. i said start one from it

signal bronze
slender nymph
signal bronze
#

i looked in the video docs

tropic agate
#

Hi, I'm trying to make a RayCast based suspension system only using the car RigidBody. Does anyone know why is the suspension acting weird and does'nt want to stay in place?

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

public class WheelSuspension : MonoBehaviour
{
    
    public Ray tireRay;
    public Transform tireTransform;
    public Rigidbody carRigidBody;
    public float wheelRadius = 0.5f;
    public float springStrength;
    public float springDamper;
    public float suspensionRestDist;
    
    void Start()
    {

    }

    void Update()
    {
        tireRay = new Ray(tireTransform.position, -tireTransform.up);
        Debug.DrawRay(tireRay.origin, tireRay.direction);
        if(Physics.Raycast(tireRay, out RaycastHit hit, suspensionRestDist + wheelRadius))
        {
        Vector3 springDir = tireTransform.up;
        Vector3 tireVel = carRigidBody.GetPointVelocity(tireTransform.position);
        
        float offset = suspensionRestDist - (hit.distance - wheelRadius);
        float vel = Vector3.Dot(springDir, tireVel);
        float force = (offset * springStrength) - (vel * springDamper);

        carRigidBody.AddForceAtPosition(springDir * force, tireTransform.position);
        }

    }
}

Thanks in advance

slender nymph
#

why would you look there

signal bronze
#

here

slender nymph
#

you obviously need to look at the info about the video player component

signal bronze
#

there i supose

hybrid sundial
#

yes

slender nymph
#

physics should be applied in FixedUpdate

tropic agate
#

Thanks, going to try that

hybrid sundial
#

and the fixed update is at a constant rate

slender nymph
#

yes, but physics simulates on a fixed loop at the same rate as FixedUpdate

signal bronze
#

still cant find it

#

its the renderer?

hybrid sundial
slender nymph
tropic agate
hybrid sundial
signal bronze
#

please tell me what it is

meager raptor
#

been trying to find this for ages but is there any way to change this so it finds an inactive instead of active object:
unit.Find("Highlight").gameObject.SetActive(true);

clear seal
#

i dont understand the error here

north kiln
sharp abyss
#

How can I add 90 degrees to hips.AddForce(hips.transform.forward * strafeSpeed); because my hips.transform.right is not my left and right. It's up and down

signal bronze
clear seal
signal bronze
meager raptor
hybrid sundial
clear seal
signal bronze
#

what, i dont know what i touched but now it works @slender nymph

#

i think it was skip on drop

#

or smth

north kiln
wary olive
# clear seal

Don’t use a coroutine for that, just use void shoot