#💻┃code-beginner
1 messages · Page 109 of 1
Okay, I need some help again
My otters are visible
but their coordinates are completly jumbled up
Have you looked into coroutines yet?
this is where they are atm (I stopped the game, the coords keep on changing)
I have yes, but I don't understand how to implement them
If not, consider investing some time into that to substitute your delay feature from sleep
thats the plan, however right now the coordinates are my priority, i can't tell why they're moving wrong.
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Else the game/while-loop will immediately end (an undefined behavior which no amount of bandaid can help)
hello every1, im new
hiya, same here
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
also don't use print()
what should i do now🥺🥺
ues Debug.Log instead
can some1 show me what should i do🥺🥺
understood
please learn how to ask questions
oh my apologize
This is important @vocal thorn
Install Unity, try to make a simple game, when you encounter an error google first and if you find no results then post here
Im aware that the loop ends.
but that shouldn't change the fact that the coords change...
and pls adapt your formating and naming conventions
to one standard
it is unreadable
Immediately, so no amount of replacement will matter - which is what your appearance function does.
i installed but im Python programmer, not C programmer, so idk how 2 code em 😦
then learn it, this is a code realted help question
when you will have an issue with particular code/system/mechanic then you can ask here
also unity is C#, not pure C
You'll either need to learn how to code with c#, find/use specific code on the net (non flexible) or !collab with others
We do not accept job or collab posts on discord.
Please use the forums:
• Commercial Job Seeking
• Commercial Job Offering
• Non Commercial Collaboration
we don't have something to convert them right?
I'm really sorry if this is super annoying, but I can't quite understand what you mean..
any suggestions?
google the unity programming naming conventions
Right. Thank you!
Everything will finish in one frame
I'll send the updated version
OH.
Okay, understood. That's the reason why the Coroutines exist right?
I just read up on that
A slightly random question, but if anyone knows Java, do you have any Tips on how to use that knowledge (other than Algorithms) in C#?
Well if you have the knowledge in Java, then you'll find there's similar/same concepts in c# and you don't even have to learn them bc you know how they works
Common sense basically
it's just different syntax
as any other language
Dont always use class
java have no struct....
is mine wrong cause in the videio they have asset
please watch(?) the video more carefully
oh is it not in the IEnemurator
I moved from Python to Java this year, and it was quite simple, but a few changes. Java to C# is relatively close from Syntax (in my opinion ofc), however I just can't quite grasp everything like with the Java transition, I think that might be my main issue.
While loop is outside of the coroutine or any function which was invalid
yh i put it in
Right I just changed the variables. I hope it's easier to understand now.
im facing this error now
Read what the error says
The code is completely different in those areas
You'll want to follow along more carefully
The name of GameObjects do not relate to how you write code
Is a Coroutine something i should look into?
k thx imma try fix it
Either that or you'll have to implement your own timers.
Or use task-await, invoke, etc
From your personal experience, which one is more reccomendable?
can u elaborate pls
It'd be relative to the task at hand (none are deprecated) https://www.codinblack.com/how-to-run-a-method-at-certain-time-intervals-in-unity/
What you've done was Type = name = stuff instead
please compare your code and the code video shown char by char
This doesn't include c#/unity tasks (which are a bit more complicated) @vocal thorn
I think I'll test out CoRoutines first, see how it works and come back to that if it doesnt work that well...
thank you though!
It would be much easier to write if you tried to understand why you were writing it 
Before I dissapear into Coroutines, I have 3 Otters and I'd like for the code to run for each at the same time, is that possible? (As in, my coroutine would change the position of one otter only and not all 3)
They're GameObjects, does that make a difference?
if i were to type:
startCoroutine(randomappearance(otterTopRow);
startCoroutine(randomappearance(otterMiddleRow);
startCoroutine(randomappearance(otterBottomRow);
wouldn't the next Coroutine start once the first one is done? Or am I thinking completely wrong, and a Coroutine is like it's own process?
You are thinking wrong either way
Okay. Do you mind explaining? I'm sorry for the inconvieniece
The code executes each coroutine until their first yield, and then the next frame Unity resumes at that point of each coroutine if the yield has passed
Nothing executes in parallel/simultaneously, but there will be 3 coroutines running at once
Okay Okay.
You can use the debugger and step over the code for the first execution and see where it goes. Though the next frame execution jumps to the yield from unmanaged code when Unity calls it
Just so that i know I'm understanding it correctly:
the yield in one Coroutine has nothing to do with the yield in a different one, for example:
CoRou 1 -> yield return null;
CoRou 2 -> yield return new WaitForSeconds(5);
it wouldn't wait for those 5 seconds so that it CoRou could move on. Because It's not connected.
They are separate state machines, yep
This is so dumb, but I love the debugging tool in Java, how do you use it in Unity? I've seen the Debug icon at the bottom, but i dont see a change.
google it
Okay, I think i understand the concept now thank you.
"how to debug in Unity using a debugger"
There's good resources pinned about debugging with VS. the video series is quite thorough
Thank you!!! I'll def look into it
bit of a weird question, I have a terrain that im loading into a scene OnSceneLoaded
but due to its resolution and trees and such it seems to drawcall bomb the build into crashing
That wouldn't crash the build. At least not directly.
is there a built in way to gradually stream this in or can i like professionally unity to brace for impact
Indirectly you could be running out of vram, but I highly doubt it.
Inspect the player/ crash logs. There must be some clues to what caused the crash.
im doing some weird unity mod type stuff here w/ assetbundles so i think it might be in this case along with some other stuff. I know the specifics of that isn't the vibe of this server but i was hoping for a more generic solution for it if it exists
The generic solution is: investigate the crash and eliminate it's cause.
There's no more generic than that.
Or logs.👀
anyway, use addressables on that and recude draw calls by batching, making atlas materials, merge meshes together into one
there is a lot of optimization you can do
do LODs etc, many drawcalls = cpu bottleneck
A short video on how to improve your frame rate in Unity. This video covers various optimizations to reduce draw calls such as combining meshes, batching and gpu instancing.
Music Credit: LAKEY INSPIRED
Track Name: "The Process"
Music By: LAKEY INSPIRED
Official SoundCloud https://soundcloud.com/lakeyinspired
Official YouTube Channel:https:/...
I would love to use Adressables here but as it’s mod related I cannot
I’ve been looking through the logs a ton and I can’t find anything that points towards the crash specifically that doesn’t also occur on a build that successfully loads. I can add logs to places but aside from the function where i create it I don’t know where specifically unity crashes between then and the crash, will post a log but ofc it will be missing a lot of context
without any context/data/logs/errors we cannot help you, espeficially in a code related channel 😉
just debug the issue, try to load smaller terrain
see if the problem is indeed in the big terrain itself
then maybe async load it piece by piece
The crash would be the last thing in the logs. Also if it actually crashes, there should be a dedicated crash log.
Or crash report.
what do you even my by crash
does the app just fereze and dont respond
or do you have unity crash message?
game freezes before crashing, i do not get a crash message
not avoiding btw in the process of getting info
Could be an infinite loop then
so this is not a crsah
either infinite loop, or you load extremaly insane amount of data (which i doubt it)
Connect the debugger to the build and break when it freezes(it might break automatically too)
Player.log with crash
https://hastebin.com/share/puqiciciji.yaml
This is the code that instantiates the terrain on OnSceneLoaded (it spawns the prefab, moves all its root objects to the scene and turns itself off)
GameObject mainPrefab = Instantiate(Terminal_Patch.newMoons[StartOfRound.Instance.currentLevelID].MainPrefab);
if (mainPrefab != null)
{
Logger.LogInfo("Moving Custom Moon To Scene : " + scene.name);
SceneManager.MoveGameObjectToScene(mainPrefab, scene);
mainPrefab.transform.DetachChildren();
mainPrefab.SetActive(false);
this is the end of the function and crashes after this, depending on the terrain settings
can I do this at runtime?
Sure
Could be a script in the terrain.
didnt know that! i'd love if you could point me in the right direction for that
only has terrain, terrain collider and ive experimented with a rigidbody too. i've had crashes and no crashes regardless of the rb
how would i go about doing that?
tried googling but couldnt find any solid answers
Google "attaching debugger to unity build".
From the logs, it looks like it's something in the hdrp render render loop, but it's hard to say anything specific, since there are debug symbols missing.
I was under the impression I was limited from doing that as this is a mod that’s injected to a preexisting build
Hello- it's me again. I think I have the Coroutines figured out, the only thing I can't right now is something fairly basic. My otter is always at the wrong coords.
IEnumerator randomappearance(GameObject selectedOtter){
Debug.Log("Coroutine Started");
selectedOtter.gameObject.SetActive(true);
var hInput = Input.GetAxis("Horizontal");
var vInput = Input.GetAxis("Vertical");
int xlocation = Random.Range(1,3);
Vector3 newx = new Vector3(vInput,hInput,0);
if(selectedOtter != null){
if(xlocation == 1){
newx = new Vector3(vInput,hInput,0.7f);
Debug.Log("reached location changer start 1");
yield return null;
}
else if(xlocation == 2){
newx = new Vector3(vInput,hInput,1.4f);
Debug.Log("reached location changer start 2");
yield return null;
}
selectedOtter.transform.position = newx;
yield return new WaitForSeconds(Random.Range(0,3));
}
}
When looking at the coords that I want, they're completely off...
Could be. I don't know how exactly you're building it, so can't say much.
Local position would be what you'd see in the inspector.
the position i want is (0,0,1.4)... It's slightly off.
Probably better contact the actual game devs.
Show the logs
Are you certain they're the same object?
quite yes
Debug.Log($"{selectedOtter.name} has a position of {selectedOtter.transform.localPosition}", selectedOtter);```
okay
Place it before the yield statement but after assigning position
just did!
So you've got a clearer image of what's going on now.
yes
not sure how to fix it though
one second i think i might have found the issue
nevermind
still cant find the issue
i know what the issue is, im not sure how to resolve it
Was that with the edit? #💻┃code-beginner message
what edit?
The edit to the code I provided.
Ah sorry, i didnt see it
It should be the correct object with the edited code
Previously it was analyzing whoever was managing the three
Yes! It's selecting the Children now
So is the info correct?
is there a way to get the axis of the children instead of the parents too? I think thats whats happening,
Maybe you meant to move relative to local position
this is how im getting the coordinates at the moment
could i put a selectedOtter.Input.etc()?
...localPosition = newx;```
I'm not sure what you're doing so I've got no advice.
I tested it and It didnt work
Error code I get with localposition
Take my log example as a reference
Ah, okay I see my error
I think the parent is moving with them because the coords on the children are looking great, but they're landing in the middle of nowhere
The inspector position would be the local position of the object relative to it's parent. If you want their world position to be at the specific coordinates, use position like before.
The inspector value will not be what their world position is if they're child to another object not at (0, 0, 0)
is there a way to lock the parent into place?
i found a solution
if anyone else ever has this issue
just add a rigid body and put all constraits on
you said you got the naming conventions don
I attempted, did i not do it right? I understood it as easy to understand variable names, the first letter small, the other words (if present) with a capital...
IEnumerator randomappearance(GameObject selectedOtter)
that is not a propper funcion naming
infact it makes me not even wanting to read the rest of the code 😄
newx so this should be newX based on your conclusion, why isn't it
I forgot about the functions
I personally don't really set much worth on the names of my variables, i know they're important, however I keep on forgetting follow the guidelines. Apologies.
Probably used to not having the .Net naming convention. 
Microsoft seems to hate snake_case.
Im coming from Java and Python, so possibly? (I have no idea.)
Basically:
- Classes, Structs & Functions: PascalCase
- Getters/Setters: PascalCase
- Variables: camelCase
- Private field variables: _case (I don't think people hear this often but i'm pretty certain Microsoft suggests this and can see this on some of their standard libraries.)
- Interfaces: IPascalCase (Yes, with the I at the start.)
- Attribute Classes: PascalCaseAttribute (With the Attribute at the end. Don't worry about having to use the entire name though, compiler lets you cut the Attribute at the end when using the attribute.)
Thank you! I'll try to keep that in mind.
Nah, don't. Just follow the naming convention when the compiler notification gets annoying. 
I do snake_case for my variables.
There's just some people that wants you to stick to those guidelines as much as possible. I'd prefer to stick to whats right for me.
I feel like that's a good mindset.
you can have your own set of naming convention

Hi guys, how do I assign Meshes/Materials from a ScriptableObject?
...
[SerializeField] ArrowSO type;
...
private void OnEnable() {
MeshFilter meshFilter = this.gameObject.AddComponent<MeshFilter>();
MeshRenderer meshRenderer = this.gameObject.AddComponent<MeshRenderer>();
meshFilter.mesh = type.meshFilter.mesh;
meshRenderer.material = type.meshRenderer.material;
}
public class ArrowSO : ScriptableObject
{
public BowSM.EArrowType _ArrowType;
public MeshFilter meshFilter;
public MeshRenderer meshRenderer;
public Material material;
}
Doesn't work like that, Filter/Renderer are still none in the inspector...
In that case, just disable the compiler checks for the above. 
I personally don't wanna see "IDEXXXX: The name must be in fuck u case."
ty !!
Sure, then you join a company where they are adapted to the standards, and you need to adapt yourself so why not adapt frmo the start to the standards?
I don't see you assigning these fields anywhere.
Assuming you're talking about the SO fields
I hate how you have a point. 
lol
I don't think i'll be a programmer for work though. But i can bend myself in work.
i suggest you follow the naming standard actually, it is easier to read some source code of standard libraries
That's just the bare-minimum.
also when you share code to public
when they are adapted to standards
it is much easier to read your code
instead of your own naming conventions
Some conventions are widely accepted in the developer community. If you go against them, it would be more difficult to get help.
Are there standards on how you sort the members of a struct/class/interface?
(Top to bottom)
- Constructor
- Fields
- Properties
- Methods
- Private Methods
- Static Methods
- Operators
- Nested class or something
I guess? 
There aren't really that I'm aware of, but most people just end up having a similar layout.
fields and properties at the top and methods in the bottom/
usually i will align them manually to reduce padding space
in cpp you can put variables in header, left the methods in other file
same as c
U can do the sorta the same with partial in C# too. 
So why not?
I'm having an ArrowSO, that hat some Meshes and Materials, created several of them for different Arrow Types
Now I want to assign the different Meshes and Materials to just one Arrow Object, that can change it's appearance/behaviour depending on the SO given to it.
public class Arrow : MonoBehaviour,IArrow
{
#region StateMachine
...
#endregion
#region ArrowSpecifics
[SerializeField] ArrowSO type;
#endregion
...
private void OnEnable() {
MeshFilter meshFilter = this.gameObject.AddComponent<MeshFilter>();
MeshRenderer meshRenderer = this.gameObject.AddComponent<MeshRenderer>();
meshFilter.mesh = type.meshFilter.mesh;
meshRenderer.material = type.meshRenderer.material;
}
...
}
Okay. So what's the problem?
I think i'd prefer you to paste the entire !code.
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
That my Meshes and Materials assigned to the SO aren't assigned to my added components on the Arrow GameObject using the Arrow class.
How do I assign the Meshes and Materials specified in my SO to my Arrow GameObject properly?
Are there any errors in the console?
Oh yeah, doesn't seem to be allowed anyway.
`Not allowed to access MeshFilter.mesh on Prefab object. Use MeshFilter.sharedMesh instead``
My bad, f'ed up my debug console
Well, the error pretty much explains it
Yeah, thanks anyway 😄
Hi, I've seen a few resources that suggest to use the Animator built-in state machines liberally for when you need a FSM even if it has nothing to do with animations.
Is this a common practice ?
unity editor cancels all assigned List<> contents when entering playing mode from editing mode any idea why ?
Probably doing with it something in code in awake/start/onenable
maybe even update
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class BossKilledScript : MonoBehaviour
{
public GameObject RewardUI;
public BossScript bossScript;
public LootSystemScript lootSystemScript;
public List<KilledRewardScript> RewardsUI = new List<KilledRewardScript>();
public List<RewardScriptableObjects> Rewards = new List<RewardScriptableObjects>();
public bool Rewarded = false;
void Start()
{
bossScript = GameObject.FindGameObjectWithTag("Boss").GetComponent<BossScript>();
lootSystemScript = GameObject.FindGameObjectWithTag("LootSystem").GetComponent<LootSystemScript>();
}
void Update()
{
if (bossScript.BossKilled == true && Rewarded == false)
{
Rewarding();
}
}
void Rewarding()
{
RewardUI.SetActive(true);
int RewardNum = 0;
foreach (RewardScriptableObjects Reward in Rewards)
{
if (lootSystemScript.ItemID[Reward.ItemId] == false)
{
int RewardRNG = Random.Range(1, 101);
if (Rewards[RewardNum].RNG >= RewardRNG)
{
lootSystemScript.ItemID[Reward.ItemId] = true;
RewardNum += 1;
RewardsUI[RewardNum].ItemImage.sprite = Rewards[RewardNum].RewardIcon;
}
else
{
RewardNum += 1;
}
Debug.Log(Reward.DisplayName + " " + lootSystemScript.ItemID[Reward.ItemId]);
}
}
Rewarded = true;
}
}
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
it is a bit messy in here
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class BossKilledScript : MonoBehaviour
{
public GameObject RewardUI;
public BossScript bossScript;
public LootSystemScript lootSystemScript;
public List<KilledRewardScript> RewardsUI = new List<KilledRewardScript>();
public List<RewardScriptableObjects> Rewards = new List<RewardScriptableObjects>();
public bool Rewarded = false;
void Start()
{
bossScript = GameObject.FindGameObjectWithTag("Boss").GetComponent<BossScript>();
lootSystemScript = GameObject.FindGameObjectWithTag("LootSystem").GetComponent<LootSystemScript>();
}
void Update()
{
if (bossScript.BossKilled == true && Rewarded == false)
{
Rewarding();
}
}
void Rewarding()
{
RewardUI.SetActive(true);
int RewardNum = 0;
foreach (RewardScriptableObjects Reward in Rewards)
{
if (lootSystemScript.ItemID[Reward.ItemId] == false)
{
int RewardRNG = Random.Range(1, 101);
if (Rewards[RewardNum].RNG >= RewardRNG)
{
lootSystemScript.ItemID[Reward.ItemId] = true;
RewardNum += 1;
RewardsUI[RewardNum].ItemImage.sprite = Rewards[RewardNum].RewardIcon;
}
else
{
RewardNum += 1;
}
Debug.Log(Reward.DisplayName + " " + lootSystemScript.ItemID[Reward.ItemId]);
}
}
Rewarded = true;
}
}
Can you remove "using Unity.VisualScripting;" line?
make the lists private
wouldnt that make them unassignable in unity?
Not if you use the proper [SerializeField] attribute
aight
[SerializeField] private List<KilledRewardScript> RewardsUI = new List<KilledRewardScript>();
same :/
its not the update method
i removed it completly and still same problem
it caused by smth else
and it is not refrenced in other scripts aswell
Are these actually scriptable objects..?
uhm not these but other ones
Stop calling your Scripts 'Scripts'
what should i call scripts other than scripts?
So it's fixed?
i think so i just need to find a solution for this new error
just leave out the 'script' part
typical domino effect
What error?
noooo it is better so u can have boss and bossScript at the same time
Why would you need both? lol
Seems like there are more Rewards, than there are RewardUI
boss is the boss game object while bossScript is the bossScript
How the heck are you gonna mix up scripts and gameobjects?
do you know that monobehaviour has a field that reference back to the gameobject?
yes
yea however if im gonna refrence the boss from the player script
so you just need to reference the script
You don't need the this. btw
Then you can name your variables differently. Script/class names have nothing to do with it.
script, rigidbody, etc etc
when i change the health the hearts done decreae
yea ik its just how my brain recognize it
is it that bad tho ?xd
update wont run in edit mode
Is Muliplayer event system known to be unreliable? I have it working perfectly instantiating a UI menu for each player, however if i load that scene from my lobby, it doesen't work at all, every component has been linked as it should be (Player root/First select) but i get no response from the UI even though the player inputs works absolutely fine, i don't know how to trouble shoot it. I can see it has the "first selected" selected but i can't get it to move at all.
shall i remove that line
actually i dont even know if you are in play mode or not....but i guess
this is a code related channel
i just gave you alternative, simplier, shorter replacement for your if/else
im not in play mode
do whatever you want with it
then ofc update wont run unless this class is execute always
why this loop repeats infinitly
i wanted to make it repeat only one time
Aren't components just code visualized in unityxD?
ur confusing me so what shall i do with hat lin e
read again what i said
technically everything is code and visualized by your gpu finally sent to screen
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
it doesn't repeat infitinetly, you are just calling it (probably) every frame.
why do you use a loop
if you want to do something just one time?
yes
shall i replace this with that u wrote
as i said man, do whatever you want with this
you can replace it or not
Components are serialized objects.
would it solve it tho
no
read what i had said
not related to your issue
ok i understand now
you can set dead to false, or even better have another bool that you set to true once you call the code you want to run only once.
do u know how i can attempt to solve the issue
turn on play mode
show all of your code
Create a new method with all the code in your Update function and call it UpdateHeartDisplay()
Call that method in
Update() and OnValidate()
OnValidate() is called in the editor whenever you make changes to the script, so it will now also update before you enter playmode.
ty
if you bothered to go and learn some basic C# you would know how to fix it
Tip: PlayerHealth is a type name.
Or supposed to be at least.
Do you have a script with that name
yh
Show it
nvm it keeps showing up as (script)
even thought when i go on it its called PlayerHealth
Show it
The code
inb4 it NewBehaviourScript
It should be equal but it's not im guessing
This is a variable declaration.
The. Lid.
the class inside the PlayerHealth.cs, show the class together with file name
and
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
im trynna call the PlayHealth script into the dealing damage script
Show the fucking code already
Does that look like PlayerHealth?
mb i thought u can just rename it
You can rename it now to the proper name.
yh i chanhed it thx
called it #💻┃code-beginner message
you can have different class name and file name but only in the newer unity versions iirc
also you might want to restructure your code architecture
SlimeDealingDamage, what if you have skeleton and zombie and more enemy types?
will you do SkeletonDealingDamage ZombieDealingDamage etc for each?
you can make generic DamageDealer class for example and just set different parameters for each enemy (via scritpable objects or directly in the inspector), you can then make other classes based on this class for Boss for example, and with overriding certain functions etc
thx for the tip ill change that
the charachter not taking damage ive looked at the code and console
and cant figure out what to do
Why have an Update method when you can do all of that within TakeDamage method
Start putting Debug.Logs in your methods to see if they are even running
im trynna learn how to do that never done that
Also check your damage field within the inspector to check if it's actually non-zero
the damage is set at 2
Then do a Osmal said
do i have to go here
im watching a vid

or is reading better
You should learn to read the docs first, yes
The video might have some useful tips but start with docs always
this is the first time i got null reference error but no details. I cannot figure out what scripts causing this error. why this happening?
turn on the stacktrace?
would this be corrrect
This might be too deep, put a debug into your OnCollisionEnter2D as this is where it all starts
To see if it even calls that method
Yeah but add some text to it so its easier to identify rather than just a number.
$"Health after TakeDamage: {health}" or "Health after TakeDamage: " + health
i'm trying to precalculate circle segment mults by chord.
each step increases chord length by 0.001 and it is just array for 1000 doubles.
the problem is that with chord length close to zero, central angle in radians is close to Pi, and it decreases as chord length increases, it should be opposite, rigth?
for (int i = 0; i < lengthMultsByChord.Length; i++)
{
if (i == 0) continue;
double chordLength = 1d * i / lengthMultsByChord.Length;
double centralAngleRad = 2 * Math.Acos(chordLength / 2);
double centralAngle = centralAngleRad * 180 / Math.PI;
lengthMultsByChord[i] = ((centralAngle / 360) * 2 * Math.PI);
}
i think i can just inverse angle, but how it works?
assuming r = 1
But the main idea is to see if the functions are running at all @whole isle
i can check the health whike running cause i can see on the script and the heart
and it dosent decrease
Ok but you still dont know if the functions are running or not unless you do some debugging.
thank you, set the stack trace logging to full in console menu shows the details.
some1 told me
No, they didn't
i guess i misunderstood
At no point did anyone tell you to try to log a function
You were told to log to check if the function was being called.
k i changed it
Debug.Log("it works");
ohhh so if the function works it will say itworks
Correct.
would i check the console for the message
All Debug.Log() does is send a log message to your unity console, which you can then read, so the input parameter should be a string or something convertible to a string
Also reading the docs is helpful
you can also pass a second argument as the "context" of the log. clicking on the log entry will take you to the context object in the hierarchy.
Debug.Log("I worked", gameObject);
(or in the project window, if it's an asset)
I have some editor scripts that check for any invalid assets
e.g. I forgot to give something a description
it'll log a warning, and clicking the warning will take me to the bad asset
; means you're ending a statement
which is invalid on an if statement makes if statement pointless
Restart your editor.
that's a problem on unity's end
There's a bug with the code that draws graphs (like for animators, I think) that makes it spew those errors
Well, it's valid, but it means the if statement is entirely pointless, it contains no code
yeah mb, ill fix it 😅 its still compiles fine but the if useless yea
its gone now somehow
the message is still there actually but the game loaded
this is the only thing i get
but i dont think it related
you have empty Animation Event on your animation clip
found it and got rid of it
Yeah that sounds like a good way to reset the animator state
thats good
Did you actually open the console to check
mb i thouight i was on console log let me chek
still nothing
Then nothing ever calls TakeDamage
so your collision don't work ? https://unity.huh.how/physics-messages (follow this guide)
Next check if OnCollisionEnter2D is being run and log the other object/its tag too
Put some thought into it
i tried doing bothj
collison2d and collisom
then i tried doing Collison2D by itself
ill try playuer
Trying random things won't help
You are accessing the tag right above it. I didnt tell you to log the collision itself, but the tag.
Also a comma is not how you print multiple values here
so i would need to look in the other function
do i need to add another debug log underneath
Im so confused how you come up with this random stuff from simple instructions
😭
Probably best if you read everything 4 times
Log the tag and name of the object you are colliding with
wdym when u say tag
.tag
oh
You are literally already using it
private void OnCollisionEnter2D(Collision2D collision)
{
Debug.Log($"Hit object: {collision.gameObject} with tag: {collision.gameObject.tag}");
}```
if you're curious about $, its called [String Interpolation](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated)
thank u
nothing happeningggg
then you did not follow this ? #💻┃code-beginner message
what the diffrence between Kinematic rigid boddy trigger and the 3rd 1
Sorry if this is the wrong channel, but I think the "beginner" channel could help me with everything so, I am trying to add a package through Git URL but its not working, I tried adding a manifest line but then there is written, that I need to have Git installed on my System, so I installed it and added it in my system environment variables. But still its not working... please help me
Kinematic Rigidbody refers to a rigidbody that is set to kinematic and does not have a trigger collider.
Kinematic Rigidbody Trigger refers to the same thing but with a trigger collider
Someone knows how to place the IDE for modding a game in VSC? Idk if it's the same for unity, since i have it installed and no errors show for unity (It's a unity game obviously, and idk if i am on the wrong channel, if i am please lead me to the channel where i should be)
would a trigger collidee be like my charchters sword
modding is not supported on this discord
#📖┃code-of-conduct
how should i know whether your character's sword has a trigger collider or not?
k im pretty sure it does
rather than being "pretty sure" you can just look at its collider and find out
Hi guys, how can I use a ParticleSystem defined on an ScriptableObject on my GameObject?
Having a ParticleSystem that holds a reference to a flame prefab
public class ArrowSO : ScriptableObject
{
public ParticleSystem ParticleSystem;
}
Want to instantiate the ParticleSystem hold by the SO and play it on my arrow, but watching in debug _ParticleSystem stays stopped
public class Arrow : MonoBehaviour,IArrow
{
...
[SerializeField] ArrowSO _Type;
Awake(){
...
if(Type.ParticleSystem != null)
{
_ParticleSystem = Instantiate(_Type).ParticleSystem;
_ParticleSystem.Play();
}
...
}
How can I use a ParticleSystem defined on a ScriptableObject?
yh it is each time i click the sword then the clollider turns on
that's not what trigger collider means. there is a checkbox that is literally called Is Trigger on the collider
its turned on
you need to instantiate the ParticleSystem
there's nothing about modding in that channel i think, i passed it 2 times
Also you define _Type but you are using Type
Wow you know the server rules line by line or something?
oh k i guess.
My bad, was just from copying the code over to Discord
oh
no, i just know how to read
dam im slow to send today
Did you understand what you are doing wrong?
i think this is my problem
why
nvm it not mb
Thought I already instantiate it by _ParticleSystem = Instantiate(_Type).ParticleSystem; or do I have to do it like
var SO = Instantiate(_Type);
_ParticleSystem = SO.ParticleSystem;
both are wrong. You are Instantiating the ScriptableObject and not the ParticleSystem
So you are telling me that the moment he said modding you went to the rules and checked if his message didnt break any rules? I dont think anybody does that. You can only say that instantly when you know that rule from before
i've also been here long enough that i know modding is not permitted. and if you knew how to read you would know that i wasn't even the person who pointed out that modding isn't permitted here, i just pointed out that they were wrong about modding not being mentioned in the rules
You should try reading things instead of just looking for copyable things and blindly copying
So how is it done then?
Do I have to use AddComponent<ParticleSystem>() and copy the values from the SO?
you need
ParticleSystem particleSysClone = Instantiate(_Type.ParticleSystem);
He literally said "It's not in the rules" with a link to it. Then we clicked on it and found it, it's like eight lines down
it's not hard to find
Oh so you can also instantiate a ParticleSystem by itself? Didn't know that
Well that's what I said previously that you know the rules of the server but you are the one who said "No, I just know how to read. "
You can Instantiate any unity object
Yes, because that's how they found the rule that they highlighted. By reading. Reading the thing the other guy said wasn't there
preachhh
So ParticleSystem is inheriting MonoBehaviour and thus can be instantiated?
Does everything that can be seen in the Inspector work that way?
no it's inheriting UnityEngine.Object and hence can be Instantiated
Note that if you instantiate a reference to a component, it clones the entire object that component is on
My point was that he had to know that discussion about modding was not allowed in this server which he admitted himself.
Instantiate clones an entire GameObject, so you can pass in the object or anything on it
OK, good to know, time to refactor some stuff 😄
Thanks!
@rich adder soz for the tag but i went through the entire thing and couldnt find the problem
- They weren't the person that originally pointed it out
- They've been here for 3 years and there's like twelve rules it's not hard to learn
christ you're really set on being right, aren't you? well if you want to familiarize yourself with what is and is not allowed here you can go read #📖┃code-of-conduct yourself
So which object has the rigidbody2d
show both objects colliding, their inspector
I never said it is hard to learn the rules, I was just amazed that he knew them so well considering I am fairly new to the server
Also I wasnt even talking to you @polar acorn
you will find that all of us regulars know the rules and we enforce them as much as the mods do
preachh
Okay so you didn't follow the instructions on the page
ohh that's amazing, in all the other server's I had been no one bother's rules
tuff this 1 does
no
not referring to that at all
you're using wrong method for your collider types..
it's self preservation and for our own sanity
On this page, which link did you click
https://unity.huh.how/physics-messages
nice
i wam working in 2D
On this page, which link did you click
https://unity.huh.how/physics-messages/2d-physics-messages
collison message
and are you using colliders or triggers?
Where on this grid would you place your two objects
this will never work with OnCollisionEnter
(2,3)
Why
Do you know what a trigger is
Do you notice how both of your objects have both a rigidbody and a trigger
they are also both kinematic so even if is trigger was disabled for both that wouldn't even be the right one
😭
so what do i ned to do
You need to actually figure out what you're doing instead of changing random checkboxes
it's not magic, all those changes mean things
Is that new, never seen it
You've been here for days coding by successive approximation, you need to actually do some guided learning on !learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
ill do that from tmr
It's on Vertx's frequently asked question site
https://unity.huh.how/
i just wanna finsih this health systme
Thanks
then do it correctly lol
Bro I think instead of just asking for help and copy pasting other's codes you can learn and write the code yourself.
If you are having a problem you can ask here but you are practically having these guys babysit you which is not appropriate at all.
ill stop asking for help after i finish the health
i promise
when i start my game i cant see my spaceship
so how could i do the backround transparent so that i could see the game objects?
the image should be on the Backround
first, this is a code channel. second, you're not really providing enough context
be mad
Did you mistype "my bad" or are you being a dick

mimimimi
someone clearly doesn't want help
bro i just only ask a Question
def the latter
in the wrong channel
Hahahahah
ok
Markus wreakin havoc in the Unity Discord Server
what?
what channel should i use?
id:browse Find the right one for your question
ok but why are these people so toxic here
nothing toxic about it. There are rules, we obey those rules, so must you
You were the most toxic person here. Someone pointed out the rules and you insulted them.
And then antagonized people
Asking the question in the relevant channel only serves to actually get your question answered instead of ignored but if you want to be ignored you do you
Lol literally just did the Unity Tutorial Create with Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveForward : MonoBehaviour
{
public float speed;
void Update()
{
transform.Translate(transform.forward * Time.deltaTime * speed);
}
}
For some reason the object doesent move along the local z axis, but rather the world z axis.
Thought transform.forward is local and Vector3. forward is global and sometimes it works like that too...
afaik Translate default is self no ?
Hey guys.. was checking here on how to communicate or transfer data between scenes.. and found some ways to do it.. any tips or best practices on that? Never done it and I might need to do it now first time. thank you!
when is "sometimes"
Link us to the tutorial page you're on.
Well there are several ways
- Scriptable Objects
- Make a save file and save your data in there and you can retrieve it in another scene
- Have a DontDestroyOnLoad Gameobject store important variables
You're correct in that transform.forward is the forward direction of the transform and Vector3.forward is global.
last tutorial project
aka last script that did the same
Also static non-monobehaviour classes
Show us that last script, then.
Overview: In this lesson, you will allow the player to launch the projectile through the scene. First you will write a new script to send the projectile forwards. Next you will store the projectile along with all of its scripts and properties using an important new concept in Unity called Prefabs. The player will be able to launch the projectil...
hmm yeah.. i dont know found kind of dumb of unities part.. u need to save or go around just to transfer data between scenes.. i dont know.. any ways i got the idea now. thank you!!
yeah
Notice the difference.
transform.forward is a vector pointing in the forward direction of the transform. The vector is a world-space vector.
transform.Translate interprets the vector you give it in local-space, by default.
So transform.Translate(Vector3.forward) moves you forwards by 1 unit in your forward direction
Actually for most cases non-monobehaviour classes should be go to option. I forgot to mention them lol
never used transform. Translate
transform.Translate(transform.forward) will be unpredictable
Suppose you're pointing straight up
always jsut used transform... += ... xD
transform.forward will be an up-vector: [0, 1, 0]
or mostly rigidbodys
same
Passing that to Translate will move you in your local up direction
Yeah they're of great use, for example I'm using them to keep a cache of all loaded save data and stuff
which will make you move sideways
It'll work perfectly if you aren't rotated at all
in that case, local-space and world-space directions agree exactly
and transform.forward will be equal to Vector3.forward
That's why your code sometimes worked
I would not think of Vector3.forward as being "global"
A vector, by itself, doesn't have any context
Vector3.forward interpreted as a world-space vector points in the world +Z direction. Vector3.forward interpreted as a local-space vector points in your +Z direction
ok and when the function itself usees local space it is reversed I guess?
var a = transform.TransformDirection(Vector3.forward);
var b = transform.forward;
These are the same thing
You wound up doing this
var a = transform.forward;
var b = transform.TransformDirection(a);
b is...extra-transformed
it doesn't really make sense
ah ok got it XD
var a = transform.InverseTransformDirection(transform.forward);
var b = Vector3.forward;
these are also identical, btw
Transform* goes from local to world space. InverseTransform* goes from world to local space
any thougts about that please ?
Not super common from what I know but it's a valid option
yeah, it is a state machine
Probably not common because it is rarely spoken of
ok thanks
It's an interesting concept but I would be concerned about the unnecessary overhead compared to just rolling your own state machine system
Hey, guys! I have a question. I want to pause and unpause my game whenever the game is running and it is not game over with an ESCAPE button how to do that?
So, when the game is over to not allow the player to interact with that button.
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (pauseIsActive)
{
StartCoroutine(ResumeAfterDelay());
}
else
{
StartCoroutine(PauseAfterDelay());
}
}
}
IEnumerator ResumeAfterDelay()
{
yield return new WaitForSecondsRealtime(pauseMenuScreenDelay);
pauseIsActive = false;
pauseMenuScreen.SetActive(false);
audioManager.mainGameMusicAudioSource.UnPause();
Time.timeScale = 1f;
Debug.Log("Pause menu screen is disabled after delay!");
}
IEnumerator PauseAfterDelay()
{
yield return new WaitForSecondsRealtime(pauseMenuScreenDelay);
pauseIsActive = true;
pauseMenuScreen.SetActive(true);
audioManager.mainGameMusicAudioSource.Pause();
Time.timeScale = 0f;
Debug.Log("Pause menu screen is enabled after delay!");
}```
I have this code on my UI manager script here!
Use a "game over" bool and just check that?
So, here is where I am interacting with that button and pausing and unpausing actually
I have made one time before this functionality but now I got confused!
whats confused on
May I recommend a global event?
public static event Action<bool> OnGamePaused
then anything that needs to stop doing stuff, ie like UI you can disable interactor/raycast
unless I misunderstood the q sorry xD
Oh, that's seems cool! How to use it do I have to copy paste that somewhere in my code?
put it inside a GameManager script or something
then anyscript that needs to know game is paused you subscibe to it in Enable
So, what that does actually can you please specify?
its just an event. if you pause game you can have other scripts do stuff depending on if game paused/unpaused. isn't that what you wanted?
I think he just wants the player to not be able to pause the game once the game is over.
Just add a bool for gameOver in there.
Yes that's what I want
yeah def a bool but may I suggest enum instead ?
Yes!
imo its cleaner to have your gamestate be enum
instead of a bunch of bools
public enum GameState { Playing, Menu, Paused, GameOver} //etc.
I usually have something like this with also an event OnStateChanged?.Invoke(currentGameState)
currently when i accelerate my car quickly stops because of the drag value of my rigidbody. how can i make my car not stop so quick without changing my drag values (cant change them because my suspensions wouldnt work well anymore), im using AddForce for accelerating the car
why would it break suspensions
i bet it'd get too powerful and fling the car around
I suspect you just need to tune your suspension as well
maybe the suspension spring joints need more damping
I've been going through similar things recently
trying to find a good combination of parameters that doesn't just explode the object
yea thats what is happemning
whenever i fall and land its like constantly bouncing
Damp the spring joints themselves
yea i just got it
There is this
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
And good resources pinned to this channel
quick side question, should i use an empty parent object for my car and attach the rigidbody and driving script to it or just have the carmesh be the main parent with all the scripts and the rigidbody?
i prefer the former
(in general, not just when doing physics)
that makes it way easier to swap out the model
thanks
Which one? Unity.learn?
Go to pathways and do the "essentials" pathway, then the "junior programmer" pathway
Hey, guys! I want to know when we declare a bool variable called gameIsActive what we mean when we want to use it somewhere in our code. I mean the game is active when the play mode is active or when the game is running like the player is playing the game?
This bool variable confuses me sometimes and I don't know in which cases to use it that's why I ask.
A bool is just a variable that can have one of two values : true or false
what we mean when we want to use it somewhere in our code. I mean the game is active when the play mode is active or when the game is running like the player is playing the game?
I don't really understand this question. The scope of the variable really depends on where you declare it
You should learn about the various different types of variables in C#:
- Member variables
- Local variables
And modifiers like static etc.
As a general rule anything you do in code is something that will exist in your game program when it is running, The exception is if it's a serializeds variable somewhere you can then assign it in the editor/inspector.
Im following a ground check tutorial vid and in the vid he was able to see the BoxCast and I cant here is my code ``` void OnDrawGizmozs(){
Gizmos.color=Color.red;
Gizmos.DrawCube(transform.position-transform.up*maxdistance, BoxSize);
}
bool GroundCheck(){
if(Physics.BoxCast(transform.position, BoxSize, -transform.up, transform.rotation, maxdistance, LayerMask)){
return true;
}
else{
return false;
}
}
Did you enable gizmos?
Thanks for that! I know all of that you say I am using C# and learning it already a year or so and I have learned the basics. I just got confused with that specific gameIsActive variable like if we use it when the play mode is active or when the player is playing the game and for example when the game is over then game is not active so bool will be false.
I have no idea what variable you're talking about
gameIsActive sounds like some custom variable you made
idk how
press the gizmos button
first time using them
I dont see one
top right
Public bool gameIsActive; when we declare it on our own
there's nothing special about that
you could have called it public bool ajlskhdlakjhrfelkjhrf;
learn the enum like I suggested and set your gamestate with that @sage mirage
it's just a normal bool variable
I mean when you call it with a name and you want to use it for something specific you will not call it fjdhvuduirth
sure buyt my point is jthe name of the variable is irrelevant
the variable will behave the same no matter what name it has
Still cant see them
ur missing a comma
where?
do you have any compile errors?
nope
You sure?
You are asking us about the use case of a variable that you yourself made, can't really answer that
If someone suggested it and there is some context then ask whoever suggested it
send tutorial
Learn how to use Boxcast to check if the player is grounded in Unity.
#unity3d #unity3dtutorial #unity2d #unitytutorial
You can get the code samples from
https://vionixstudio.com/2021/10/26/how-to-make-a-character-jump-in-unity/
TIMESTAMP
00:00 Introduction
00:36 Different ways to Ground Check
02:31 Ground Check in Unity 3D
08:14 BoxCast not w...
timestamp for boxcast
lemme try to find it
between 3:00 and 6:50 imma try to find the exact moment tho
about 4:10
oh ig you did copy the same
heres the full image
You spelled OnDrawGizmozs wrong
it should be OnDrawGizmos
OnDrawGizmozs
so thats what ive been doing wrong
oh nvm im too slow today
This isn't really a code question.
#🔀┃art-asset-workflow maybe?
Now that I actually got to see the boxcast if my player moves the boxcast also moves making it impossible for him to jump sometimes
Would you say this Kart Controller is a good alternative to RCC?
nah man xd
Is there a glaringly obvious reason the Scale of these GameObjects returned via method are incorrect and do not update whatsoever?
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
you're overwriting size each iteration
so I need a Vector3[] for scale as well
scale is set to the last value of the itteration, so yes if you want a scale per object
thank you
not sure why you have 2 identical loops though @ocean wolf
for(int i = 0; i < TPRP.Length; i++){
colliderLengths[i] = (point[i].transform.position - associated[i].transform.position).magnitude;
scale = new Vector3(width, width, colliderLengths[i]);
}
for(int i = 0; i < TPRP.Length; i++) {
go[i].transform.position = TPRP[i];
go[i].transform.rotation = Quaternion.LookRotation(point[i].transform.position - associated[i].transform.position);
go[i].transform.localScale = scale;
go[i].GetComponent<MeshRenderer>().material = blue;
}
make them one loop
then your scale is ok
@languid spire @rich adder cheers fellas
why am i getting this error in particular? i dragged an item into the "spookyenemy" field
Maybe you have a different instance of the component somewhere
Or you unassign the reference in awake or start
this is my code
using System.Collections.Generic;
using UnityEngine;
public class tutorialSpawning : MonoBehaviour
{
[SerializeField] public GameObject spookyenemy;
[SerializeField] GameObject spookyscaryskull;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Player"))
{
Instantiate(spookyenemy,transform.position,Quaternion.identity);
Destroy(spookyscaryskull);
}
}
}
Then the first thing I said
Type "t:tutorialSpawning" into the hierarchy search bar
I'm making a tetris-like game, but when the pieces aren't 0 degrees, they don't fall down.
probably worth it to post some script of the problem
Me?
yes, but please screenshot what your code looks like in your IDE to get started
you didn't do that yesterday when it was requested of you
this is not your ide
Lord almighty that code style
screenshot your code editor
My god. Why!?
What?
why am i not surprised it's vs code after seeing this god awful formatting
Put it all on one line at this point
also i can see you didn't listen to a thing that was told to you yesterday considering you're still trying to use the individual components of transform.rotation as if they are actually in degrees
How do I fix that?
at this point it would be quicker and easier if you just started over and learned the basics first
And focus especially on code style while learning, please
Oh, well alright then
That's how every conversation has been with them. They post a question, people react, how do I fix it, they dont respond further and come back another day
Just gotta wait until people who'll just hand out the solution for free with no follow up questions are out. Like prodding a jenga brick until you find one that's loose
This is a special case, no one is reading that code
I must say, that is probably the worst block of code I have ever seen and that is saying a great deal
I've seen worse
Hah sadly me too
At least the variables aren't all sequential single letters
Don't give them ideas 
cant say my first tetris game looked all too well haha
My favorite part is that it's a screenshot. You literally have to review it as is 😄
in all fairness i did specifically request a screenshot so we could see if they are using a configured IDE. and of course they are using vs code and screenshot it in a way that doesn't make that very clear
tobe fair to VSCode even that formats your code with C# devkit
idk wassup with theirs
I'll leave it at - at least they are trying and didn't copy it from chatgpt
I'll say one thing for their code formatting, at least the misplaced ; was blindingly bleeding obvious
i get some fps drop because of this scene what can i do for optimization
that grass tho
probably what lagging
what can i do for it
is it on a terrain
First time I've seen that code format structure. Sheesh . . .
grass should be somewhat optimized, but the verts would still add up
ideally I'd look into baking the fort meshes together
yea terrain grass is just billboard yes?
is fort static ?
that should at least bake it into a whole mesh
oh yeah static should work (probably better if you don't want to deal with the culling)
how can i do static
Hey
I made a “private Coroutine deathPlayer”
And then to call it I did
deathPlayer = StartCoroutine(DeathPlayer(“Animation));
That works fine, but to stop it I did
StopCoroutine(deathPlayer);
The coroutine did not stop
show the full !code (use link)
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
What I described there is the only things that are important
context of the code is more important
I don’t see the point in using that since it will show the same thing
i couldnt find this section
this is a code channel
deathPlayer = StartCoroutine(DeathPlayer(“Animation));
really?
That is how you stop a coroutine that is playing, yes.
#💻┃unity-talk
also is the Rendering section (window => rendering)
What do you mean “really?”?
well what you've posted would be a compile error
well that line of code will not even ccompile
The thing is it didn’t work
https://hatebin.com/nzwvlfqihy
eye-bleach I tried to fix the formatting.. Not sure if i got it exactly correct, but the {s starting blending in to each other about 2 if statements in.. lol
share the full code as requested
Hence 🫴 #💻┃code-beginner message
*(“Animation”)
Meant to put that
Ok
I’ll show it then
But anyway, not interested in people who are resistant to help. Hopefully someone else can.
That is why you just show your code properly from the start. You cannot show 2 lines of code then claim all is correct. If all is correct then you dont have an issue
(But likely you're calling the coroutine multiple times 🏃♂️)
we have a winner
Never presume you know what is relevant to share and what isn't ever again.
I just put that there for a sec, I’ll explain it now
you never bother checking if the coroutine is already running when you go to start it
damn, are we having a 'bad code day' or what?
that is also a gigantic mess of conditions
That would be a good idea, I think that would work
You must be misunderstanding
When I missed the quote I was actually typing it from memory, in the actual code it works
I mistyped it
the parameter is the last thing they're prob referring to
I meant your code, have you never heard of caching GetComponent?
Why would I need to
or caching soundclips..
any reason why my editor / game stopped seing OnRightClickEvent? It was working just fine and then suddenly (no idea what I did wrong) it stopped working and rightclick event doesn't get registered at all
I don’t want to make a giant mess
ironic
first rule of programming, never repeat anything you dont have to
It's an even bigger mess with all these GetComponents and Resources.Load
Like dear lord, it's been a while since I've seen this many in one place
sfx.GetComponent<AudioSource>().PlayOneShot(Resources.Load<AudioClip>("sfx/Hr_run_jump"));
this can literally be
someAudioSource.PlayOneShot(Hr_run_jump);
or hell use a dictionary/lists of Sfx someAudioSource.PlayOneShot(soundFxDict[c_run_jump]);
You can literlly load those in from resources
just in awake
put them in dictionary
lookup each sound by const of names or something
do something else other than what you're doing now lol
prefer a bunch of fields over dozens of unnecessary getcomponent and resources.load calls
Hello everyone! I'm working on a Unity project and need help creating a custom function in C#. I want it to behave like Start or Update but with a 3-second delay after the game starts. Is there a recommended way to do this and allow different scripts to define their own behavior for this function, similar to Start? I've tried Invoke but seek a solution that supports different implementations in various scripts. Any advice or examples would be appreciated! Thanks!
Did i express good myself?
for delayed functions Invoke should be enough tho
hmm... i want to do it on many scripts... so my intention is like to create function like start , for example delayedStart, callable from every scripts just one time from each script... idk if i'm expressing good myself...
I try to stay away from unity's invoke
why?
iirc it uses reflection
/slow
idk if its still like that
I dont use it
You can do coroutine as suggested, but I have to ask what is the purpose of this? This sounds like you're trying to combat some execution order in a poor way
oh right
I feel the beggining of the game it's like not as fluid as i would like... idk if its cause i'm doing too much things on start / awake... so i hope executing some things later would make the game start a bit more fluid (i have a loading screen, so i dont care calling a bit later some things
Using forces (rigidbodies), I'm looking for a way to generate a very specific radius of gravity instead of a lesser field of gravity over an area. Would that be possible or should I just consider doing my own transformation logic
fun fact but you can turn Start into a coroutine and just put a delay right inside of it if you need to
that's another posibility
i'll first try it with a corrutine to try... thanks @slender nymph @rich adder @eternal needle @golden otter 🙂
void OnCollisionEnter(Collision collision) {
if (collision.collider != null)
{
rb.velocity = new Vector2(0f, 0f);
}
}
am i using it wrong

what about this:
void OnCollisionEnter(Collision collision) {
rb.velocity = Vector2.zero;
rb.isKinematic = true; // disable physics
}
its prob cause its a 2D game
this still wouldn't work
then you prob want to use 2D physics messages 🙂