#💻┃code-beginner
1 messages · Page 288 of 1
https://hatebin.com/tnqtaqdayq @sashok
omg you're a life saver that works, thansk so much 😭
If you drag the script asset in, you'll only see "MonoScript" in the list of things you can call methods on
(and that doesn't even exist in the built game)
it was because i was using slerp
what was that method that returned 0 if a vector3 was right in front of a direction, and 1 if the vector3 was behind the object?
I am not aware of a method that does exactly this, but this sounds a bit like Vector3.Dot
Dot tells you how well two vectors align
Hey guys I wanna add a way to attack in my game. I dont have any sprites for attack so i wanted to make like a sword go around in a circle like terraria. Anyone know how to achieve this. Dont worry about hitboxes or collision detection just wanna know if anyone can do the spinny thing with a sword
Two unit vectors produce 1 if they align, 0 if they're perpendicular, and -1 if they point in opposite directions
!IDE
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
Ty for the help
how do i use Vector3.Dot so it returns -1 if a ct.go.transform.position is to the left, 1 if its to the right, and 0 if its on the front of transform.forward?
i have a prefab on my enemy; i also have an enemyspawner that instantiates more enemies over time, but as soon as I destroy the original enemy, they obviously cannot get the prefab anymore since he died
whats the easiest way to fix it?
what are you actually trying to do here?
what gameplay are you creating?
im trying to use the data for my animation controller
i have three animations, one for front melle attack, one for left, and one for right
I'd suggest using Vector3.SignedAngle followed by Mathf.InverseLerp and Mathf.Lerp
SignedAngle gives you the angle between two vectors.
InverseLerp turns a range of values into 0..1
and Lerp turns 0..1 into a range of values
float angle = Vector3.SignedAngle(transform.forward, targetDir, transform.up);
float t = Mathf.InverseLerp(-90, 90, angle);
float result = Mathf.Lerp(-1, 1, t);
here is a diagram of what i want
That might be backwards. I always forget which way the angles go
(so you might need Mathf.InverseLerp(90, -90, angle))
If angle is 45, Mathf.InverseLerp(-90, 90, angle) would produce 0.75
Then Mathf.Lerp(-1, 1, 0.75) spits out 0.5
If you need to snap this to -1, 0, or 1, you can use Mathf.Round
using InverseLerp followed by Lerp is basically a remap
i dunno why Mathf doesn't have that baked-in
whats the difference between Vector3.Angle and Vector3.SignedAngle?
Angle produces a value between 0 and 180
It can't distinguish between a left turn and a right turn
SignedAngle takes a third argument to figure out which way is left and which way is right.
so its the same but always positive?
hence transform.up being included
I'm not sure if it's exactly equivalent.
notably when the two vectors are not in the plane of the third vector
right
Vector3.Angle(Vector3.forward, Vector3.right + Vector3.up);
Vector3.SignedAngle(Vector3.forward, Vector3.right + Vector3.up, Vector3.up);
I'm not sure how signed angle behaves there
I've always used it with vectors that I've already projected onto the Vector3.up plane
well, thanks, ill try it out and see if it works
I'm currently working on a project involving scripts for a car, a spawn zone, and a GameManager in Unity. I've encountered an issue where I want the game to transition to a 'game over' scene when an object spawned by the spawn zone script touches my car. However, I'm having trouble implementing this functionality. Like I create a script for my object that get spawn but the code I use aint working. I would appreciate any help! 
Use an OnTriggerEnter func and use SceneManager.LoadScene inside the function
You should read the docs if you want more info on how these work
can anybody tell me why the projectiles appear on that wall on the top?
they are supposed to be created on the transforms with the yellow gizmos(assigned in the flechetteDirection Transform array)
https://hastebin.skyra.pw/falasavoxe.csharp <- Hunter_Flechette.cs script placed on the projectiles (position assigned on line 41)
https://hastebin.skyra.pw/xoturuyaya.csharp<- AI_Hunter.cs script creating the projectiles (Init() func of the Hunter_Flechette script called on line 94)
I have this but doesnt work
the gm is for my GameManager script that has the Game Over scene
What is scenefin()?
Is the Game Over scene (some of my code is in french oop)
It supposed to bring to bring u to another scene
Just for context that part is also for some portals I have that if u collect them all it will bring u to You Won and if u dont Game Over
idk if that is why it cause some trouble for my code to work
Add debug.log statements first and then keep troubleshooting
Ayt!
Are those included in build?
I have a script for those element as well, those work fine.
What do you mean?
The those scenes included in build?
I'm talking about the scenes you're trying to load in the image above
aah oop my bad
Yes they are in the build cuz they work with my portals when I collect them all and when I dont
And you say they're not loaded in the SceneFin method?
I just cant make it work for my spawn object that when it come in contact with my car it doesnt bring me to the Game Over scene
Have you added debug statements yet...
Is the method even called?
Yeah, that's what you usually do before asking a question
You should figure out what part of the code isn't working
I add a Debug.Log but it doesnt show anything
Define "doesn't work"
Step 1 is adding debug.logs to figure out wgat runs and what doesn't
Where? You want to add it before the if statement in OnTriggerEnter. And one IN the if statement
Yes, so the method isn't called?
to this but Imma add it to the other script as well
push.
The Three Commandments of OnTriggerEnter:
- Thou Shalt have a 3D Collider on each object
- Thou Shalt tick
isTriggeron at least one of them - Thou Shalt have a 3D Rigidbody on at least one of them
Is it a traditional English?
Also IsTriggerEnter is called when the object, containing the script, has isTrigger ticked
Otherwise OnCollisionEnter
Quick question is there ever a scenario where you configure your IDE correctly and it doesn’t work?
- They do
- If I put isTrigger on my car it mess it up and when I put it on the object in goes through the ground (but I will check something)
- They do
What if it’s a 2D project 👀
The same, but usually with 2D colliders and rigidbodies
Yes, the same way 2x2 doesn't equal 4 when done correctly 😅
"Correctly" implies that it will work, you have to be more specific
Ok thankyou, I’m in another discord for helping people with code someone asks a question (code is all black no colours, doesn’t autocomplete) I tell this person configure your IDE he says it doesn’t work and now someone is helping him manually change the colours in visual studio settings
Haha Thankyou I know I’m just being annoying
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
You should forward this to them ^
Already did 😭
IsTrigger is only needed on one of the two objects
But it IS required for OnTriggerEnter (obviously, see the name)
Then you wouldn't be using the 3D collision methods
Make sense, I will figure out something
Thanks for the help yall!
If neither one is a trigger then why are you using OnTriggerEnter? Use OnCollisionEnter if they're both solid
Does the other object NEED a rigidbody? It won't fall through the ground if you don't have one
I wonder whether you should help them if you don't know it yourself?
Are they too shy to ask themselves? You're both going to end up wasting more time on this
oh that may solve it
Rigidbodies are for things that should be affected by physics in some way. If it's just a pickup or checkpoint or something, I see no reason for a rigidbody
I was able to fix it!!
i actually needed my rigibody since that object come from my spawn zone meaning they fall from the sky
Ah, fair enough. One idea that comes to mind is to have the rigidbody for falling, then when it collides with the ground, delete the rigidbody and switch the collider to a trigger.
Or just use OnCollisionEnter for everything hahaha
Glad you fixed it
I guess OnCollisionEnter would have solve it quicker hahaha I will keep it mind!
I appreaciate the help!
is there any limit in string size in unity?
no
That's kind of a terrifying question. What is the purpose of that question?
im loading a 266 Kb csv into a string and its giving me trouble
can i store it on a string list somehow?
does GetComponentsInChildren() also return a component in its array if its placed on the object calling this method?
https://docs.unity3d.com/ScriptReference/Component.GetComponentsInChildren.html
Gets references to all components of type T on the same GameObject as the component specified, and any child of the GameObject.
yea
lets say the first line of a virtual method has return in it, and a method overriding it, has the base method, on its first line and some other operations next. will those operations also be aborted?
base.TakeDamage is just a function call
It behaves the same as if you did SomeOtherObject.TakeDamage() instead
it just specifically calls the version of the function from the parent class instead of this one
static fields cannot be accessed on instances
since they live on the class itself
why is damage static in the first place
with a raycast, is the layer you pass in one to ignore or one that it will only collide with?
it can be both
ah, how might I tell which way round I have it?
if you add ~ you can Invert the mask (hit everything else but these)
As i've got a layer for objects that can obstruct the view of something, and a player layer it needs to try and pickup on
given that, i think mine is just set to hit the layer I've given it
just trying to troubleshoot why this isn't working as I'd like
Vector3 playerDirection = playerLocation.position - transform.position;
Ray ray = new Ray(transform.position, playerDirection.normalized);
if (Physics.Raycast(ray, out RaycastHit hit, playerDirection.magnitude, obstructionMask))
{
Debug.DrawLine(transform.position, hit.point);
print("passed LOS");
return true;
}
else
{
return false;
}
``` I have it so when I enter this radius, it should perform a raycast to see if the source has LOS on the player, but it always returns false. Think I've missed something somewhere
try Debug.DrawRay(transform.position, playerDirection.normalized * playerDirection.magnitude; instead
put it outside the if statement
How could I find which enemy in a 3d space is closest to my crosshair in the center of the screen?
Vector3.Distance + ScreenToWorldPoint
Thanks!
in 3d might be easier to use ScreenPointToRay or a plane, instead because of the prospective camera
Wouldn't ray also count the distance from the camera backwards as well as sideways/upwards?
How to make a character jump while animating?
a ray is nothing but an infinite line
jump while animating wdym ?
Seems to be drawing the ray twice as long as the actual distance
I'll give rays a shot and if that fails I'll go with the screenpoint thing
oh wait hol up
ops yea should be playerDirection.normalized * playerDirection.magnitude
Yes, for example I want to be able to jump while the running animation is running
!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.
yeah fixed that, the ray is correctly projecting towards the player, but even if there are no obstructions it never behaves like it should when it has LOS
https://gdl.space/jececoruru.cpp
This is the code
use animation events
So i can see the ray now, but the raycast always returns false
which one is the item supposed to hit
ray's supposed to come out from the sphere, be blocked by objects with the 'obstruction' layer, and if it hits the player without being blocked by said objects, does a thing
Unless I have things the wrong way round
it cannot hit player if player is not inside the layermask filter
but it should hit obstructions, if you put them in the Layer on the gameobject itself ofc
yeah that's what I've done, all I need is to return a boolean whether the player is obstructed or not
but at the moment it looks to always be saying it's obstructed, when it's not
can anyone tell me why i should not use null propagations on unity objects? i mean, they are way shorter then a if statement.
it might be hitting itself
Debug.Log the hit.collider.name
because unity overrides the null so in short it wont work
it deals with nulls in its own ways
shouldn't be, the sphere only has the default layer, none of the player's layers have that layer on it either
magic numbers as limits = index out of bounds
I do
if (myunitything)
{myunitything.DoThing()}
I think it has something to do with how unity does garbage collection on destroyed objects or something, basically less error prone
Hi i need help bcs I lack for logic.
I want to make pattern for an enemy with pattern switching randomly( think of a bullet hell) but I dont have any idea how to do that
wdym magic numbers
particile system or somethign
x = 1
i = 1 -> 4
what is 4 what is 8 ?
Unity has a custom == null that also works on objects that have been destroyed but not cleaned up yet. The null propogation does not actually account for this, so an object that is "Unity null" would fail an obj == null check, but would pass an obj?.method() check and throw an unassigned reference exception
8 is irrelevant its in a different section, it is the amount of audio sources though
Magic Numbers are numbers whose values you have to "just know" what they mean.
No its like attack, my enemy switch attack
im just explaining to you what they are, it was rhetorical question
still dont get it
If it's the amount of audio sources, why not just use the amount of audio sources as the variable instead of manually counting them and plugging in a number that becomes obsolete once you change the number of audio sources
How do you know 8 is the number of audio sources
beacuse i have 8
Okay but how do you know
exactly
So don't use magic numbers. If you want to use the count of a list, use list.Count
don't just do it by hand and type it in
its an array
so .length
will this create one instance of a material, and then have all of my renderers use that same material instance like i want it to?
the advice is still solide
So don't use magic numbers. If you want to use the length of an array, use array.Length
Yo guys, what does serialise field mean?
first time im seeing these weird crops 👏
just makes private field show up in the inspector
serializing = storing/saving stuff in an organized way
Whats the benfit of having it private over public
prevention of modification from outside of the class
encapsulation basically
guarding against yourself or collaborators from changing it in the future
flipped them around, my logic was just backwards X/
I often get confused as to whether that parameter is for blocking or accepting hits
Security over simplicity
Yes. Those are pretty bog standard loops now. You won't hit an out of bounds exception with i with these no matter what audiosource and music are. You might still get one on volSliders though, you could probably do with a check to see if x is greater than the length of that array too
its not i checked
not "security" in the traditional sense
ohhh so you were using Physics.Raycast bool wrong?
As long as you have it checked somewhere and are not just assuming it's correct, that's fine. It doesn't need to be in this method, it could be a check before calling this method
believe so. As simple as that sounds :/
ohhh that makes sense then lol
usually is
oh so its nothing
i think
Organization. On a big project you're going to have an order of thousands of potential variables at your disposal at any given moment. If you make private the things that shouldn't ever be changed outside this class, you can add a field variable (to use between functions in this class for example) without increasing the overall complexity of the system
i posted this in the c# server and have still got no response so ill post it here:
so i have a glitch where the player starts "twitching" when you walk beside a block or just on a block thats not a plane. ive tried a bunch of things and now im getting brain bleed. i have no idea why this is happening (plus ive got a automatic parkour movement without implementing it!). ill leave the code and a vid of me showcasing it down below. thanks in advance
// public's
public float speed;
public float jumpForce;
// private's
private Rigidbody rb;
private bool isJumping = false;
private bool isGrounded = true;
void Start()
{
transform.position = new Vector3(0,1,0);
rb = GetComponent<Rigidbody>();
}
void Update()
{
if (!isJumping && isGrounded)
{
if (Input.GetKeyDown(KeyCode.Space))
{
Jump();
}
else
{
Move();
}
}
}
private void Move()
{
Vector3 direction = Vector3.zero;
if (Input.GetKey(KeyCode.W))
{
direction += transform.forward;
}
if (Input.GetKey(KeyCode.S))
{
direction -= transform.forward;
}
if (Input.GetKey(KeyCode.D))
{
direction += transform.right;
}
if (Input.GetKey(KeyCode.A))
{
direction -= transform.right;
}
direction.Normalize();
if (Input.GetKey(KeyCode.LeftShift))
{
rb.velocity = direction * (speed * 2);
}
else
{
rb.velocity = direction * speed;
}
}
private void Jump()
{
if (isJumping == false)
{
isJumping = true;
rb.AddForce((Vector3.up+(rb.velocity/5)) * jumpForce, ForceMode.Impulse);
}
}
private void OnCollisionEnter(Collision collision)
{
if(isJumping == true)
{
isJumping= false;
}
}
private void OnCollisionExit(Collision collision)
{
isGrounded= false;
}
private void OnCollisionStay(Collision collision)
{
isGrounded= true;
}
@polar acorn whenevr i use any of the sliders the error comes up yet the code works exactly as i intended
What error
What is line 89 of Button.cs
I would like to direct your attention to exactly the thing I said would happen
x is out of bounds of the array
So check
i checked though, the script is attached only to those two sliders, in one, x=0, and the other x=1
And by "check" you mean "I looked at it and I assumed it was right" or "I explicitly put in an if condition that checks if this is correct so I know it has reached this place with valid values"
because the second one is what I said to do
and I have a feeling you're using it for the first
btw shouldn't it be < instead of <=
Ah, also that
what do you mean how can it be not 0 or 1 if i never defined it as something else
0 can still be out of bounds of an array with nothing in it
i is out of bounds, it should be < instead of <=
x is probably alright (but I'd rather just make separate fields for these two sliders)
i printed x infinitely and it said 0 or 1 aswell
Again, that's your fallible human brain, who knows if you've got a copy of this script with less vol sliders set?
While the loop condition is definitely wrong, this error is happening on x
How about, instead of going on a snipe hunt you just, you know, put in the if condition
Oh, didn't notice that
Print the value of x and the length of the array
both of the arrays?
since the error occurs on both lines
whenevr the loop is active
The only reason there wasn't an error on i is because it dies on the very first iteration of the loop
Once you've fixed the condition like navarone and caesar pointed out, i cannot be out of the bounds of audiosource or music. x, however, can be outside of the bounds of volSliders
Those crops man
Because nothing in your code is preventing you from passing in 4 or -12 or 525600, and nothing in your code is checking if volSlider has anything in it at all
i dont get it
what do u want me to do
if (x < volSlider.Length)
And maybe an else statement with a log that prints x and the length of volSlider so you can see what those numbers are when it goes awry
like so?
Sure, but putting it around the function call is probably fine, that way you don't need to add it twice to have it around both conditions
ran it, console only prints the error
the else statement isnt printing anything
can someone help me because my player movement script somehow got Wal climbing without me even needing to code it? like i stick to walls and stuff
and it lets the for loop run
Stop taking screenshots like that
You can just put the code here too
Like so
Where did you end up putting the if statement, and what line throws the error
You still didn't fix your for loop
< instead of <=
wdym you told me to change it to length
ok let me do that
No, they told you to use <
Multiple people, in fact
Length is fine, that's not the problem
please ive tried to fix it for a while now and its still not fixed
anyone please
be patient bro
send your code lets have a look
wait wtf did i write
also you have no provided code
- That only checks one condition
- your else has no braces so it will just always print
volSliders.Length
Wrap the call to freqVolume in the condition
here it might be messy:
// public's
public float speed;
public float jumpForce;
// private's
private Rigidbody rb;
private bool isJumping = false;
private bool isGrounded = true;
void Start()
{
transform.position = new Vector3(0,1,0);
rb = GetComponent<Rigidbody>();
}
void Update()
{
if (!isJumping && isGrounded)
{
if (Input.GetKeyDown(KeyCode.Space))
{
Jump();
}
else
{
Move();
}
}
}
private void Move()
{
Vector3 direction = Vector3.zero;
if (Input.GetKey(KeyCode.W))
{
direction += transform.forward;
}
if (Input.GetKey(KeyCode.S))
{
direction -= transform.forward;
}
if (Input.GetKey(KeyCode.D))
{
direction += transform.right;
}
if (Input.GetKey(KeyCode.A))
{
direction -= transform.right;
}
direction.Normalize();
if (Input.GetKey(KeyCode.LeftShift))
{
rb.velocity = direction * (speed * 2);
}
else
{
rb.velocity = direction * speed;
}
}
private void Jump()
{
if (isJumping == false)
{
isJumping = true;
rb.AddForce((Vector3.up+(rb.velocity/5)) * jumpForce, ForceMode.Impulse);
}
}
private void OnCollisionEnter(Collision collision)
{
if(isJumping == true)
{
isJumping= false;
}
}
private void OnCollisionExit(Collision collision)
{
isGrounded= false;
}
private void OnCollisionStay(Collision collision)
{
isGrounded= true;
}
i cant its called through a slider drag
so x is the value from the slider?
no
then where does the parameter come from
x is the int in freqvolume
basecly it stiks to wals and i dont know why
its either 1 or 0
ill send i vid
okay and where have you told the code that
what calls this function
please send a video of the issue as well
in the inspector i set x to 1 on slider1 and to 0 on slider2
onvaluechanged
Okay, I think I get what you're doing now. I didn't know what you meant because this is an absolutely terrible, convoluted system for implementing multiple sliders
Do you want to fix this one or do you want to do it correctly?
it took a while to upload but there
thanks
lets do it correctly
Make two functions. Both take a float parameter. One loops over audiosource and sets the volumes to that parameter. One loops over music and sets the volumes to that parameter. Call that function from the slider OnValueChanged. It will pass in the float from the slider and you no longer need to have an array of sliders
public List<Carrera> RandomRacesCreator()
{
print(dias.Count);
List<Dia> RandomDays = dias;
Shuffle(RandomDays);
float reductionPercentage = UnityEngine.Random.Range(0.3f, 0.5f);
// Calculate the number of elements to remove
int elementsToRemove = Mathf.FloorToInt(RandomDays.Count * reductionPercentage);
// Remove elements randomly
for (int i = 0; i < elementsToRemove; i++)
{
int randomIndex = UnityEngine.Random.Range(0, RandomDays.Count);
RandomDays.RemoveAt(randomIndex);
}
List<Carrera> carrerasa = new List<Carrera>();
foreach (Dia dia in RandomDays)
{
foreach (Carrera c in dia.Carreras)
{
carrerasa.Add(c);
}
}
return carrerasa;
}
Why is the script removing the variables form dias?
if i call this function various times it eliminates the Dia from dias and not form RandomDays
shuffle is a custom function that shuffles the list
RandomDays and dias are the same list
If you want a copy of dias, do List<Dia> RandomDays = new List<Dia>(dias);
oh
oh yeah the arrays were to save 1 line of code lmao
but if i have 2 functions and 2 sliders i dont even need the float do i
The float parameter is the value of the slider
i can just volume = slider.volume
You don't even need to reference the slider
Just use a parameter
ohhhh
the slider passes its value to the function
cant seem to see the issue
Yes. Although tbh you can probably just use a foreach instead of an indexed for loop
you know what ill just ignore it. try and find a better alternitive for my scripting
my "how to build a game like fortnite" course that i bought 5 years ago didnt include foreach
Then it was a dogshit course you shouldn't have spent money on when !learn exists
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
well whats done is done
anyway what did i do wrong cuz what i wrote doesnt reference in any way the slider volume amount
You can still do Unity Learn
The parameter
true
but no one told x to be equal to slider.volume
The OnValueChanged passes the value
ohhh
As long as you actually picked the dynamic function
my course didnt have sliders either
and not entered a value in the box
Show a screenshot of your slider's inspector
is your slider set to ints?
Use the dynamic function, not the one that has you enter in a value manually
what can i change to dynamic
When you pick the function
pick the one from the "dynamic" section
ohh
Do that on both
Now consider doing !learn to catch up on the things you missed
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
problem is im in the middle of a project so i think ill just newbie it then stop being stupid
but ill definetly get into it soon
cuz i definetly need it
thanks
Guys from this code I only want the enemy to track the x position of the player, how would I do this?
position.x?
u wont be able to use it in MoveTowards
make a new v3
Vector3 targetPos = transform.position;
targetPos.x = player.transform.position.x```
Thanks navarone but this would make the enemy teleport to the players x position, how about just slowing moving there?
Not a code question
And don't crosspost
it doesnt ?
did you not put that inside MoveTowards targetPos ?
Oh
Mbmb
Yo @rich adder you gonna make more yt vids?
Did it work?
And I usually make them when I can or feeling inspired, been very busy lately .
I'm working on a site though it will have many written tutorials
Yep
I feel like vid tutos would attract a bigger audience though
Especially younger
Unless you dont care about them kids lol
I just enjoy making videos, I kinda hate using a microphone xD
there are more youtubers with more oomf personality for videos haha
Loll i get ya
Hey all I'm really stuck on this muzzle effect:
the cone of light only goes backward
Looks like you're using a point light or your cone is manually placed incorrectly
Not much more I can discern off of such little info tho
how can I get it to show the outline of the cone?
By selecting your light gameObj
I have the muzzle effect selected
You need to select the light, the muzzle is different
how can I select the light?
i don't see it on the hierarchy
I just have MuzzleFlashEffect on the hierarchy
Select whichever gameObj is giving off the light and turn gizmos on...
sorry not sure what you mean by turn gizmos on
there is a light module for the particle system component
Ok select it
Can you see a cone in your scene view?
One that reflects how the light is showing?
Can I draw a ray (debug), using a Ray as input?
No that's not the right thing
Press on the gameObj in the light area
"ParticlesLight"
"ParticlesLight (Light)"
Ah this should work
Now send an ss of it selected and showing in the scene view
I don't know how to make it show in scene view
When you select it, it should be highlighted in your hierarchy
After selecting, press f to focus
it's not in the hierarchy though
So that's not the right object
Use the search bar and search for lights
And find which one is the muzzle flash light
nothing shows, the only light in my hierarchy is the directional light of the sun
but the ParticlesLight are definitely the cause of the backwards cone
flip it
Rotate it
Yup
ok so rotate the ParticlesLight
Yes, then you will know if that is really what's giving off the light
Wait what
No, rotate the particle effect
Rotating the particle effect has no effect
yea,, u need to sim it in local space no?
i think its only effecting the orange square part here:
that light in the back
on the player
is definitely ParticlesLight
because when I uncheck Lights on the effect it disappears
Show the inspector for it
inspector for ParticlesLight?
Yes
if ur rotating ur particle and nothing is noticeable.. it leads me to believe its simulating in world space
instead of local space
Show the one in the hierarchy
Evenin' all. I've got myself a couple of issues I can't seem to figure out with my enemy spawner.
Video to demonstrate the current working for context.
Wave Spawner code with a comment at the top explaining one issue.
Basically I have a wave spawner where I'm trying to keep track of the enemy count per 'wave' when the enemies 'hit' their position in the grid formation the count goes up by 1 (if they get destroyed, the count goes down) and at the end of the wave, if the enemy count is 0, then a power up will get dropped. Now the keeping track of how many enemies there are works fine.
https://pastebin.com/yYdFwh6j
This is how I'm keeping track of the enemy numbers.
The first issue is I can't figure out where to 'reset' the enemy count to 0 as the Waves 'overlap' each other in terms of spawn time, so if the next wave starts to spawn and the count gets reset to 0, if I shoot one of the previous waves enemies, the count goes into negative numbers.
The enemies are governed by a State Machine
Enemy Code.
https://pastebin.com/agAjHcn2
Apologies if that's a lot, but this is driving me up the wall.
And please excuse any random un-needed 'using's for some reason VS keeps randomly adding them.
So, basically, any ideas where I should put my reset to 0 line? 😕
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
No, select particleslight in your hierarchy
Press the box next to the search bar and search by component
the box to the right of the search bar?
Yes, that's what I just said
it sounds like you need an array/list of enemyCounters, one per wave, OR each enemy needs to know which wave it is a part of, and the state machine would need to know which wave the current wave is (so that it only decrements the counter when the enemy's wave number matches the current wave number).
You meant the prefab is what you have in your scene 🤦♂️
Unpack it and mess around with the values
Or don't un pack it
Up to you
do you actually need to know the count, or do you just want to spawn a powerup ever n'th kill?
Also press e and rotate the gameObj
I need to know the count. Idea is if the player destroys every ship in a wave, a power up drops.
rotate the prefab, ParticlesLight?
Yes, you don't have to ask for permission for everything
rotating the prefab has no effect
it's not in the scene
🤦♂️
Ofc rotating a prefab is gonna have no effect if it's not in your scene
right
that sounds like you'l need a list of enemyCounters... one for each wave. Assuming: you destory all of wave 1, after wave 2 has started. The enemies will still need to know which wave they are a part of, so it can decrement the appropriate counter in the list
Right okay. I'll give that a go tomorrow, brain is a bit cabbaged for tonight. lol.
Thank you 🙂
i believe the muzzleflasheffect is what's giving off the light. rotating it has no effect
Best notification I got today AAAAAAA
Hello, does someone know why accessing Image.material doesn't create an instance of it?
renderQueue = image.material.renderQueue;
Accessing TMP_Text's fontMaterial does though
renderQueue = text.fontMaterial.renderQueue;
hallelujah 🙏
From one problem into the next one tho 
when u access the material ur accessing the property of the shared material, when u access the text ur accessing the material instance specicially for the text component.
u probably need to create a copy of the image material and queue that
how can i check if an animator has a trigger?
Oh, I haven't noticed there is no sharedMaterial on the image
how can i check if an animator has a trigger?
like if(animator.TriggerExists("Shoot"))
ya, not sure exactly how it works on image.. but maybe try making the copy of it instead
just an idea
That's a great idea, appreciate your help
i know when i want to change the material of a renderer i have to do the same..
create a copy.. modify the copy.. assign it back to the renderer
var params = animator.parameters;
foreach (var param in params)
{
if (param.type == AnimatorControllerParameterType.Trigger && param.name == triggerName)
{
return true;
}
}```
My ray is doing this, but still logs Hover regardless of where I am aiming, but only when I am clicking the mouse button?
(The Function Hover just Logs Hover!)
Anybody got an idea why?

ive never used the exact syntax or hunted for triggers i didnt know where there
soo. you can test for me 😆
no.. it shouldn't be logging only when you're clicking the mouse button
Yeah that's weird
its in fixedupdate.. w/o being in any kind of input conditional
unless u have multiple scripts running.. and (1) is
I have this, but I don't use mousePos anywhere
then why u have this?
Before I did the LookAt - POV, I did the MaincameraToScreenPoint. But that didn't work, so I tried it without using an input action (potentially wrong)
I am very confused bcs it doesn't seem logical for once
👍 ur very welcome
may not be the most performant to search thru all the params of the animator tho
i'll prob end up having a bool
cool, just letting u know in case u get performance issues later down the road
you'll know what to look for
is there a decent way of rendering 3D models onto a canvas? or if not possible whats the next best workaround
as long as it doesnt have 100s of params u should be fine
i only have 3
does it have to be on the canvas or can it just be behind hte canvas?
u could have the camera w/ the canvas render just the model
w/ the UI on top (or around it)
its gonna show the active tool so im not sure
if you wnat it to be part of the canvas like a 2D image.. you can use a 2nd Camera.. and a RenderTexture
ur Image component would hold the render texture.. and it would be rendering w/e the camera is showing..
ie: focused on ur 3d model
i see
Any ideas? 🥲
📃 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.
Good evening, im struggling with a code where my code works, half of the time. So basicly my code consists of:
public bool hit;
Vector2 movement = new Vector2(horizontal * moveSpeed, rb.velocity.y);
hit = Input.GetMouseButton(0);
if (hit);
{
terrainGenerator.RemoveTile(mousePos.x, mousePos.y);
}
anim.SetBool("hit", hit);
and it will not allow me to break all the blocks on the map. Blocks are being placed like:
public void PlaceTile(Sprite tileSprite, float x, float y, bool backgroundElement)
{
GameObject newTile = new GameObject();
newTile.transform.parent = this.transform;
newTile.AddComponent<SpriteRenderer>();
newTile.GetComponent<SpriteRenderer>().sprite = tileSprite;
newTile.name = tileSprite.name;
newTile.transform.position = new Vector2(x + 0.5f, y + 0.5f);
worldTiles.Add(newTile.transform.position - (Vector3.one * 0.5f));
worldTileObjects.Add(newTile);
}
and are abled to be deleted by:
public void RemoveTile(int x, int y)
{
if (worldTiles.Contains(new Vector2Int(x, y)))
{
Destroy(worldTileObjects[worldTiles.IndexOf(new Vector2(x, y))]);
}
}
and for some reason i dont understand why it will allow me to break some of the blocks on the map, but it wont allow me to break all of them. This is totally random so idk whats going on. If anyone could help me?
@leaden lotus and @hot palm
#💻┃code-beginner message
ok thats cool
public void Hover(Object whatCalledMe)
{
Debug.LogWarning($"Hover! {whatCalledMe}");
}```
private void FixedUpdate()
{
Vector3 raycastDirection = (_LookAt.position - _POV.position).normalized;
RaycastHit hit;
Ray ray = new(_POV.position, raycastDirection * interactRange);
if (Physics.Raycast(ray, out hit, interactRange, LayerMask.GetMask("Interactable")))
{
if (hit.collider != null)
{
if (hit.collider.gameObject.CompareTag("Interactable"))
{
hit.collider.gameObject.GetComponent<InteractableObject>().Hover();
}
}
}
Debug.DrawRay(_POV.position, raycastDirection * interactRange, Color.red, 1.0f / 60.0f);
}
I'll try that
can u change ur debug to include this? then in ur Hover() method.. u can
hit.collider.gameObject.GetComponent<InteractableObject>().Hover(this);
u can see what script is calling it.. if it is indeed ur only script it would be obv but im not sure..
Yes Ill try
is there an interactable object blocking the raycast?
idk why it would be being called all the time
especially when ur pressing left click..
No for testing I tagged evrything as untagged an only the object as interactable
Hi, how can i save this in PlayerPrefs?
ud just need to save the musicSource.mute bool
Okay interestingly I get no logs now
and when u read from it.. do the function
ah I know whay
👀
forgot to updte this
ohhh u have events going too?
did u add this part?
yea.. weird
it should show u the script/object that ran that function
I can assume my code is not working, but me left clicking starts this event somehow
but its saying null
ahh yea.. the event part i wasnt even aware of
thats probably linked to ur mouse click
alright.. u can change it back how u had it.. that didn't reveal any use-ful information as i thought it would
Well I now know that event stuff isnt really working perfectly
and the SetActive?
ya, silver lining i guess
no, ud just do that after u read the bool..
like when ur loading
-> set it[yourgameobjectsyouneedactive] active or inactive.. to match```
playerprefs should contain simple data..
1s and 0s
strings and such
all u need to know is if it is muted..
and then if it is.. ur loading logic would handle what changes in the game
PlayerPrefs.SetInt("Music", 0);
bool music = PlayerPrefs.GetInt("Music") == 0 ? false : true;
Like this
thanks this worked a charm
private void Interact(InputAction.CallbackContext context)
{
interactEvent.Invoke();
}
I did this for the function, so ofc no script called it... 
Hi folks! Can somebody advise me on how to fix my script for successfully printing my player name? My current script is:
public static string playerNameInput;
public void ReadPlayerName(string playerNameString)
{
playerNameInput = playerNameString;
Debug.Log("Player name = " + playerNameString);
}
I believe the issue comes from the section circled in red on my screenshot. There shouldn't be a field to type something, right?
Thank you!
Turns out why it was loggin this, now I just need to find out how to get the raycast thin working
i think you're gonna need someone more advanced than me to figure out that issue, sorry 😦
ya, i would just retry
do it something simple..
i tend to isolate things until i get them working/fully understand them
Yeah
may help you too.. to maybe make a new scene w/ nothing in it..
and just work on that 1 script.. maybe a simple cube or 2
only this or? sorry i´m beginner
No you would safe it, whenever you change it
So OnMusic has the PlayerPrefs.SetInt("Music", 1); (1 is for true)
and OffMusic has PlayerPrefs.SetInt("Music", 0);
// Read your data
bool isMuted = PlayerPrefs.GetInt(MuteKey, 0) == 1;
// Now apply your data to the game world
musicOn.SetActive(!isMuted);
musicOff.SetActive(isMuted);```
Then this
bool musicOn;
private void OnEnable()
{
bool musicOn = PlayerPrefs.GetInt("Music") == 0 ? false : true;
}
you wouldn't need musicOff, as musicOn being false means the music is off
yup. just 1 bool..
isMusicOn and isMusicOff is the same property
altho i know why u have 2 gameobjects..
1 for like a Microphone.. and 1 for a Microphone with a slash thru it
but u dont need that extra stuff for the playerpref key
just do that in ur logic after u read the key
I have 2. One static instance one the player and the other one on any object that is interactable. I use the event to apply the script to the interactible to have variable stuff that happen when I interact
same for like levels.. if ur on level 2..u just read that 1 value.. and then ur gamemanager or w/e would set up everything else.. that level2 needs
sounds a bit overly complicated imo
i know this is just an example, but the person the example is actually for clearly just copies code blindly so you should probably fix that issue where the GetInt call is assigning to a local variable entirely unrelated to the musicOn field
how beginner are you?
2 years into unity
i dont know, I do not understand PlayerPrefs :/
Know nothing of netcode but a bit about stuff going on.
ahh okay.. about the same as me.. have you never worked with raycasts before?
Not really that's the problem I am at right now
I have problems with detecting collision with raycasts
All the stuff I tried didnt work
oh yea, me neither.. im 3 years into Unity.. i know my way around raycasts for sure.. but i havent touched netcode yet
Can I call OnTriggerStay on the script doing a raycast and make the interactable a trigger?
Do I put OnTriggerStay on the intersecting object or the one with the trigger collider?
why use triggers event if ur using raycasts
// Check if the left mouse button is pressed
if (Input.GetMouseButtonDown(0))
{
// Perform a raycast from the raycastStart position in the forward direction
RaycastHit hit; // Store information about the object hit
if (Physics.Raycast(raycastStart.position, raycastStart.forward, out hit, distance, shootableLayer))
{
// Log the name of the object hit
Debug.Log("We hit: " + hit.transform.name);
// we also have the *hit* variable we can check against for components / tags
}
}```
heres my basic raycast script that i recycle..
pretty basic.. and has everything ud need as a beginner.. uses a layermask... and has an out variable
Yeah but that doesn't work somehow
What I want to do is
Have the object know when I could interact with it and the object listens to my input and does the event when specified input is done.
what is MuteKey?
string muteKey = "Music";
In this case
like this?
private const string MuteKey = "IsMusicMuted";``` i actually used a cosntant in my example code
but same thing..
Just so you use variables and it always works when changing the variable name
Yeah this is smart
private void FixedUpdate()
{
Vector3 raycastDirection = (_LookAt.position - _POV.position).normalized;
RaycastHit hit;
Ray ray = new(_POV.position, raycastDirection * interactRange);
if (Physics.Raycast(ray, out hit, interactRange, LayerMask.GetMask("Interactable")))
{
if (hit.collider != null)
{
if (hit.collider.gameObject.CompareTag("Interactable"))
{
hit.collider.gameObject.GetComponent<InteractableObject>().Hover(this);
}
}
}
Debug.DrawRay(_POV.position, raycastDirection * interactRange, Color.red, 1.0f / 60.0f);
}
This should work, no?
Oh good to know
they are infinite line from 1 point toward direction
I know is bad but i don't know what do next or :///
!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.
wrong you don't store local variable
youdo have interactRange as part of the raycast, though, so it should work out
Put the GetInt line in the enable function like this
private void OnEnable()
{
bool musicOn = PlayerPrefs.GetInt(MuteKey) == 0 ? false : true;
}
Because it will ask for the value you want, when you start it
that's assigning to a local variable whose scope is entirely within that method
Also you do this
private const string MuteKey = "IsMusicMuted";
Above outside the function
Hey Guys, Can anyone have help to why the transform position of 2 prefabs is the same, but their position in the scene is different? Thanks (:
this sounds like not a code question. and by the vague wording of this, i'd assume you are actually referring to the tool handle position. make sure your tool handle is set to pivot rather than center
what I got lost 
The transform origin of a child is its parent. So if you have a parent and a child, the child has to be 0, 0, 0 to be on the same position
Just a sec
Im sorry to be slow, but how do i change that?
private AudioSource musicSource;
private const string MuteKey = "MuteMusic";
private bool isMuted = false;
private void Start()
{
isMuted = PlayerPrefs.GetInt(MuteKey) != 0;
musicSource.mute = isMuted;
}
private void ToggleMusic(bool value)
{
musicSource.mute = !value; // Calling this function with true will mute the music
int num = value ? 0 : 1; // Int is 0 when not muted, 1 when muted
PlayerPrefs.SetInt(MuteKey, num);
}
sorry i dont know the terminology quite yet, thanks for the help
Is it (bool) ? when true : when false; or the other way around?
condition ? true : false
Okay
PlayerPrefs.GetInt(MuteKey) == 0 ? false : true;
can just be PlayerPrefs.GetInt(MuteKey) != 0;
also what's the point in storing that in a field if you are just not going to use that field ever
if ? then : else
Looking this up is difficult xD
It's called a "Ternary Operator"
that'll help you find it online
ohh thx
private void FixedUpdate()
{
Vector3 raycastDirection = (_LookAt.position - _POV.position).normalized;
RaycastHit hit;
if (Physics.Raycast(_POV.position, raycastDirection, out hit, interactRange, LayerMask.GetMask("Interactable"))
{
if (hit.collider != null)
{
if (hit.collider.gameObject.CompareTag("Interactable"))
{
hit.collider.gameObject.GetComponent<InteractableObject>().Hover(this);
}
}
}
Debug.DrawRay(_POV.position, raycastDirection * interactRange, Color.red, 1.0f / 60.0f);
}
Changed it a bit still doesn't work
Lemme trouble shoot
can i get iframe to add my unity webgl game to my website
just copy whatever code unity gives you inside the index.html
i dont think that will work
ofc it works
i need an iframe. iframe is a little box you can play it in.
copying all the code will just mess the entire thing up
ok, i know what an iframe is
told you
when I pressed yes it didnt work.
i am gonna scavenge the code for an i frame
you also don't need an iframe. you just need to embed the game onto the page literally the same way that the index.html file does for the built game
private bool isMuted = false;
private void Start()
{
isMuted = PlayerPrefs.GetInt(MuteKey) != 0;
musicSource.mute = isMuted;
}
private void ToggleMusic(bool value)
{
musicSource.mute = !value; // Calling this function with true will mute the music
int num = value ? 0 : 1; // Int is 0 when not muted, 1 when muted
PlayerPrefs.SetInt(MuteKey, num);
}
public void OnMusic()
{
musicSource.mute = false;
PlayerPrefs.SetInt("MuteMusic", 0);
bool music = PlayerPrefs.GetInt("MuteMusic") == 0 ? false : true;
bool isMuted = PlayerPrefs.GetInt(MuteKey, 0) == 1;
musicOff.SetActive(isMuted);
//musicOn.SetActive(true);
//musicOff.SetActive(false);
}
public void OffMusic()
{
musicSource.mute = true;
musicOn.SetActive(!isMuted);
//musicOn.SetActive(false);
//musicOff.SetActive(true);
}```
like this?
You can delete Off and On music
I don't know what you want to achieve with
//musicOn.SetActive(true);
//musicOff.SetActive(false);
but you can add it if you need it
Didnt see the original issue but how come you set and try to read it instantly?
Now just call ToggleMusic(false) somwhere to mute it
because they have copied code from multiple different examples blindly without actually understanding any of what is happening
We should probably check it, true.
if (PlayerPrefs.GetInt(MuteKey) != null)
{
isMuted = PlayerPrefs.GetInt(MuteKey) != 0;
musicSource.mute = isMuted;
}```
this?
How di I check for it existing?
and that is also entirely unrelated to what bawsi was asking
Thought he meant reading it instantly = in start
Yes
int?
/jk 😛
no, it was set on one line then get on the next several lines
Well OnMusic and OffMusic are italian food at this point (Spaghetti), so they can go
You should probably rename ToggleMusic to MuteMusic for better readability
(Mark it, press F2 and rename it there, press enter) That changes the name everywhere
Sorry for messing stuff up. I'm working on a game jam simultaneously and I really need to get stuff done haah
i'm sorry to bother you
Last thing I realize it you should change it to
musicSource.Mute = value;
if you rename it to mute music, aswell as swap the line to
int num = value ? 1 : 0;
can i tell you what i need to do?
You can always ask. In the case I don't answer some one else will surely
to remain mute
MuteLogo.SetActive(value);
NotMuteLogo.SetActive(!value);
It should, if it's not staying the same and you followed everything you will need someone who understands playerprefs. I don't like using them. I rather use actual data saving like json
okay thank you
where should I put it?
How tf does the object change transform
private void FixedUpdate()
{
Vector3 raycastDirection = (_LookAt.position - _POV.position).normalized;
RaycastHit hit;
if (Physics.Raycast(_POV.position, raycastDirection, out hit, interactRange /*, LayerMask.GetMask("Interactable"*/))
{
if (hit.collider != null)
{
Debug.LogWarning("Intersecting Raycast object " +hit.collider.gameObject.name + " at " + hit.collider.gameObject.transform.position + "!");
if (hit.collider.gameObject.CompareTag("Interactable"))
{
hit.collider.gameObject.GetComponent<InteractableObject>().Hover(this);
}
}
}
//Debug.DrawLine(_POV.position, _LookAt.position, Color.red, 1.0f / 60.0f);
Debug.DrawRay(_POV.position, raycastDirection * interactRange);
}
it looks like your raycast is hitting the cube object on the player
oh my
you are completely right
face palm moment
Sometimes we don't see the things directly in front of our eyes

I had removed the capsule collider but not the box
why did you remove any colliders? you should be using a layermask with your raycast to ensure it only detects colliders you want it to
I usually have that, but as you see I commented it out for troubleshooting
Also I remove all colliders from my visual stuff, as I don't need them messing with the controller
Is there a simple way to debug something every second instead of every frame?
You'll have to make a timer
I see
alternative would be an IEnumerator with wait for seconds and then calling stopcoroutine at some point, would that work?
Alternatively, you could use the Invoke call and set it to 1 second to call a debug function
And if a condition is true recursively call it huh?
Yes that would work if there was a need to stop it
Yeah I kow of them, but I read those shouldn't be used
Well you're just debugging, it doesnt matter if you use them
This is for debugging, so you can be as messy as you want.
It's just unnecessary if you've organized your code correctly
I guess coroutines do everything you would need so no need for invoking?
Btw I'm trimmed to used private functions and parameters as often as possible, why's that? Hacking/Cheating?
You can't prevent hacking or cheating by making things private
It's purely for code organization, and preventing accidental changes by the developers.
This really only matters when things get large or with multiple developers working together.
I see, good to know. Thanks for the information
What is the syntax for the 'i' at the end of Coin? I have pickups that are called Coin1, Coin2, etc.
I vaguely remember it looking something like $"Coin"[i] as well but it's still not right.
$"{Coin[i]}"
why would coin ever have [] in its name
I think
still wrong
this will print the object
Oh mb didn't understand what was asked
I really should focus on one thing at a time
My compare tag seems broken
Hello everyone. In Unity, my particle effect covers my item as I want, but when running on Android, my particle effect does not cover my item. What could be the reason for this? Does anyone have information?
also basing your logic on gameobject names is a bad idea. check for a tag or component, not the object's name
Thank you I didn't know what this was called.
I thought about checking by tag, but the object is not in the scene yet. I thought I could only look for objects by tag if they are in the scene.
It almost works. I get a reference to the Interactable GameObject. It just doesn't seem to accept the tag.
i didn't mean use FindGameObjectWithTag or whatever
i just meant to not base your logic on the name of an object. like when you collide with an object or whatever don't check its name, check its tag or for a specific component
This is how I get target
print some useful information rather than useless numbers. you can print what was hit and its tag
Well I do that, but only once for every new object
I know I hit the cube
And the 1 runs
just the 2 not
meaning something is wrong with _Target.CompareTag
because you've hit something that you are not expecting to have hit
nothing is wrong with CompareTag
because that was the object that was hit by the raycast
It is checking cube tag, not the object the collider is on
The collider is on the Interactable object
Cube also has a collider
👀
Makes ense why I get a nullpointer
Gosh I hate it
It's the simple small things
thx for enduring my stupidity @slender nymph 💌
what is that function which can be used to detect collisions for non-trigger colliders
does it run as soon as the collider is touched
OnCollisionEnter?
yeah thanks
There is also OnCollisionStay which is called every frame they intersect, not just once
thanks
Any idea the best way to make a simple 2D destruction
in terms of visuals
of a rectangle
particle system I guess
Dani said it's good
xD
Or shader stuff. I'm not into shaders tho
yet
thanks ill try it
What happens to Debug stuff when leaving it in a build?
Depends on what log level/behaviour you set in your build settings
Yo guys, the sprite of a character is moving in my game but I want the sprite of the character to flip when it moves in the other direction, how would I do this?
Check it's velocity and flip the sprite renderer y
Is there an operator for if (x == a or b or c) then do this. Instead of having to write if (x == a || x == b || x == c)
Set the scale to a negative value
When what occurs?
A is B or C or D
Bottom right you see the toggle for flip y, just access it through script
Cool thanks
You can check in which direction it walks by looking at the x velocity (when you have an rb2D) or just have 2 variables get the last and the current position and check which one is smaller
what does the operator look like?
Can i also check if its vector is negative or positive?
Well it's entirely up to you, depending on how you implemented moving
Literally that
LOL did not occur to me that "is" would be the actual one. Thanks!
if (a is 1 or 2 or 15) {}, more here https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/patterns
Wait tillydally the hit box wont flip if I flip the sprite
Any work aroud?
Oh, then you have to make one parent game object for both and either set x scale to -x scale or rotate around the y axis by 180
Idk if this is code-based, but everytime I move my cursor in the editor, I get nullreferenceexceptions. Also this text blends in and out of existence, whenever I hover Debug Inspector?
Damn and i though your the one who knew everything lol
Haha no no. I just learned by doing for 2 years. More complicated stuff will often exist
What's in the callstack of the error?
What do you mean? This are the errors
Click the error and take a screenshot of it's details
That's the callstack
Okay
Why is unity screaming at me while throwing glass and food??
Seems like a random unity ui bug related to the inspector. Does that happen if you disable debug inspector?
I know it but try to figure it out yourself first
No
Can't set a component of a position like that
But it's not workign as intended
What's not working as intended?
Do you know any workaround?
Does a canvas block raycasts?
Make a whole vector 3 and set position to it
No. Raycasts are only blocked by colliders.
It should display text now, which it doesn't (it sometimes does)
Or multiply position by a vector with only x, times a float for the magnitude. Like Vector3.right
well Physics ones 😅
there is Graphic raycaster which uses rect transforms or something
How is that related to the error issue?
It may be a mimic careful
I dp use a Physics.Raycast
oh thx thx xD
Yeah, but you can't cast ui raycasts afaik🤔
You cannot both get and set an individual component of a vector in the same line. You will need to either assign the entire position at once, or store the position a variable, modify it, then set it back
When I tried troubleshooting that happened.
But dont need help for the X problem rn
Thank you man
Ah, ok. Well, it's unrelated to the raycast. It's just something wrong with your inspector ui.
Ahh I see
If you apply the Physics Raycaster it uses the Event System raycast to do IPointerHandler events on colliders
Yes, but you can't cast them manually. I guess I assumed too much though. They could have been talking about the ui events.
yea myb i just kinda butted in with no context lol
Basically if UI in world space can interfere with collision and raycast
it should not
bcs I expierenced some weird UI behaviour regarding raycast before
Not in 3d tho
I think it was something like text making a slider area bigger or smth
You can debug it really easy. Just print what your raycast hits
If it does hit the UI somehow, you will see it.
true
are you trying to hit a WorldSpace UI with FPS controller?
No I want to evade that
I want to display world space UI when looking at a collider up to a max distance, but it jitters kinda
let me ask you more after troubleshooting this
Well it's important for static instances and referencing them in the start method
they're very different methods
Share a video of the issue
Start just runs after awake. Generally you want to use them for different purposes. Neither is "better"
its important for many reasons you would use a Constructor in a regular class
so like initializations
Start is better for Using the values from references like you said
also Start can be disabled via script checkbox, Awake cannot etc.
(Awake always runs on disabled scripts not disabled objects though)
wait it cant??
Damn
nah unity runs awake when the instance is created
only game object starting disabled would prevent that
these methods * can be disabled from running ( i mean the checkmark in inspector myb)
Actually, pretty sure awake is also affected by active/enabled state
https://docs.unity3d.com/ScriptReference/MonoBehaviour.Awake.html
of the GameObject active state, not script .enabled
private void Awake()
{
Debug.Log("Awake Ran");
}
void Start()
{
Debug.Log("Start Ran");
}```
Oh, I see.
The first paragraph in the docs was a bit confusing as it mentioned "enabled" components.
I guess it was me who had false memories after all.😅
Unity calls Awake when an enabled script instance is being loaded.
ah yeah tha is confusing, I always assumed that to be like a traditional constructor
I mean he proved his point with the gif
when unity has a gameobject as active its running its own new()
which runs awake basically
I see. That makes sense.
why's that?
only called through a domain reload
oh cause its like an Asset being created not a runtime thing
yeah, it's silly
I guess the whole AssetDatabase needs to update too
So better off using OnValidate() or ISerialization interface, otherwise grab all scriptable objects and implement your own Awake
no wondering i see OnValidate more often in SOs 😅
So uhhh any alternatives?
You could use that to register an so with some static manager or something.
distance.x = distance.x * -1
right, usually the better idea. Also similar idea for plain c# objects
quick question for documentation reasons, is there a point of oncollisionenter on a trigger collider
What does the first error say if you hover over it?
There is no definition for scale and no extension called scale
Because you might want to distinguish wether it is colliding with a collider or a trigger.
okay thanks
yes because there is no such property
Ah, there's local scale only it seems.
https://docs.unity3d.com/ScriptReference/Transform-localScale.html
https://docs.unity3d.com/ScriptReference/Transform.html
So how can i "transform" the scale (get it)
always check the docs/api when something doesn't quite line up
shouldn't your IDE have that in the suggestion box somewhere :p
Theres a problem bc I cant change the scale of the current gameobject the script is on
Why not?
Yh it did but i was hoping you guys could explain it bc I didnt understant
Soz
Local scale is only for the parents right?
I may have read wrong
No
Ima try anyway
It's what you see in the inspector, it's scale relative to the parent.
local always means the child object and yeah like dlich said relative to parent
if the child has no parent, then local is just world
OOHHHH
Cool cool
Im learning
Thank you thank you
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
I remember someone said with a video that I could also use a camera follow that doesn't just fully focused on the player like you can go to the egde a bit, but I don't remember where
cinemachine . . .
which one? there's many
https://docs.unity3d.com/Packages/com.unity.cinemachine@3.0/manual/CinemachineTargetGroup.html?q=target group
if you want both objects being kept in the frame
it's a package you import for the camera . . .
I said "which one", because's there many different cinemachines
huh? it's a single package . . .
@hushed hinge you can search or
where the package manager is or how to import cinemachine. i'd look for a tutorial . . .
what can I use instead of a while loop here?
what are you trying to achieve?
text to appear and disappear every half a second, until the player has either ran out of time or the level has ended
but i havent implemented a level ending yet so just until they run out of time for nnow
what currently happens when you run the game?
it flashes but really glitchy
definitely nnot half a second
oh wait
i know what happened
its in update 😭
there you go. nice talking with you, haha . . .