#💻┃code-beginner

1 messages · Page 375 of 1

naive pawn
#

MonoBehaviour inherits from Component, so same as you would a component

#

wait no, from Behaviour

#

setting enabled to false

vocal fjord
naive pawn
#

well, that's not how false works

#

it's a literal, not a method

#

SetActive is also itself a method

vocal fjord
#

So how would I do it?

naive pawn
#

SoundPlayer also doesn't seem like a component?

vocal fjord
#

It's the name of the script

naive pawn
#

you can't disable a script

#

you disable a script component

#

you have to disable something that's actually on a gameobject

vocal fjord
#

wait a second

#

OHHHH i'm stupid

#

nvm lol

naive pawn
#

from there it'd be .enabled = false;, without the parens.

#

parens are for calling methods, which in c# will be in PascalCase (by convention)

vocal fjord
#

here's my script, what am I doing wrong? the "nvm" was a false alarm

naive pawn
#

you shouldn't be using Component directly

vocal fjord
#

oh

slender nymph
#

Component does not have a member called disabled. that property is implemented on the derived class Behaviour

naive pawn
#

you have a script that inherits from it, use that

slender nymph
#

but yes, use the actual type you care about

naive pawn
#

also you would have to set ThisScript (missed that it's public, nvm), and probably name it more appropriate to what it is

slender nymph
#

oh and another thing, you do not want to use Thread.Sleep on the main thread 😉

naive pawn
#

also props/variables should be in camelCase to distinguish them from types and methods

swift crag
#

also, Thread.Sleep would completely freeze the game if it worked

slender nymph
#

use a coroutine

naive pawn
#

Coroutines

vocal fjord
#

just realised that i could use waitforseconds but C# doesnt like it :(

swift crag
#

you can...in a coroutine

#

WaitForSeconds is a class. If you create a WaitForSeconds and yield it from an enumerator that's being run as a coroutine, Unity will wait for that long before resuming the coroutine

vocal fjord
swift crag
#

this is very wrong

slender nymph
#

even if WaitForSeconds was a coroutine (which is isn't), starting a coroutine does not delay the code after the StartCoroutine call in a normal method

swift crag
#

and yes: you cannot make the OnTriggerEnter method "pause"

#

doing so means the game is frozen

vocal fjord
#

ok this is really stupid, let me explain what i'm trying to do:

I'm trying to make it so that if a user presses a button, an animation plays that opens the gate. I have to wait a specific amount of time so the animation doesn't loop. Then I have to disable the script so the user can only open the gate once.

swift crag
#

OnTriggerEnter will still run even if your behaviour is disabled, i'm pretty sure

#

just store a bool that tells you if you've already opened the door

#

and do nothing if it's true

vocal fjord
#

what about the animation part? how will i make it wait

swift crag
#

by using a coroutine

#

read the page I linked above

vocal fjord
#

yeah i give up

#

ill just remove de door

rocky canyon
#

ate up a good day or so for me to figure that out on my own

queen adder
#

Oh crap thanks

mystic steeple
#

@vocal fjord I skimmed so I might have missed what you wanted but if you want to wait for an animation, or to do something, can't you just disable or do whatever you want and then invoke a function with a delay to reactivate / do the thing?

#

For instance.. Disable the player controller so they can't move and then invoke a function to reenable it after 3 seconds?

swift crag
#

Invoke is also an option, yes

#

it can be used to send a message to a MonoBehaviour after a delay

mystic steeple
#

Probably an easy way to achieve it for someone new

#

Invoke is pretty simple to get working Elliot, just create a function with the stuff you want to wait for and then do

Invoke("<YourFunctionName>", 3.0f);

dense root
#

How do I poll the new Unity input system? I've read and re-read the documentation but I'm still lost on how to get the desired polling

private void Update()
{
    var moveDirection = moveAction.ReadValue<Vector2>();
    position += moveDirection * moveSpeed * Time.deltaTime;
    Debug.Log("position " + position);
}
hollow dawn
#

I never knew it would be this hard to make a door that can only open using a key 😭

swift crag
#

show the entire script

summer stump
hollow dawn
dense root
#

I'm trying to receive and then set the animator to the appropriate float

swift crag
#

you should fetch the move action from that

#

the moveAction field has nothing to do with it -- it's a completely separate input action that only exists on this component

summer stump
# hollow dawn I followed a video and you need like 4 scripts for that or is that wrong?

The number of scripts is incredibly irrelevant. You could do it as 4, or do it as one. You could break it up into 10 if you want

I would have a class for remembering what keys I have, one for interactions with objects in the world, and one for the door. Might abstract the communication between the interaction class and door with an interface or abstract class, but only if I'm going to be interacting with many different types of things

dense root
#

Okay noted, I'll get back to my code

hollow dawn
hollow dawn
swift crag
#

you're going to have a miserable time if you refuse to read anything

summer stump
#

But learn has videos. As I've told you mutliple times before

#

But once you complete learn, then you can just look at the docs for a raycast and... understand it.
Youtube is clearly holding you back a LOT

dense root
swift crag
#

controls.Main.Movement

#

this is getting an InputActionMap named "Main" and then an InputAction named "Movement"

dense root
#

Oh

swift crag
#

You could assign that into moveAction if you want

uncut crypt
#

In simplest terms, what is [SerializeField] doing here?
[SerializeField]
Transform hoursPivot, minutesPivot, secondsPivot;

willow breach
#

hey, i usually work on windows but when i wanna test on iOS i pull the project on my mac and test
but for some reason the project on the mac have issues with the c#
can find some classes for some reason and act weird.

p.s i know there are different .net version on my windows(4.X) and mac(2.X) but cant find the same version for mac

strong wren
#

do animator Controller Triggers stack?

#

like if i have

Controller1.SetTrigger("1");
Controller2.SetTrigger("2");

#

in the same method and i call them at the same time do they both activate or first trigger 1 then 1 frame after trigger 2

polar acorn
#

So, they're both true, but it depends on the order you're checking them

slender nymph
#

this isn't an issue with your code. and don't crosspost

#

this is a code channel

rich egret
#

oh

#

sorry

slender nymph
#

is this code AI generated?

summer stump
#

"Don't work" is not really helpful. What do your logs say? What debugging steps have you taken? What is currently happening?

polar acorn
#

What isn't working about it

dire kiln
polar acorn
#

What do you have that moves the character

#

You haven't shown any movement code

#

Because you are changing it based on your rigidbody velocity. Where do you change that velocity?

#

What is the transition from walking back to idle

#

Show your logs

#

what do you mean where?

#

Where what?

#

in the console

hasty tundra
#

I am trying to have the transform of RocketTurret1 be set to the exact same position as GameObject, however no matter what i try in the code it always sets to some random offset value. Ive tried setting it to Vector3.zero, Ive tried any combination of localPosition and Position, ive tried having the position it needs to be saved as a preset Vector3 and NOTHING has worked. Its the simplest problem ever but its just. not. working.

slender nymph
#

the localPosition is the position relative to the parent's origin point where as position is relative to the world's origin point

cosmic dagger
#

did you assign its local position to 0?

polar acorn
slender nymph
#

that would only be true if this has no parent since then it's localPosition and position would be identical

hasty tundra
#

The code example i showed was one of the many examples

#

no matter the combo of localPos and Pos it didnt work

#

both pos, both local, mix and match etc

slender nymph
#

if you assign one object's transform.position to another object's transform.position then they absolutely will be the same position

#

correct the code to do that, then show how you are verifying it isn't the same position

summer stump
hasty tundra
#

thing is in the prefab the object is where its meant to be, and even if i dont change the values what so ever, it still gets offset

polar acorn
slender nymph
slender nymph
hasty tundra
#

im getting SS now

#

These SS show the position of the parent and object after instantiating, as well as the code used in the example and the physical distance between them in the scene

dense root
#

Do you think it's worth it to use/learn the new input system? Or if I'm new I should stick with the old one

wintry quarry
#

That depends on if you need to implement key rebinding or local multiplayer

dense root
#

I don't think I need it

slender nymph
dense root
#

@wintry quarry do you recommend the old one for newbies?

slender nymph
#

also are you certain the Child variable is referencing to the correct object

hasty tundra
#

bro... its 2am.....

slender nymph
#

your point being?

hasty tundra
#

sorry for the time waste ig 😭 i forgot to remove the gravity scale from the rigid body

#

that was the longest hour of my life istg

dense root
#

How do I poll the new input system for ReadValue<Vector2> values in order to set my animator?

    private void Start()
    {
        controls.Main.Movement.performed += ctx => Move(ctx.ReadValue<Vector2>());
    }

    // If we can move, then transform.position += Vector3direction
    // We are adding in direction because the value is a 0 or 1 and with tilemaps each cell size is one unit size 1x1
    // Same with the Y axis
    private void Move(Vector2 direction)
    {
        if (CanMove(direction))
        {
            transform.position += (Vector3)direction;

            animator.SetFloat("moveX", ctx.ReadValue<float>());
            animator.SetFloat("moveY", ctx.ReadValue<float>());
        }
    }
rich adder
summer stump
rich adder
#

You could with .device ReadValue instead
but you should just use the events

dense root
summer stump
#

That is pulling it from an InputAction

#

Which you can make a variable

#

You already have the callback set up though, so why not use that? It is way better

dense root
#

Oh I see your points

#

How do I utilize the call back in this context?

#

Nevermind don't answer that let me read the documentation and try to figure it out on my own

rich adder
#

you're passing it in the "direction"

queen adder
#

I have this attached to a gameobject meant to serve as a speed powerup that lasts 10 seconds, but after the player acquires the speed boost they never lose it. I was thinking it's because the object the script's attached to gets destroyed, yet the coroutine still runs after destruction so that can't be why. Do I have to pass anything to the player object to make it work?

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class SpeedBoost : MonoBehaviour
{
    public float SpeedBoostDuration = 10f;
    PlayerController controller;

    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        {
            controller = collision.gameObject.GetComponent<PlayerController>();
            Destroy(this.gameObject);
            StartCoroutine(SpeedBoostEffect());
        }
    }

    private IEnumerator SpeedBoostEffect()
    {
        Debug.Log(controller.runSpeed);
        controller.runSpeed *= 2;
        Debug.Log(controller.runSpeed);
        yield return new WaitForSeconds(SpeedBoostDuration);
        controller.runSpeed /= 2;
        Debug.Log(controller.runSpeed);
    }
}
rich adder
queen adder
rich adder
#

so yeah basically run it on something you're not destroying

queen adder
#

👌 thanks!

outer coral
queen adder
#

Yeah that’s what I ended up doing

silent vault
#

Got it. It might be better your way since the new toggle would be first then. Thanks!

silent vault
#

Thanks. I'm not too familiar with naming conventions in Unity but after some reading, my aim was to add a non persistent event (added through code, right?) before persistent events (events added through the inspector?). In the end, I used methodinfo reflection to get the objects and method names for persistent events, created a new dropdown event, added my own non persistent event first, added the reflected persistent events then applied this new dropdown event to the actual dropdown. It seems to be working fine. Why am I doing this? Because I wanted to create a multi select dropdown feature for the base legacy dropdown and to do that, I needed to save the legacy dropdown changes in a list of int before any persistent events triggered, so I needed to add my own non persistent event to change the selected values first. I got it to work fine in the end. There are 2 quirks at the moment: the ability to reshow the dropdown values after you select an option and the ability to reclick on an currently selected item in the dropdown which does nothing by default. For the first quirk, using coroutine to wait for all toggles to get destroyed allow me to reuse the Dropdown.Show() method (which I extended to update the toggles and enabled all currently selected values) and for the second quirk, I detect which item was selected last and add a new click event on it to trigger the original click event. It works fine except a little delay to reshow the options after selection due to the fade in timer. It can be lowered to 0 but even then, you still get a really quick on/off effect on the options, plus a small problem of the scrollbar being reset if many options. But that's acceptable. With the new "isMulti" bool from the inspector, I can now change the dropdown behavior from single select to multi select and vice versa even at runtime.

#

Just above 🙂 I found a solution, thanks!

gloomy jacinth
#

Can someone help me with something?

cosmic dagger
gloomy jacinth
#

Ok lol! How do i fix this?

cosmic dagger
#

anyone who has the time and know-how will help . . .

gloomy jacinth
#

Ive been trying for a bit but i cant seem to fix it.

ivory bobcat
#

Don't ask if someone's available to help, just ask your question with the provided information and folks who are idle on the server-channel might be interested enough to provide some suggestions.

cosmic dagger
rich adder
gloomy jacinth
#

Ill show you the code can you tell me if there is a problem in the floats?

gloomy jacinth
cosmic dagger
#

your IDE should highlight the error in red . . .

ivory bobcat
#

!ide

eternal falconBOT
gloomy jacinth
ivory bobcat
#

Your script editor should have highlighted the error

rich adder
#

It will show you exactly where its messed up

gloomy jacinth
#

How do i make it work with unity? I have visual studio

cobalt creek
#

does EditorGUIUtility.systemCopyBuffer work in exported apps, or editor only

gloomy jacinth
#

Installed with unity hub one?

ivory bobcat
#

Make sure the work loads are installed

cosmic dagger
rich adder
cobalt creek
#

ok thank

#

so ill have to find something else to get clipboard text on windows

gloomy jacinth
rich adder
#

ops nvm

cobalt creek
#

acshully i shall try

ivory bobcat
# gloomy jacinth Installed with unity hub one?

Execute the installer again and select modify. Ensure the work loads are installed and follow every step to make certain they're complete. There isn't too much. After that, you may be required to regenerate your project (also shown in the guide) and reboot the Unity Editor.

rich adder
ivory bobcat
#

(the others aren't necessary at all to do Unity game development)

rich adder
cobalt creek
#

whats interop?

gloomy jacinth
rich adder
#

the windows dlls

gloomy jacinth
cobalt creek
#

thank, that sound complicated

ivory bobcat
rich adder
ivory bobcat
#

Those would usually fix the problem

cobalt creek
#

cool beans

#

that sound good approach

rich adder
gloomy jacinth
#

@ivory bobcat What should i check off here?

rich adder
gloomy jacinth
#

Thanks!

rich adder
#

@cobalt creek It works. Just gave it a quick test

cobalt creek
#

awesom

gloomy jacinth
#

I have it configured and working but i still dont know how to fix the script think u could help?

#

Anyone?

ivory bobcat
#

Can you show where the red squiggly lines are?

gloomy jacinth
#

Im pretty sure unity is saying this ':' is not supposed to be at the end of this line but when i remove it it is saying that there should be ';' this at the end of the line

silent vault
cosmic dagger
eternal falconBOT
gloomy jacinth
#

!code

eternal falconBOT
gloomy jacinth
#

Oops

#

Ill show it

#

Its the character controller float

#

Here are the errors to

#

Their both on that line

cosmic dagger
#

you have float CharacterController characterController. you have two types for one variable . . .

gloomy jacinth
#

Do i turn it into two floats?

cosmic dagger
#

[accessor] [type] [name] or
[accessor] [type] [name] = [value] . . .

gloomy jacinth
#

Whats the accessor type and name?

ivory bobcat
#

[accessor] [type] [name]
You've got two types though

cosmic dagger
#

only you know what type of variable you want to create . . .

summer stump
cosmic dagger
#

do you know what a type is?

gloomy jacinth
summer stump
gloomy jacinth
#

The tutorial guys worked with that float

cosmic dagger
#

go back and watch the tutorial. i doubt that is what they did . . .

ivory bobcat
#

Both float and CharacterController are types.

#

You'd only want one or three other as the type

gloomy jacinth
#

Thats what he used

summer stump
#

How it is not a float?

gloomy jacinth
#

OMG

#

OMG

#

OMG

cosmic dagger
gloomy jacinth
#

ok.

#

welp

#

welp

#

sorry guys.

cosmic dagger
#

you clearly know (and can see) that what you have is different . . .

gloomy jacinth
#

Yup i very aware of what im looking at

#

Im very sorry 😭

#

WOW

#

would you look at that

#

I actually looked at my last error

#

and saw a capitalization error!

#

Now it works!

#

THANK YOU GUYS!

#

lol im very sorry abt that

#

Ok guys now i like actually have an issue

summer stump
#

Show the code 🤷‍♂️

gloomy jacinth
#

How do i send it here as a code?

cosmic dagger
#

you have to read the prompt (bot message) . . .

gloomy jacinth
#

Message is to long

summer stump
#

The bot is too long to read? It is pretty short

gloomy jacinth
#

!code

eternal falconBOT
summer stump
gloomy jacinth
#

So its easier to view

#

srry

summer stump
#

Just use a paste site...

cosmic dagger
#

if you click the link we posted, it would've sent you to the same bot message . . .

gloomy jacinth
#

Ya i know

#

Im sorry

cosmic dagger
#

bruh, it's too late for this . . .

gloomy jacinth
#

Bro i actually dont know how to send this

#

Do i do '''cs script then '''?

summer stump
#

A paste site

polar acorn
#

You read the section under "Large code blocks" and do that

summer stump
#

Do not do the formatting

gloomy jacinth
#

Does that work?

#

Does this work?

polar acorn
#

Read the section under "Large code blocks" and do that

gloomy jacinth
#

I did

gloomy jacinth
#

I dont know what the problem is. My character just keeps moving in a certain direction and i cant stop it.

polar acorn
#

That's not a link to a paste site

gloomy jacinth
#

That?

polar acorn
#

yes

#

Can you show the inspector of this object

gloomy jacinth
polar acorn
#

Try logging the value of moveDirection after you get it.

gloomy jacinth
#

What do you mean?

polar acorn
#

Log the value of moveDirection after you get it

gloomy jacinth
#

What do you mean by log

polar acorn
#

I mean log

ivory bobcat
#

Debug.Log

polar acorn
#

Debug.Log should literally have been the first line of code you ever wrote in Unity

ivory bobcat
polar acorn
#

Pretty much every tutorial would go over that before anything else

gloomy jacinth
#

Im sorry im just new to coding and stuff so some things just kinda confuse me

#

What code would i use to log it?

gloomy jacinth
#

Would the "Text" be moveDirection?

#

Becuase thats what i want to log

spare mountain
gloomy jacinth
#

Do i need to log the value i want?

spare mountain
#

... _ _ _ _

gloomy jacinth
#

What do i add after this?

polar acorn
gloomy jacinth
spare mountain
gloomy jacinth
#

Do i add moveDirection + 0f or something?

polar acorn
gloomy jacinth
#

Idk what im doing.

#

i dont even know what logging does

polar acorn
#

Just give it a bit of thought. What would adding 0 to it accomplish

spare mountain
gloomy jacinth
spare mountain
gloomy jacinth
#

Logs a message to the Unity Console

spare mountain
#

so what do you reckon debug.log does?

fickle plume
gloomy jacinth
#

Logs a message to the unity console

spare mountain
#

🤯

gloomy jacinth
#

I just want help 😭 i dont know what to do

spare mountain
#

you're clearly not ready to take on any projects

gloomy jacinth
#

Like i know it logs message but i dont know what to put in the messgae

fickle plume
polar acorn
gloomy jacinth
polar acorn
#

!learn might be a good idea

eternal falconBOT
#

:teacher: Unity Learn ↗

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

fickle plume
eternal falconBOT
#

:teacher: Unity Learn ↗

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

polar acorn
#

I don't know what you've done to start learning, but it's probably better to use this

spare mountain
polar acorn
fickle plume
spare mountain
fickle plume
#

So it won't work in Scriptable Object for example.

cosmic dagger
#

better to learn Debug.Log since it works for non-Monobehaviour scripts . . .

gloomy jacinth
#

I cant find out how to do it

#

Would the debug stop the player from moving continuously?

spare mountain
gloomy jacinth
#

Should debugs be in void start()?

polar acorn
gloomy jacinth
#

Im trying to make my character not move when keys arent being pressed so sure

spare mountain
polar acorn
fickle plume
#

@gloomy jacinth You still didn't even bother to look at the documentation page where the method is used inside another method.

#

You are asking questions that any introductory scripting tutorials covers. To spoonfeed you one here in chat would take hours.

#

While also showing no interest to actually try learning yourself.

#

@gloomy jacinth If you want to continue here, create a thread in case someone want to bother with personal tutorial for you. Otherwise stop with posts in the main channel.

gloomy jacinth
polar acorn
#

Three actually

spare mountain
#

three in one

gloomy jacinth
#

I know but i dont know what objects its talking about in the line: Debug.Log("Hello: " + gameObject.name);

polar acorn
gloomy jacinth
#

I just dont know where and what other variables i would use to debug moveDirection

polar acorn
#

I told you what to log

lavish magnet
#

How would you guys recommend finding the closest something is to something? Like the closest one object is out of an array to the current gameobject

polar acorn
cosmic dagger
polar acorn
#

When the loop ends, whatever's set to current is the closest object

eternal needle
ivory bobcat
# gloomy jacinth Would the debug stop the player from moving continuously?

You need to log the direction to see if it's a value other than zero for x and y. If the values are zero for both and you're still moving, something else is occurring. If the values are not zero but you aren't pressing anything, perhaps you've got a drifting joystick connected to your system or something - relative to your input system.

#

The log will not fix your problem but it'll help you figure out what might be wrong.

lavish magnet
polar acorn
gloomy jacinth
gloomy jacinth
ivory bobcat
#

Did you log the values?

fickle plume
gloomy jacinth
#

Would this log work?

polar acorn
#

Literally what information does this give you

gloomy jacinth
#

Im just testing how a log works 😭

polar acorn
#

Why do you want to see the words "This is a message" twice in the console

gloomy jacinth
#

To LEARN how logs work.

polar acorn
#

You can just run the code

gloomy jacinth
#

Ya it doesnt work then

fickle plume
eternal falconBOT
polar acorn
#

I assure you that Debug Log indeed "works"

cosmic dagger
ivory bobcat
gloomy jacinth
ivory bobcat
gloomy jacinth
ivory bobcat
#

The image would suggest otherwise

polar acorn
gloomy jacinth
#

Oh

#

It would say there?

polar acorn
#

It would have proper syntax highlighting

gloomy jacinth
#

It wasnt in a gameobject yet

ivory bobcat
lavish magnet
cosmic dagger
# gloomy jacinth Oh there. Thank you!

seriously, at this point, you need to follow the basic tutorials from !learn. you're wasting everyone's free time with something you can understand in a few minutes by following along . . .

eternal falconBOT
#

:teacher: Unity Learn ↗

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

polar acorn
gloomy jacinth
#

I cant really find anything that shows how to get the value of an object with debug. Does anyone know?

gloomy jacinth
#

What does [i] mean?

eternal needle
polar acorn
gloomy jacinth
#

Just asking what [i] means.

eternal needle
#

Funny considering I didnt even reply to that message

#

It is called an indexer

fickle plume
#

@gloomy jacinth For the last time. Create a thread if you want to continue bumbling here.

#

You are wasting your and everyones time

gloomy jacinth
#

Need help!

pure obsidian
#

Is there anything I need to do to get the URP preset to work?
I removed the global light, and created an object with a sprite rendered with the lit material, and used a point light, but everything is still as if no URP is installed
EDIT: I wasn't using 2D lights (lol)

pure obsidian
#

Thank you. I will look properly next time 🙏
Sorry for the mistake!

fringe plover
#

Whats the difference between string.Format("test") and $"test"?

#

i know both used to put variables in string, but idk which one should i use

cosmic dagger
fringe plover
#

so... there is no difference?

spare mountain
#

that's just a string

#

right?

fringe plover
#

that was just example

spare mountain
#

or is that not how string.Format works

fringe plover
#

ik that i need to put {variableName} in string

timber tide
rocky gulch
#

o yeah mybad

#

sry

timber tide
#

also probably look up tutorials for this stuff cause it's a pain in a butt if you havent

rocky gulch
#

great idea

willow scroll
fringe plover
#

okay, thanks for explaining

#

but question was different...
I asked what is better

willow scroll
fringe plover
#

Welp, when i started learning C#/Unity i always used + operator for strings, i learned about $ thingy recently

willow scroll
#

If deciding whether to use string.Format or $, I, personally, use the 2nd one in most cases, and the 1st one when the parameters are too long

willow scroll
fringe plover
#

Okay, thanks 🙏

eternal needle
# fringe plover Welp, when i started learning C#/Unity i always used + operator for strings, i l...

if you need to actually concat strings, then use stringbuilder. But this would be when the input is unknown, like manually reading a text file for example.
as for string.format and string interpolation, you can get the same result from either. there may be small differences internally though. You probably wouldnt even run into this case but theres a difference here:

string _ = string.Format("Something {0} " +
    "something {1}.", a, b);
// and
string _ = $"Something {a} " + 
            $"something {b}.";

The 2nd one uses string.concat even though both do the same thing and otherwise look the same

fringe plover
#

okay thanks

magic drift
#

In a game jam atm and having an issue with Quaternions:
I want a quaternion facing in the opposite direction. It works in almost all cases i.e

Quaternion originalRotation = Quaternion.Euler(new Vector3(0, 90, 0));
Quaternion oppositeRotation = Quaternion.Euler(-originalRotation.rotation.eulerAngles);

oppositeRotation will be a quaternion with eulers (0, 270, 0) however, if the originalRotation has the euler angles (0, 0, 0) or (0, 180, 0) oppositeRotation will simply be that same exact quaternion as originalRotation

languid spire
#
Quaternion oppositeRotation = Quaternion.Euler(new Vector3(0,180,0)) * originalRotation;
ivory bobcat
#

Accessing the Euler angle property will give you some angle that would represent your current rotation - it might be any coterminal angle.

#

You might be better off having a Vector3 field being your actual rotation at all times and simply assign to the rotation property (quaternion) - don't acquire the Euler angle from the rotation property.

ivory bobcat
magic drift
ivory bobcat
#

I'm simply asking because oppositeRotation is assigned the the euler angle of -existingConnector and not originalRotation

magic drift
#

oh my bad

#

forgot to replace example code

frank zodiac
magic drift
magic drift
eternal needle
errant pilot
#

if(Input.GetMouseButtonDown(0) || i == 0) Guys this checks if i left clicked anywhere right?

errant pilot
eternal needle
# frank zodiac ill try that

there is a lot you can simplify and improve on here.
Like cache that GetComponentInChildren, infact you dont even need get component. Just directly assign it in inspector.
That whole timer setup just looks so weird too, like adding and subtracting to it constantly.
and ill just suggest to use StringBuilder instead of concating strings like this, but that might be a bit above your understanding for now.
You really should have Debug.Logs around or use the debugger to solve issues like this though, theres gotta be one clear problem area. And that is likely the while (!isNextClicked) based on your description

willow scroll
willow scroll
frank zodiac
eternal needle
#

im not even sure of what it does myself, this must be the first time if (timer < Time.deltaTime) has been written 😅

frank zodiac
eternal needle
#

the math probably checks out but its definitely a unique way of writing a timer

willow scroll
willow scroll
#

Because I don't

#

Oh, there is interval added in the condition

#

But, why..?

eternal needle
# frank zodiac tbh i got it from a website which explained the code thorougly

its more understandable if you just do something like this


  timer += Time.deltaTime;
  while (timer >= interval)
  {
      textBuffer += characters[i];
      gameObject.GetComponentInChildren<TextMeshProUGUI>().text = textBuffer;
      timer -= interval;
      i++;
  }

If deltaTime is somehow a lot larger than interval, itll also still instantly print out the characters it needs. The only thing is you'll want to rearrange this a bit, so its checking the value of "i" to make sure its not trying to access out of bounds elements.

willow scroll
#

E.g. for 20 & 10:

0 += 0.05;

while (0.05 >= 0.1) ...
eternal needle
#

well yea itll still need some check to yield. this part was just to simplify the timer so its not confusing

willow scroll
#

They should simply WaitForSeconds in a Coroutine, even if it's not going to be calculated too accurately depending on the frame rate

WaitForSeconds intervalWFS = new(1f / charactersPerSecond);

foreach (char c in line.ToCharArray())
{
    // ...
    
    yield return intervalWFS;
}
#

@frank zodiac

fringe plover
#

I need help, i have texture in this folder, but when i load it trough script as Sprite, it doesnt work...
Resources.Load<Sprite>("path/Shicka.png")

#

Is there any way to load it?

eternal needle
fringe plover
languid spire
languid spire
#

why not?

eternal needle
fringe plover
#

"var sprite = Resources.Load<Sprite>("Sprites/sprite01");"
Whats difference?

languid spire
#

no file extension?

fringe plover
#

thank you so much

languid spire
#

next time RTFM

fringe plover
#

okay

mortal portal
#

Hello everyone,
I currently have the following code to rotate my player around a pivot point. He does this for the whole game and it looks very smooth on the PC but as soon as I start the game on my mobile phone the rotation bends and doesn't look smooth at all.

transform.RotateAround(target.position, Vector3.forward, rotation_speed * Time.deltaTime);

i've already done a lot of research but i only started with unity and i'm not very familiar with vectors or quaterniums.

Does anyone have an idea?

#

its a 2d game by the way

mortal portal
#

yes

willow scroll
#

Then there shouldn't be any issues

mortal portal
#

I thought the same

willow scroll
#

Are there any other factors affecting the rotation?

mortal portal
#

no not that I can tell it runs smooth as it should on my PC but not on my phone

willow scroll
#

What's the fps on your phone?

mortal portal
#

120

willow scroll
#

Could, you send a video of it?

mortal portal
#

yes pls wait a moment

willow scroll
#

If you're referring to the graphics, I think it's purposely worse in Unity Remote

mortal portal
#

it seems smoother on the record i dont know maybe beacause its not build jet ?

mortal portal
willow scroll
#

The quality is just bad

#

And it's not your fault

mortal portal
tiny hatch
#

Does anyone know how to fix this little thing ?

willow scroll
willow scroll
tiny hatch
#

Maybe its an easy fix, but youtube was just not doing it for me

willow scroll
tiny hatch
willow scroll
#

What's with them?

#

It's too dark for me to see anything

ivory bobcat
#

You may need to explain the unwanted behavior

tiny hatch
#

Basically on the biggest wall, we have like 10 of them, on the smaller one theres like 20 and on the smallest theres 50

willow scroll
tiny hatch
ivory bobcat
tiny hatch
willow scroll
tiny hatch
#

preferably

ivory bobcat
#

There's probably some setting to have them not stretch (or squished) but rather tiled etc

tiny hatch
#

Will do

#

Thank you

timid fulcrum
#

does anyone know why my character with Character Controller component doesn't collide with the floor?

timid fulcrum
#

sorry 🙂

timber tide
# timid fulcrum sorry 🙂

if you're sure it's something related to your code then you could post it here, but if you're just juggling components on the editor and having trouble with that alone then stick to #💻┃unity-talk

#

and provide more information on what you tried

timid fulcrum
#

ok ty

scenic saffron
#

!code

eternal falconBOT
scenic saffron
#
void Update()
    {
        if (Input.GetKey(KeyCode.Mouse0))
        {

        }
        else if (Input.GetKeyDown(KeyCode.Mouse1)) 
        {
            spawnBullet();
        }
    }

how do i make it so spawnBullet() can only be called every 0.25s or something

willow scroll
teal viper
#

Or a timer

willow scroll
#

With its WaitForSeconds

#

You can also do it in Update with Time.deltaTime, as was mentioned by dlich

scenic saffron
willow scroll
scenic saffron
#

ok

willow scroll
storm dove
#

hi, im extreamly new to c# and unity and i was just wondering what void and public does?

willow scroll
teal viper
#

These things are covered in most places teaching you C# basics

languid spire
#

In Unity public also exposes the variable to the inspector for serialization if it is serializable

dim wharf
#

is there no one function that removes all children from a gameobject?

willow scroll
dim wharf
languid spire
#

you said remove, thats what it does. what did you actually mean?

dim wharf
#

removes all children

#

that one removes the parent but not the children

naive pawn
#

"remove" is unclear here

dim wharf
#

ohhhh i get the confusion now

#

i mean destroy

near vessel
#

hiya guys. we are having this error in our unity VR game and not sure how to fix it as its not letting us save latest changes in version control, how do we fix this error?

languid spire
naive pawn
# near vessel

does it allow you to view/resolve the conflict in any way?

near vessel
#

no it does not

naive pawn
#

idk unity vcs specifically, but when there's conflicts you would have to resolve them somehow, by either accepting your changes, accepting the incoming changes, or merging them (which may be manual)

naive pawn
near vessel
#

i was thinking if we remove pro builder from the project will that work?

naive pawn
#

conflicts aren't a one-off thing, they can happen whenever

near vessel
naive pawn
#

it..could fix it, but may as well use the opportunity to learn how to properly fix conflicts

near vessel
naive pawn
teal viper
#

My advice is to also get the proper plastic GUI, instead of using the unity package(or in addition).

near vessel
#

processing merge its saying now taking quite a while

naive pawn
#

should get you there though

near vessel
#

how long should the merge take?

#

as it looks like its taking quite awhile

naive pawn
#

depends on the file size, i guess

rocky gulch
#

is there a build in function that lets a navmesh only move with only 1 axis (Only X / Y)

vestal adder
#

do u mean a navmesh agent

teal viper
rocky gulch
teal viper
vestal adder
#

not that important but X,Y would be two axis

languid spire
#

I think OP meant one axis on any one step of the path

vestal adder
#

That makes sense

formal venture
#

current_heat is a float 100% same as effective_change so i have 0 clue what is a problem

timber tide
#

syntax

eager spindle
#

you may be using a , instead of .

formal venture
#

why this always has to be so simple

#

thanks anyway

#

shame the text editor gaslighted me for 15 minutes into thinking u cant multiply a float, instead of pointing the problem

teal viper
#

Well, when you're a beginner you have simple issues. The more experienced you'll get, the more difficult problems you'll face

teal viper
ivory bobcat
#

I'm assuming semicolon to terminate/split the statements - it may think it's meant to be two statements.

formal venture
merry spade
#

How can I check if the navmeshagent stopped because of the stopping distance? (checking boolean isStopped doesnt work)

merry spade
#

yes thank you

rocky canyon
#

good morning code crunchers 👋

sterile radish
#

hi right now they way this script works is by whenever the player clicks, they start a timer. when this timer is finished, a bool called "giveclicks" is set to true meaning that the game should add to the player's click count. however, right now whenever "giveclicks" is true, it adds to the clickcount every frame. i only want the game to add to the clickcount once then move on. how can i acheive this?

https://hatebin.com/jqcjeqhgnl

languid spire
sterile radish
languid spire
#

no it doesnt, it sets time remaining to 0

sterile radish
#

yeah but wouldnt that just make the timer start by itself?

languid spire
#

yes, but if you don't do that then the third if is always true, so givclicks keeps getting set to true

sterile radish
#

oh right

#

is there a way to not make it automatic but also not set the third if statement to true?

languid spire
#

of course there is, just think about your logic

sterile radish
#

okay i will try

#

SteveSmith i fixed it!!! thank you for encouraging me to fix it myself

languid spire
ionic zephyr
#

Is it better to have Items as a class or as a scriptable object in a Crafting Game?????

gloomy jacinth
#

Does anyone know how i can make this turn into a scope screen? Instead of having it look at the actual model.

ruby python
ruby python
gloomy jacinth
#

Ok!

#

Ill try that!

late burrow
#

why when i add custom get/set to variable it doesnt display in inspector

short hazel
#

Some games also make the model invisible and overlay the screen with a scope image

wintry quarry
ruby python
# gloomy jacinth Ok!

Actually thinking about it, you'd want the second camera at the end of the barrel (not massive accurate in terms of realism, but would allow you to use a crosshair to accurately aim.)

late burrow
#

i want run action whenever editing variable and onvalidate runs bit too much how can i do it property way

gloomy jacinth
wintry quarry
#

Not with a property

ruby python
swift sedge
ionic zephyr
ruby python
#

But you would need to add any muzzle flash/bullets to a new layer and tell the second camera to ignore that layer so that it doesn't render them.

gloomy jacinth
#

I fixed the animation but i still just fall through the floor and move randomly.

gloomy jacinth
silent vault
#

is there a way to tryparse a string to int which is bigger than int.maxValue and if it's biggger, clamp it to max value instead of returning false ?

#

Currently, it returns false if the string is bigger than int.maxValue but I can't figure out a way of knowing if it's false because it's too big or because the string is not an int format.

ruby python
silent vault
languid spire
night owl
#

Hello! I am a very beginner programer and I've been using many youtube tutorials and stack overflow posts to piece my game together. I recently ran into an issue when trying to add attack function(?) and animation.

this is the code I have so far for my player controls

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

public class PlayerController : MonoBehaviour
{
    [SerializeField] private float movementSpeed = 22.5f;
    private Rigidbody2D rb;
    private Vector2 movementDirection;

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

    // Update is called once per frame
    void Update()
    {
        movementDirection = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
    }

    if (Input.GetKeyDown(KeyCode.Space))
    {
        anim.SetBool("isAttacking", true);
    }

    void FixedUpdate() 
    {
        rb.velocity = movementDirection * movementSpeed;
    }

}

the problem is when I added the
if (Input.GetKeyDown(KeyCode.Space)) { anim.SetBool("isAttacking", true); }

I got lots of errors(Ill send a photo) and I tried moving that section of code to the fixed update section but that also did not work.
In the animator I have set up my move/idle animation (which is the same in this case) and my attack animation with transitions between of "isAttacking" true/false. Thanks for all help in advance!

gaunt ice
#

length can be 11
-2147483648, int min, though you can just check if the first char is '-'

eternal falconBOT
languid spire
rich adder
#

@night owl is your IDE configured? you have a shite ton of syntax error

night owl
night owl
languid spire
#

!ide

eternal falconBOT
rich adder
#

assuming you're using one and not notepad

night owl
#

oh like vsc

#

yeah

rich adder
#

yes make sure to configure it so you can format your code properly

#

it will highlight errors for you

night owl
#

im so sorry to ask but is that what the lightbulb is?

#

Everytime I click it it just seems to undo my formatting

#

like visual formatting

#

which i had gotten from tutorials

rich adder
night owl
rich adder
#

ah wtf

night owl
#

yes i believe so?

rich adder
#

why is not highlighting that huge error you got

#

You literally have an if statement outside a function

night owl
#

I think the problem is that I didnt declare the vari

rich adder
#

nah man you got if statement outside a function

night owl
#

but it seems i have other issues as well

languid spire
#

that was only a small part of the problem

rich adder
#

your vscode is like partially working

#

make sure you updated all the extensions and try regen project files in unity external tools preferences

rich adder
night owl
#

oh what

#

I swear I got all the plugins if thats what u mean?

rich adder
#

the Unity one?

#

make sure you don't have the old Visual Studio Code package in Unity

#

!vscode

eternal falconBOT
#
Visual Studio Code guide

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

https://on.unity.com/vscode

rich adder
#

do a few checks here on this link ^^

night owl
#

many thanks i wilil try that

ruby python
#

Always fun when you accidentally divide by 0 lol.

night owl
#

this is what it looks like now

#

oh and

#

its on 1.90.0 but 2.0.22 is the one under it and the one i have in unity

rich adder
#

Also Click Regen Project files too on that same page

night owl
#

ohhh awesome

#

ok

night owl
rich adder
#

did you close vsc and open script from unity after you did it

night owl
#

no not at all

ruby python
#

!code

eternal falconBOT
night owl
#

in vsc it does seem like it isnt connected to the unity project

rich adder
rich adder
ruby python
#

Copy/Pasting the ''' cause typing doesn't type the same characters

rich adder
#

uh what kinda keyboard you have?

ruby python
#

UK Standard layout Corsair

#

'''cs
//this is a code test
'''

#

see

rich adder
#

thats because its not '

#

its ```` ```

night owl
#

its above the tab and ~
as well as below escape

ruby python
#

Well the 'open' quote mark yeah I have that, but I don't have the closing

rich adder
#

no its a backtick

#

not open quote

#

do you have this

night owl
#

oh sorry my bad

rich adder
#

its literally the only slanted symbol

ruby python
#

that's not uk layout.

#

|\ is that key

#

Also, that's a mac keyboard.

rich adder
#

idk I typed in UK layout and that came out lol

#

I would think by now you should know what a backtick is

ruby python
#

yeah, which I don't have on my keyboat (not even kidding)

#

keyboard.

night owl
#

yeah wait look at this

#

u might have to use the code thing

#

like on the num pad?

#

or copy paste

#

or the links i guess which is what u were doing?

#

it says something abt pressing right alt key

rich adder
#

its literally here

#

next to the 1

night owl
#

oh oops i just followed the highlighted ones 😭

rich adder
#

I've yet to see a keyboard without one, unless its some special 60 keyboard

night owl
#

im gonna stop trying to help

ruby python
#

oh wait. lol. Sorry, I'm being a spanner. Yeah my bad, I thought they were two seperate symbols (open/close if that makes sense)

#

Long day and trying to do maths. lol.

night owl
ruby python
#

Anyway.........speaking of maths................Would anyone be able to check this please? It's breaking my brain at the moment.

So I'm getting the circumference of a circle, which works fine, then getting an angle increment based on the circumference and the size of the object(s) that I want to spawn in said circle at regular intervals (objects x/z size is 20 units/meters) so that the objects form a 'solid' circle at the outer edge of the play area.

Can't seem to get the numberOfPerimeterObjects to calculate correctly.

        perimeterRadius = mapSize * tileSize / 2f;
        perimeterCircumference = 2.0f * Mathf.PI * perimeterRadius;
        Debug.Log(perimeterCircumference);
        angleIncrement = perimeterCircumference / 20f;
        Debug.Log(angleIncrement);
        numberOfPerimeterObjects = perimeterCircumference / angleIncrement;
        Debug.Log(numberOfPerimeterObjects);
keen dew
#

perimeterCircumference / 20f is the number of objects, not the angle increment

#

Angle increment would be 360 / amount of objects

ruby python
ruby python
stuck palm
#

how can i interpolate the markers above their heads properly? right now i just have it set as a world to screen point and have it follow that point exactly, which leads to some jitter

#

apparently using lerp is bad

#

like mathf.lerp

night owl
#

this might sound dumb but how much does it matter having visual studio code vs visual studio community?

rich adder
night owl
#

oh ok interesting thank you

#

I still have not been able to configure mine properly

#

But instead I've tried to fix the code

rich adder
#

Well you should fix your IDE first

#

if you are on windows then try using Visual Studio Community instead
its easier to get it working out the box

frank zodiac
#
[SerializeField] private Image attackButton;
[SerializeField] private Image defendButton;
[SerializeField] private Image tradeButton;
[SerializeField] private Image exitButton;
[SerializeField] private Sprite attackButtonSelected;
[SerializeField] private Sprite defendButtonSelected;
[SerializeField] private Sprite tradeButtonSelected;
[SerializeField] private Sprite exitButtonSelected;

public void AttackButton()
{
    attackButton.sprite = attackButtonSelected;
}

public void DefendButton()
{
    defendButton.sprite = defendButtonSelected;
}

public void TradeButton()
{
    tradeButton.sprite = tradeButtonSelected;
}

public void ExitButton()
{
    exitButton.sprite = exitButtonSelected;
}

how can i make this more efficent

frank zodiac
rich adder
#

why do you need "less code"

#

if it works

cedar crest
#

Hi! How can I determine if a point is located clockwise or counterclockwise of a ray?

rich adder
#

a ray is just a straight line

#

infinite

cedar crest
#

I mean like this
In semi-surface that is lefter or righter of a ray considering it's direction

#

green is the point and it is in clockwise part

#

Is there some built-in method for this, or should i just use math

rich adder
cedar crest
#

I'll try, sounds good
Just trying to check if unity has something for it already

rich adder
#

ops

stuck palm
#

you cant do findobjectoftype() for non monobehaviours can you

fluid kiln
#

How can i manage this in a 2d game?

I want to make a classroom scene that plays a "cutscene" when the player first loads the scene, but then it turns into a normal explorable place.

Also do you guys suggest making a scene for every "room" or should every scene be a whole map?

#

Its an rpg game

rich adder
#

trig still hurts my brain sometimes, gotta double check

cedar crest
#

looks like taking an angle with extra steps

#

The value will be discarded, only sign is needed, so i think checking angle as you said is fully ok

rich adder
#

all you're doing is manually moving the camera and disabling move controls

fluid kiln
rich adder
#

You probably want to play around with Cinemachine and Timeline

#

Timeline mostly for all the scripted animating

stuck palm
#

does invoke stop when timescale is 0?

rich adder
#

are you talking about the MonoBehaviour invoke?

stuck palm
#

yeah

#

does like its progress stop

wintry quarry
stuck palm
#

depending on timescale

#

okay awesome

#

youre a different colour now 👀

fluid kiln
rich adder
ornate spoke
#

Hey, how do I set a velocity on an instantiated clone?

stark hedge
#

then u can reference the stuff on that object

#

like its playercontroller or whatnot

rocky canyon
ornate spoke
stark hedge
#

indeed

#

the instance thats created will be set to that variable

ornate spoke
#

great, ty

rich adder
stark hedge
#

o i didnt know that

rich adder
#

ya skips the GetComponent call

rocky canyon
#

Rigidbody rb = Instantiate(rbPrefab);

#

rb.velocity =

stark hedge
#

ohhhh that is neat

rich adder
#

as long as the rbPrefab is of Rigidbody type for example

rocky canyon
#

yes ^ lol dont be assigning NavMeshAgents as rigidbodys

#

or anything silly like that

#

lol

rich adder
#

this spline shall now be a navmesh agent!

rocky canyon
#

identity crisis!

rocky canyon
ornate spoke
rich adder
rocky canyon
#

prefab, transform, rotation

#

^ i think should be bare minimum

#

u can.. just (prefab)

#

but who the hell knows where that ends up

ornate spoke
#

awkay..

stark hedge
#

either check docs or if ur code editor tells u as ur writing

rocky canyon
rocky canyon
#

no clue, been meaning to grab it

#

but my empty projects are lacking for now..

rich adder
#

a good price 😆

rocky canyon
#

heck ya, my favorite price

rocky canyon
#

and a little bit of ik for good measure

#

wait.. ik-ish b.c i doubt its a rig

rich adder
#

def some raycasting going on

#

the feet touching the walls and stuff maybe combine with ik or spline feet?

rocky canyon
#

spline feet..

#

sounds painful

gloomy jacinth
#

How do i fix this?

rocky canyon
#

dont try to access/modify gameobjects that u've destroyed

gloomy jacinth
#

But im make a weapon shoot and it destroys the game object what do i do instead

rocky canyon
#

thats fine.. but once its destroyed what are u still trying to do to it?

gloomy jacinth
#

Shoot again

#

Can you look over the script?

rocky canyon
#

should probably use a prefab gameobject.. and instantiate a new one

#

destroy the old one.. and let it be

#

u can share the script if u like..

gloomy jacinth
#

!code

eternal falconBOT
rocky canyon
#

wee need a slash command for codeblocks

gloomy jacinth
rocky canyon
#

what line is the error on?

#

does it tell?

gloomy jacinth
#

I think 67 because it says im trying to reach a destroyed game object

#

The error says that. Then it says you should check your script if its null or should not destroy the object

rich adder
#

btw you do know you can add a delay directly in Destroy method

rocky canyon
#

its ur Explode() method

#

after that.. u shouldn't try to do anything else to that gameobejct

#

or do the delay Inside the destroy method

#

Destroy(gameobject, 1f);

#

^ destroy after 1 second

stark hedge
#

since it destroys on a delay, wouldnt it be colliding with more stuff before it destroys

#

and proccing explode again

rocky canyon
#
   private void Explode()
    {
        if (isDestroyed) return; // Exit if the object is being destroyed
        isDestroyed = true; // Set the flag
stark hedge
#

ya

rocky canyon
#
    private void OnCollisionEnter(Collision collision)
    {
        if (isDestroyed) return; // Exit if the object is being destroyed```
rocky canyon
stark hedge
#

//Add a little delay, just to make sure everything works fine

#

classic

#

LMAO

rocky canyon
#

good that u caught it tbh

#

sometimes these errors can go hidden for a long long time

stuck palm
#

how can i interpolate the markers above their heads properly? right now i just have it set as a world to screen point and have it follow that point exactly, which leads to some jitter

rocky canyon
#

MoveTowards, SmoothDamp, Lerp

#

many different smoothing type functions u can use

stark hedge
#

the jitter might also be from ur camera not being in the same kind of update as them. ive had that problem before

rocky canyon
#

well his whole scene would jitter if it was camera issue

stark hedge
#

yea unless just the markers are different

rocky canyon
#

then u can adjust that modifier however u want..

#

make it snappy.. make it lag behind a bit.. etc

#

should smooth it out abunch

gloomy jacinth
rocky canyon
#

create a boolean (a flag) to let it know its been destroyed (or that has happened)

#

when u do that set the bool to true;

gloomy jacinth
#

oooh

#

ok

rocky canyon
#

and then on every function that manipulates the gameobject do an early returnif (isDestroyed) return; before any of ur other logic

#

when isDestroyed is true.. it'll just skip all the logic underneath it

gloomy jacinth
#

Do i need to make a public bool or something for isDestroyed?

rocky canyon
#

and that will let it eventually get destroyed w/o ur script still doign things to it

rocky canyon
gloomy jacinth
#

Ok

#

ill try

#

It still gives me the same error

whole lark
#

Hi, I tried to Build my project, but it gave me an error with a folder that is not existing...? Does someone know how to fix it?

gloomy jacinth
#

Line 24 and 46

gloomy jacinth
rocky canyon
whole lark
frank zodiac
#

https://hatebin.com/ivnonchplu i have this custom button script but its not working for some reason. i have 4 buttons; attack, defend, trade, exit. the functions are for when the mouse enters and exits each button

eager spindle
short hazel
rocky canyon
eager spindle
#

you deleted a folder with a scene that would've been added to the build

#

so check your scene listi n the build settings to see what scenes you've included

swift crag
#

or you moved a scene, perhaps

#

i dunno if the scene list handles that

eager spindle
#

either way the scene list will show any scenes that cant be found

gloomy jacinth
#

In my Actual gun script to?

#

Or in every void function?

rocky canyon
#

why does ur gunscript modify teh bullet at all?

gloomy jacinth
#

idk

rocky canyon
#

it should only instantiate it.. and then the bullet script would be the one doing everything to itself

gloomy jacinth
#

just asking

rocky canyon
#

so no, the gun script wouldnt need to know if the bullet is getting destroyed

gloomy jacinth
#

But do i add this: if (isDestroyed) return; // Exit if the object is being destroyed
isDestroyed = true; // Set the flag into every void function?

shy cairn
#

Good afyernoom clan

rocky canyon
#

every function that the bullet is calling

shy cairn
rocky canyon
#

the idea is to make the script not do anything to the bullet after u've said Destroy yourself

gloomy jacinth
#

So then i can only shoot my gun once?.

rich adder
# shy cairn

what is this and how is it related to unity coding questions?

rocky canyon
#

the gun shouldnt care what happens to the bullet..

#

if thats the way u have ur stuff setup.. then thats the main issue

shy cairn
#

I come to give the best of my ability to contribute to the missions and whatever the clan wants to entrust to me. I am Latino I speak through a translator and I am also in Moomens and filth

gloomy jacinth
#

No ya i meant bullet but will puting this code into the bullet script make it clone prefabs when i shoot or just only let me shoot once.

rocky canyon
#

im confused.. u shouldnt need to add anything to the gun script..

rich adder
rocky canyon
#

u can instantiate as many prefabs as u want..

#

millions..

gloomy jacinth
rocky canyon
#

yea, if the error is being caused in the bullet script

gloomy jacinth
#

So do i add that piece of code to ever void action in the bullet script?

rocky canyon
#

when u destroy it.. (or try to) set isDestroyed = true;

#

and then any function inside that script.. needs the first line to be if(isDestroyed){return;}

#

that way if its been destroyed.. dont do anything to it.. dont make particles.. dont try to destroying it again. nothing

#

and then eventually it will get destroyed completely (along with its script) and then no more errors will happen

gloomy jacinth
#

I fixed it

#

Thank you!!

rocky canyon
#

like dis

rocky canyon
rocky canyon
#

since loops can take a min to finish.. it was erroring out.. b/c the gameobject would get destroyed b4 it finished or something..

#

idk.. just a guess

gloomy jacinth
#

Where it said private void Delay() i added the code because there was only a destroy game object instance there and it worked

rocky canyon
#

but the flag should help

gloomy jacinth
#

Do you know how i can make the gravity less easily?

#

Because i want bullet drop but its quite a lot right now

rocky canyon
#

if u change gravity its going to affect everything in ur scene

#

common thing to do is apply a little force to the bullet..

#

(small upwards force)

rocky canyon
#

if u did +4.9 on the Y it'd make it fall 2ice as slow

#

since ur taking half of gravity and applying it upwards

faint topaz
#

Is anyone able to help me with this code?
It doesn't detect the fifth line in "frases" any idea why?

languid spire
faint topaz
#

It says it's out of bounds

faint topaz
languid spire
#

show the full error