#π»βcode-beginner
1 messages Β· Page 63 of 1
wat
your rigidbody is following a trajectory
store the vector3 direction and then run it thru reflect on collision
i wish I knew how lol
ballrb.velocity = Vector2.right * ballSpeed;
you have this in your code
yup
you're fixed in one spot direction , which is hard to change and not useful.
So you ideally want to store your direction inside a variable you can change
ok
then you reflect that and change that one
I understand how it works, there is this mechanism in game development on Roblox
this is where u lose me
have you shined a light in a mirror before ?
yea
you're trying to do the same thing but with the ball, the Reflect function lets you do that if you pass your incoming velocity
aka direction
alr
i still dont know how i should change my code
when i look at code i read what it says and assume it does what it says which is why i have lots of logic errors
so until i know how to use it i cant learn it
guessing your way through it isn't a good way to learn
its not like that
I read a lot of weird comments in your code which looks to be half AI generated
i wrote this by myself lmao
oh well it might as well have been
u can cross check if its ai if that is even possible but its not ai
ok do you know how to store something inside a variable yes ?
yea
so start by storing ball direction into one
as a string?
why would it be a string, does rigidbody.velocity take in a string ?
yes you do know if you think for a moment
number
hover over velocity with your mouse in visual studio
so number?
a description doesn't mean the type it wants.
What is velocity is real life?
when you look at
speed
this is Input it wants
always read that part of a variable it tells you
got it
ok there ya go
when i create the variable the name is grey
the editor tells you why
you should go through some courses
start with pins in this channel
where else would you use it ? what have you been talking about this whole time
the direction the ball is going
so why ask such a silly thing
i meant how
Have you taken any directed course (and I don't mean youtube)?
I feel like you would benefit from a c# course
https://www.w3schools.com/cs/index.php
followed by unity's pathways (!learn)
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
i did the brackeys one
Yeah, I personally thing Brackeys is one of the worst, and teaches a lot of bad habits, but either way I said not from youtube
the brackys c# ones arent good
oh
its all small concepts of basics put together
should i even be starting with unity or just the console
both work, up to you
this one mixes both Unity specific and C# decenly
https://learn.unity.com/project/beginner-gameplay-scripting
Unity is just an API built to use (an old verion of) c#
Either is fine
console runs faster than waiting for script compilation times and such
unity is PAINFULLY slow
even with domain reloading off
but it makes sense when you change 1 script its updating entire UnityEngine assembly and whatever else
so i guess assembly definitions help a lot with that
start with just c# and console applications. Hell you could even get away with an online compiler, the only downside is you wont be able to do file stuff (since they'll restrict it)
how long does new unity compiles in betterish pc's?
better than 5 mins?
depends entirely on how much is in your project, on my current newish project like a few seconds
feels like its gotten slower if anything
if im just using vscode to code a game what should i aim for
anything, just dont overscope like me
you can make console apps in any IDE, even online as mentioned
Shouldn't be relevant at all which ide you use
One of my friends has the same issue on a good pc unity 2022, on the same project as me, while mine takes like 5 seconds. Maybe theres some setting, idk what causes it
5 mins vs 5 sec on same project?
their whole pc is better than mine pretty sure
yea same project, we are working together
yeah my 2014 macbook somehow opens projects faster than my new gaming desktop π€·ββοΈ
i dont even really mind opening times, the compilation is more important
its the same with compiling for me
my shitty laptop somehow compiles it faster
could be that macos is more efficient than windows tho
πͺ π
if any of you finds anything more about it, id love to know what causes or fixes it. to pass onto my friend or just incase it happens to me in the future
I cant even think of any reason how a better pc perform worse than yours
my vs code is bugging
dont think ive seen a setting for any relevant
nothing is auto filling and i cant do anything for the console
use VS instead of VSCode
ok
also you need to do it through the CLI in vscode
huh
CLI = Command Line Interface
dotnet new console
if you have C# Devkit it should load the Solution Explorer
What is it even supposed to autofil? There isn't a language extension
i put c#
i selected it
that wont work
oh
configure ide if you want autocompletion
u said use vs tho
no wonder your font screenshot was weird lol did you have a Visual Studio skin on VScode
yes Indeed
wat
Console.WriteLine does not write to unity's console
!cs
Join the C# Discord server, a programming server aimed at coders discussing everything related to C# (CSharp) and .NET. https://discord.com/invite/csharp
yea
Or print, but that doesn't enjoy the second parameter of Debug.Log
Edit: @queen adder ?
print only works in MB iirc
Yep
it's just a lazy method, since it's shorter to write
I sent you the guide
yep, it's an instance method on MonoBehaviour. it also just calls Debug.Log anyway
That is an absurd response....
had a bad habit of using it everywhere , because it shorter to wrie π
haha funny and I just wrote this
one of those cases where short != better
im not tryna use unity
im tryna use just vscode and do some simple c# console stuff
Definitely not better always, but not worse either. It just is a thing...
yea had to stop using it at one point when i had to refactor a lot of things that had it, since I had to turn it into a normal class
it installs both extensions you need
Unity extension install C#Devkit
its just bugging
done a while ago
so did you create new console app like i said ?
wat
in terminal
now that i think of it, i could have just added the method in that case lol
wat
yea js did it
forgot that was the first step lmao
what i do after
open program.cs it Should open solution explorer if you did everything correct
This is beyond the scope of a unity server
#π»βcode-beginner message
Or just check out on of the many guides on google
where i find program.cs
here the instructions mate
this indeed is a unity help channel
https://learn.microsoft.com/en-us/dotnet/core/tutorials/with-visual-studio-code?pivots=dotnet-7-0
There are also C# focused servers if your not working in Unity, I believe one was linked earlier that may be worth joining
Yeah, I just linked back to it here
#π»βcode-beginner message
unity uses C# right?
Yes
thought so
https://gdl.space/sezigehumo.cs
Did i call this method wrong or something
https://gdl.space/liteliyiti.cpp
I am trying to get it to add 10 to the money but it seems to be adding a lot more as if its adding 10 then multiplying The multiplier will eventually become a different number but I ave tried a few different ways but I cant seem to get it to work
im new to c# I guess failure is the best way to learn
So, again, this is c# stuff, not unity. So you should ask in the c# server.
#π»βcode-beginner message
But I don't actually see you create a Wizard or call CastSpell anywhere
money += money means doubling your money
right but I cant seem to get it to just add 10 I have tried money += multiplier but it stops at 10 and wont increase
I dont realy get Quaternions... Is there a direct way to just rotate an existing quaternion by a certain degree around a certain axis without having to take the whole thing apart and building a new one?
should I make my UI a prefab? or save it as a scene? how do I make this modular?
which variable contains 10 ?
Yes you should make it a prefab. Maybe save it in a scene you load additively
Make it modular by loading and unloading smaller more modular prefabs
Ive just realised I set the money to 10 not the multiplier π€¦ββοΈ
Any reason not to just use https://docs.unity3d.com/ScriptReference/Transform.Rotate.html?
I see.. thanks :D
fixed it. was such a simple problem imma start seperating variable more
I don't have a gameObject i want to rotate. I need a rotation for an OverlapBox (which takes a Quaternion for its rotation) and want the box to have a certain difference in orientation from a specific gameObject
Right. Then you should create a quaternion using Quaternion.AngleAxis, and multiply it with another quaternion to rotate it around that axis
https://unity.huh.how/info/quaternions/multiplication if it helps any
Thanks! Thats probably it and i was almost there π I'll see if the result realy is what i wanted
i did call cast spell but it didnt work so i deleted it
Did you create a wizard to call CastSpell ON?
Same as with Unity, you need an instance
Alr
which course are you following ? seem to be missing the basics already
Iβm testing what I know before I take the course
How I do that
This is not a unity issue. Ask in the c# server
And it's not really testing what you know if you're asking at every major step. No offense
Just to reiterate, I would really appreciate some help with my code. I am pretty new to unity and so debugging has been quite difficult. For some reason, even if I start my character on the floor, if I use wasd to move it teleports the character up 2 in the air and I have no idea why. Any help would be really greatly appreciated.
start remembering code runs top to bottom
You put ReadLine before you WriteLine
string potatootomato = Console.ReadLine();
Console.WriteLine("Would you like to cast potato or tomato?(type in lowercase)");```
alr now go to some courses, some good ones pinned in this channel
https://gdl.space/ikozexudic.cpp
im getting the error Object reference not set to an instance of an object unsure what is meant by this but happened since I added MultiText
you have to read the line number
don't forget to assign your references in the inspector
its on 31 but I dont see a problem with that
unsure what you mean by references can you elaborate I only started unity today
MultiText is null, so you never assigned in
then start with beginner courses. there are some good c# courses pinned in this channel and the pathways on the unity !learn site a good place to start to learn the unity engine
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
which you do in this case by the inspector like they said
What Boxfriend said, you will learn so much faster if you do some of the Unity Learn courses
ive started these and im doing them then do a little project with what I learnt then continuing
inspector is a fundamental thing you should've learned
you started unity today and you claim to have done enough starter courses to branch off to your own projects? lol
and no, random youtube tutorials that just tell you exactly what to do but not why you should do it do not count as beginner courses
no no I am using some amounts of what I have learnt this is a very basic one I click a button and it adds a value
ah so this is your first day trying your own thing instead of just a unity course
I understand what happened in the tutorial I watched it was just simple math operators but im working away from one now it was working until I added a text label
that's what I like about Unity learn, they actually tell you why you're doing X or Y, and if they realize they forgot an explanation, they go back and include it in post.
I done like 8 hours of the course today
ah nice, that is progress
I started those courses in January, it was tough at first but you'll burn through them
I mean I am only doing this to learn the basics as of now not expecting to create a million dollar game but more a project I can use to reflect on the progress I have made in the future
that is a good way to go about it, BUT, at this point early on, you will learn so much each day that you'll find yourself constantly re-doing your personal project as you learn new things
trust me, i did the same thing haha
this will show the essentials like working with the inspector
as long as im doing something and making progress and not lacking motivation 24/7 im happy
Please help: OnCollisionEnter2D not working. But both game objects clearly touch visually.
hey I have two 2d game objects, invader and target
the invader game object has a box collider 2d, and a rigidbody 2d that is kinematic
the target game object just has a box collider 2d and a target script
"is trigger" IS NOT ON the box collider components of the game objects
I have this code in the target script, and when I press play, nothing fires from this function.
`private void OnCollisionEnter2D(Collision2D collision)
{
Debug.Log("hello");
if (collision.gameObject.CompareTag("invader"))
{
Debug.Log("collision inv");
}else{
Debug.Log("collision else inv");
}
} `
Ok thanks I have started this although I havent finished
its worth it, it covers a lot including configuring Visual Studio
same for me, I spent the past two weeks working on a movement system for a single character in a game, only to scrap it all after realizing what I had already was decent enough. But even if 2 weeks were wasted, it was 2 weeks of learning new things about movement, rather than just being unmotivated and doing nothing
alr thanks
you have at least 1 rigidbody ?
yeah the invader has a rigidbody
im really bad when it comes to motivation I had started doing something like a few months ago and Ive learnt a lot and made a bit of money I just havent been motivated to do anymore but I should really but eh
what is the best way to store data for a small object and only one object will use it?
the other object needs a non-kinematic rigidbody then
see this table
https://unity.huh.how/physics-messages/collision-matrix-2d
store it where? runtime or
I just added a rigidbody to the other game object and it still isnt firing at all
runtime
because it is static which is basically the same as no rigidbody
it cant be static
did you even look at the links that were sent to you?
this is a great chart!!
what kinda data do you wanna store ?
i'm looking now thank you
numbers/strings
thank you all!!
is it many objects? make a struct and use a dictionary or something
no, it is just one object. What script should I be saving the data? There will be multiple scripts working together
that depends on your project lol
ok
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.
Did I miss where you said what the issue is?
oh i had post it in unity talk channel talking to navarone
my issue is that i dont know how to do an action only when the down arrow button is pressed
but whenever i put this code it takes a while to detect
the input
It should be called on the exact from you press the down arrow (and only that frame) π€·ββοΈ
The other ones should probably be if statements, not if else though
if you mean that last if statement, you're not checking if the down arrow is pressed. you're just checking that it was not started being pressed this frame
Ohhh, it was way over on the right, so I didn't see the down arrow on that check.
so the fix should be to change else if to iff
huh?
You gotta clarify what the issue is.
What I said was an aside
What boxfriend said is probably the issue (but you weren't very clear, so...)
ok, let me be clear
is this not about the last if statement that is not an else if? or have i got the issue mixed up because you didn't bother posting it with your code and haven't fully explained exactly what you are trying to do compared to what is actually happening?
I'm assuming this is the same as your question here?
#1173389909684387840 message
I have this code in which if GetButtonDown, something occurs and if GetButtonUp the action stops. However, whenever I play the game, the downarrow input takes a bit to be recognized
Yeah, then change if else to if.
That is part of it
why does that make the difference?
well it will only register on the first frame you hold the button if you are not already using a horizontal key that frame
GetButtonDown happens the frame you begin pressing the key.
GetButtonUp happens the frame you release the key.
Okay, then why does it take time to recognzie the imput?
Show the actual methods being called.
It doesn't. It happens right away. But you are calling idle every frame while holding the down arrow that is probably overwriting whatever you were trying to do
ooooh i see
lets see what happens
nope, it still takes time to react
but the IDLE only starts whenever there isnt ANY input AT ALL right?
Then you're going to need to post the full code and explain what you're expecting to see happening instantly but isn't.
no. it can start when you are holding the down arrow
Unless you've changed it, idle happens whenever you didn't start pressing down this frame. If you're holding down it still runs
so what is the code i should put
if (!Input.GetKey(KeyCode.RightArrow) && !Input.GetKey(KeyCode.LeftArrow) && !Input.GetKeyDown(KeyCode.DownArrow))
{
_myManoloMove.IDLE();
}
this is the code
That's the same code you had before, did you change anything?
nono im only asking what should i modify
If you don't want it to happen while holding the down key, you should check if you're holding the down key, instead of just checking for a press
get key down is the one you want to use , i think.
do i need to add a return to a while loop if i want it to keep running
continue
return exist out the whole function
break is to only stop loop
That's what they have now
ah gotcha
π , my mb i misunderstood
It's unclear what you WANT. Do you want to be idle as soon as you are not holding the keys?
If so, them try it
i want idle as soon as getkey up
the problem is that the downarrow input takes a while to be actioned
GetKeyUp of ANY of the keys, or NONE of the keys being down?
{
while (!hasSeenPlayer)
{
enemyAgent.SetDestination(pp1.position);
currentPP = pp1;
if (distFromPP <= 1)
{
enemyAgent.SetDestination(pp2.position);
}
else continue;
}
}``` @rich adder so if i write continue then it'll just return to the top and run it again right?
of the downarrow key
oh misread what you said, thought you were talking about a for loop myb
you mean you want infinite loop or something
you dont need anything for while loop to keep running
oh
(ofc assuming the () condition doesn't end it)
Then just call idle in the getkeyup of the down arrow instead of that compound if?
Continue is to skip the rest of the code and start again at the top. If you do it at the bottom it doesn't make a difference
yes okay but that still doesnt fix the input beign recognized after a while
to end it pre-mature without if condition you would just put break to end the while loop @muted wadi
Did you try?
The input is recognized immediately, the HANDLING of the input is the issue
yes
oh i see
Then as asked, show the rest of the code
can you explain what you mean by this and actually share the rest of the code as you've been asked several times now?
also im trying to write a script that takes the positions of 4 patrol points (assigned in the editor), and make the navmeshagent move from 1 to 4 indefinitely unless the player activates the hasSeenPlayer bool. I'm not really sure if the way im doing it is efficient at all.
use a while looop but use a coroutine
then push the index ++ when you hit a waypoint
of the input manager
and share the class where those methods you are calling are actually implemented
The player takes some time to react to the down imput
what?
i understand coroutines, not sure how to add a loop to it tho
what about that statement was not clear?
in what way
please, I would like you to be more respectful
Do note that this will freeze the game. While in the loop, no other code will run, and Unity won't go to the next frame until your code has finished executing. Which is not possible, because it's in a loop right now. Be prepared to save your project and force-shutdown Unity if execution ever enters this loop
in the way that i press the down arrow and the player doesnt react after 1 or 2 seconds while playing
not everything is an attack against you. but i guess if you don't want to clarify what part of what i said you do not understand then i won't bother helping
really?
well thanks i guess, didn't know my loop was gonna blow up unity
You need to put the loop in a coroutine and yield in it
i have been clarifying it since I enterde this chat
please i need some help
ah i see
Yielding allows Unity to render the next 1+ frames, thus not freezing
ok i'll give that a shot and inevitably come crawling back once i've pulled out enough of my scalp
lol no you haven't. you keep repeating the same vague nonsense over and over. "it doesn't react" doesn't actually say anything about what behavior you are experiencing versus what is actually happening. but that's also not even what i was referring to there.
but you can stop pinging me now. you don't want to actually answer questions or provide the information that has been requested of you so i'm blocking you and will not be helping further π€·ββοΈ
I'm currently working on a Unity project and I've encountered an issue where my player character is not rotating towards the mouse position. I'm trying to make the player character face the direction of the mouse cursor, but it's not working as expected.Could anyone help me please.
player controller.cs script ( https://paste.ofcode.org/34EPK3A6J88hXp3qtQHV97m ) , Player.cs script (https://paste.ofcode.org/V54BvCfLnTbNwZtqyykPAh)
please, i do want to, i just need a little bit of a guidance
okay, give me the last opportunity okay
im gonna write it as precisely as possible
something like this maybe ```cs
public Transform[] waypoints;
int currentIndexWaypoint = 0;
IEnumerator GoTowaypoints()
{
while(patrolling)
{
if(Vector3.Distance(transform.position, waypoints[currentIndexWaypoint].position) < 1)
{
currentIndexWaypoint = (currentIndexWaypoint + 1) % waypoints.Length;
}
if (seesPlayer)
{
patrolling = false;
}
//go to waypoint
yield return null;
}
}```
Just share the. Code being called by the input.
i already did it
Lavanta
IDLE
etc
oh ok
This is not it.
my character controller no longer moves my character after I made custom gravity
yeah thats pretty much what i was doing before, minus the coroutine, also good shout on that currentIndexWaypoint, i wasn't really sure how to track the current patrol point
im quite awful with loops right now
you can do the same logic in Update
I would not use a while loop there tho
Ok. What did you do exactly?
i would recommend instead of raycasting the ground (since that not only requires a collider so it won't work if your mouse is not over a collider on whatever layer your groundMask is on but also may end up at a different elevation from the player), i would instead raycast against a plane using the player's position and up direction.
here is an example: https://unity.huh.how/screentoworldpoint#using-a-plane
yeah but i have a coroutine for my field of view check so its probably fine to have one for the patrols too
I wrote custom gravity that adds a force to the rigidbody dependng on which gravity fields the player is intersecting with. Haven't change anything with the character controller but now it won't move
yeah its fine to run multiple ones thats why they are sorta-async
I also tried reverting to the old system I used and that doesn't work either
lol solved it for me , i forgot to set layer , only my ground is using that layer mask. ty for the help π
Does the other animation state have an exit time?
Now that I see it, it seems like an animation issue
You should show code if you expect to get h elp
the "agacha"?
Wait you said rigidbody and CharacterController? Those don't work together
You should pick either one
Sure
its a custom character controller
if (onGround)
{
rb.AddForce(moveDirection.normalized * moveSpeed * 10f, ForceMode.Force);
}
else
{
rb.AddForce(moveDirection.normalized * moveSpeed * 10f * airMultiplier, ForceMode.Force);
}```This is for the player movement
where can I check that?
Looks ok, what about the gravity part?
rb.AddForce(gravity, ForceMode.Acceleration);This is how the gravity is applied which is from this gravity = CustomGravity.GetGravity(rb.position);
{
Vector3 g = Vector3.zero;
for (int i = 0; i < sources.Count; i++)
{
g += sources[i].GetGravity(position);
}
return g;
}```This is the get gravity method
I checked and the script for movement is registering input
Should I uncheck it?
Maybe the gravity force is just really massive and keeps you stuck on the ground?
definitely possible
sources[i].GetGravity is still a mystery
thats a list of all the objects containing the gravity script
its just adding it all together based on influence by distance
Oh so it's recursive? π€
I mean the GetGravity method you call here. Is it a different method than the one you posted?
{
return Physics.gravity;
}```
I see. That doesn't really make sense to me
If you have 5 sources, your gravity will be 5x from normal
Well, if your issue is that you want it to be immediate, an exit time may not be what you want.
The input is immediate, the animation is not
Or something
thanks bro it wassss
thanks for the patience
I set everything around the player to 0.1 gravity and for some reason the player now just floats straight up
Now, does somebody know how to reduce the collider of my object if it crawls?
If you set gravity Y to 0.1, then yes things will float upwards
Normally gravity is negative Y
Maybe explain what is the purpose of this system?
And what kinda game
I changed it to negatives and its still floating upward
Changed what to negative, exactly?
the gravity values on the planes
why am i getting this?
'Random' is an ambiguous reference between 'UnityEngine.Random' and 'System.Random'CS0104
they should be getting converted to negatives either way
Both namespaces have that Random class
using Random = UnityEngine;
its not that
What is a gravity value? Is it your own variable or the rigidbody gravity scale or what
{
Vector3 up = transform.up;
float distance = Vector3.Dot(up, position - transform.position);
if (distance > range)
{
return Vector3.zero;
}
float g = -gravity;
if (distance > 0f)
{
g *= 1f - distance / range;
}
return g * up;
}```All of the planes use this getgravity method
? Yes it is
wait what do you mean
Both System and UnityEngine have a Random class
It is ambiguous which you want to use
So clarify it
custom float value
It doesn't know which Random you want to use
See you should tell me that instead of expecting me to know everything about your game
I just gave you what to write.
hey man theres a lot of factors here. I can't cover everything the first time around
Oh wait. Should be using Random = UnityEngine.Random;
(Or System.Random if you want...)
Sorry
Is there a certain wait to enable certain attributes only if one box is pressed?
checked
You mean like, in the inspector?
yeah
It's not builtin, you could use a 3rd party package like NaughtyAttributes though. It has HideIf/ShowIf and a bunch of other useful stuff
https://dbrizov.github.io/na-docs/attributes/meta_attributes/show_hide_if.html
Or make a custom editor script
enums will draw like that automatically
public enum BodyType
{
Dynamic,
Kinematic,
Static
}
[SerializeField] BodyType bodyType;```
As an example
thanks
This is what I'm seeing in terms of what gravity is being applied
I still have no idea how your game works/is supposed to work though
Like why is there a Vector3.dot check with upwards direction?
Is that code on the plane?
Is it an airplane?
that's to check if the player is within the range of the planes gravity
It says distance, but it's really a dot product, kinda confusing
its some weird math
Did you write it?
I followed a tutorial for all of this
I also found that the playermovement script is not actually registering any input from the player
How can I reduce the size of my colldier when my player crouches without loosing its position?
Change the collider's center as you change its size
how can i do that?
Oh yeah it's offset, not center for 2D colliders
Yes, as long as you use the correct values
So if you reduce 0.5 from size Y, you should reduce 0.25 from offset Y (if my brain is braining correctly atm)
will it start another courtine before the first one finsihes
A clean way to do it would be something likecs float crouchTarget = crouching ? 1f : 0f; // A "smoothed" value that moves between 0 and 1 depending on your crouch state float crouchTransition = Mathf.MoveTowards(crouching, Time.deltaTime * someSpeedFloat); // Apply offset boxCollider.offset = Vector3.Lerp(standOffset, crouchOffset, crouchTransition); // Apply size boxCollider.size= Vector3.Lerp(standSize, crouchSize, crouchTransition);
@ionic zephyr
stand/crouchOffset and stand/crouchSize are Vector3's that you would adjust to your desired values
public GameObject[] Array;
public void ExecuteArrayScripts()
{
Array[].gameobject.GetComponent<ScriptIwantToExecute>().Function();
}
How can I execute a function from every gameobject in the array?
I tried doing Array[Array.Length] then that but it didnt work
foreach
Also, if you have a script you want to reference, you should use that type instead of GameObject
Thanks, both of those things helped
hi, maybe #archived-shaders would be the better channel for this
Does this code good?
I make a cards (units) there will be much of units and maps, so, I made it to make easier card works (hope) in theory I will not be need to set for every card/map their objects
(Sorry for my English, sorry)
The really long variable names make it hard to read.
I don't like that naming convention...π
Maybe it would be easier if you use the C# naming conventions
How do I change this text using code?
Is it different from doing it with the Legacy text?
No, just reference an object of type TMP_Text instead of Text
Thanks
PIN = GetComponent<TMP_Text>();
This just gets the component the script is sitting on right?
It only finds the component from the gameobject the script is attached to right?
Yes
Ok thanks.
Apart from the names (which are ROUGH), you really don't want to use Find() very much.
Where is this code? In Start? Update? We have no idea and the performance impact would be very different between the two
Lastly, your IDE doesn't seem configured? I can't tell
I don't know much, doesn't have much experienced in scripting and it's in awake
how do i create signals like they do in godot
Sounds like signals are an implementation of the events pattern programming pattern.
so, should I make my UI a Prefab or a Scene? some say a scene but some say prefab. The thing is I'm going to use the same ui for all the levels. What should I do?
you asked this earlier and also not a code question
ah wait- yes I did I forgot.. Really sorry qwq
hey, mr. navarone, i do change my code about inventory like this https://gdl.space/imedihupix.cs and finally it save to .json. But i have a problem in my LoadInventory, i want instantiate a game object based on item tag that i save, i already move my prefab to resources folder and it always said prefab not found.
I would use scriptable object instead of a tag, to hold all the data about a item or weapon and so on including the prefab and instantiate a copy of it that way and use a ID to define what item you are saving and loading
You can also make a IDManager that applied ID values to each item in your game using a for loop to make your life easier
is scriptable object made for each itemprefab? for example there is prefab A and B, and i make scriptableObjectA and scriptableObjectB and attach to the prefab?
Well you can make seperate scripts, like one for Items that hold things that are gonna be common between all your items, and if theres a special item make a seperate script that derives from that to give it special values and so on. And the same would go for the weapons. EX: So you would make a base Weapons script that hold common thing between weapons, like they all have a name, icon, description ex. then make a meele script that derives from that and add like physical attack damage and so on, and you can do that with bows, magic powers and so on
i can provide example scripts if need be
i want the example script sir
!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.
lets say i make item with both of this script https://gdl.space/norajujasu.cs
https://gdl.space/zegemeyiki.cs . then i attach this script https://gdl.space/zegemeyiki.cs to my prefab right? and fill the status in the inspector?
nope theres not attaching
https://gdl.space/podoxoyoxa.cs
So in this one at the top i did a create asset menu, so inside where you have your folders and so on, you would right click go to create and find the defined name that you have given it which is this for mine "Items/Weapons/Melee Weapon" and create a new asset and fill in the required information, including dragging in the prefab, all this does is holds a item or weapons Data to be used anywhere
and allows you to make multiple weapons and items super quick
If you need help understanding how this system works ill be glad to hop in a call and teach you how to make it
it would great sir, so u want to teach me π
Yeah i have no problem doing that
I'm currently following a tutorial but I think VScode doesn't understand this line and I'm not too sure what I did wrongly when setting up π
i don't think the code editor would get confused about . . . code . . .
did you count your parentheses?
VSCode should be underlining errors in your code for you, do you have it configured correctly?
I think i set it up wrongly? i checked everything else and they matched exactly the same as the video
i meant, what error are you receiving, if any?
no error but unity isn't applying that code
how do i figure out why calling out this method is enabling a gameobject in my scene which i dont want it to be enabled yet
is not applying? do you mean the code does not work/run?
yeah π sorry i just started today
is the script attached to a game object in the scene?
where is this code placed (within the class/script file)?
uhsh
follow the execution of each line and see what it does. this block of code β method β calls two other methods. look at them to see what they do . . .
You have a semicolon after the if statement
are you following a tutorial?
did you copy the tutorial exactly? i see a mistake on the if statement line . . .
ohh.. thank u π
welp, now you know about it . . .
well this method is just responsible for some playerprefs stuff, it cant possibily enable some gameobject
is there any way to figure in unity which line of code is enabling the object?
What about UpdateHealth(), also are you sure the method you've shown is the one responsible for this? What is calling ActivateCommonCold()? Could it be from there
Also what gameobject, what's the objects relation to this script
you still have to check all the other points of execution . . .
you can check if the GameObject activated has any relation to the GameObject this script is attached to or the code being called . . .
dont think update health is responsible either, and its being called out by a button, the third image is what it is activating but should not
why isn't your health text only the numbers? just split "Health" into a separate text component and the actual health value in its own text component . . .
thats not relevant here
true, but it's all over the code you sent . . .
well any clue on whats causing the object to be enabled?
hard to find. we only the method snippet and the methods it calls to. check the object and see if any scripts have a reference to it . . .
how do i check if any scripts have a reference to it?
click on GameObjects with scripts and check the reference fields . . .
or think of the last thing you changed. work backwards from the work you've done. you have to reverse engineer the problem . . .
Cant find anything man
Ctrl + Shift + F in your IDE and search for SetActive
then look for ones that pass in true for that
then look for the method that activates a GameObject in your IDE . . .
Okay i found something setting it to active, but it shouldnt execute until some method calls it, which a method does but then theres no method calling the other method. So the code shouldnt execute cause its not in update or start, do you know what might be causing it to execute?
place a log in the method that activates it, then you can highlight the log from the console and look at the strack trace to see where it gets called . . .
here's a guide to learn how to debug your code
https://unity.huh.how/debugging
you should learn how to identify which code is being run, be it through logging or using the debugger
FIxed it, thanks for the help guys
im trying to export a scene assetbundle but for some reason it keeps crashing. there are no missing scripts is what i know. but idk whats wrong
crash:
[Assets/Editor/ExportAssetBundles.cs line 15]
=================================================================
Native Crash Reporting
=================================================================
Got a UNKNOWN while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
=================================================================
Managed Stacktrace:
=================================================================
at <unknown> <0xffffffff>
at UnityEditor.BuildPipeline:BuildAssetBundlesInternal <0x000a7>
at UnityEditor.BuildPipeline:BuildAssetBundles <0x0008a>
at UnityEditor.BuildPipeline:BuildAssetBundles <0x0006a>
at ExportAssetBundles:BuildAllAssetBundles <0x00062>
at System.Object:runtime_invoke_void <0x0007c>
=================================================================
Crash!!
nvm i found the issue
Hello, not sure this is the best channel to ask but how would I go if I wanted to have this bed be a trigger collider while still using its mesh? I'm creating a toy war game where you control a small soldier and you can walk on the bed and I'd like the player to be able to go through the holes in the frames. But at the same time, since the player can shoot bullets, I'd like the bullets to get destroyed when they hit any part of the bed. Following tutorial video, it seems I need to use a trigger collider. But when I add a mesh collider, the trigger option is only accessible when I check the is convex option which mess the shape of the bed. So is the only solution to add several box colliders manually or is there some better way to handle this?
Gotta use convex or box colliders unfortunately afaik.
Ok, that's gonna be quite annoying :x
you should share what the error says in the console log. it's too tiny in that screenshot
and please dont crosspost
you already asked in #π»βunity-talk
try googling "Unknown error occurred while loading scene unity"
and you're right that this isn't a code question. should have stuck to #π»βunity-talk
GameObject.FindGameObjectsWithTag
Can I use this to find a PREFAB ( that hasn't been instantiated? )
no
targetUI = (Instantiate(Resources.Load("BattleTarget") as GameObject));
I figured it out, TY
Button position problems.
Hey there, I was wondering whether or not Photon Unity Networking (2.0) is P2P or if Photon has their own servers that they use to handle your games when you use their free package?
You can just drag the prefab in the inspector to the field, then instantiate. Shouldnt really need resources in this case
wondering why Visual Studio is not automatically suggesting code for Unity even though i have it selected under the external script editor
There is a photon discord pinned in #archived-networking
!ide did you follow all the steps here?
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'm having trouble here
TextMeshProUGUI dmgTxt = floatDmg.GetComponentInChildren<TextMeshProUGUI>();
damage.ToString();
dmgTxt.text = damage;
D: i don't have the option to modify
what is damage.ToString()? there should be a compile error?
Giving the actual error would be a good idea. Or at least describe the problem.
The option to "add modules" may be missing if you've installed your editor from not within the Hub
Anyway it's not necessary to install VS through the "modules" if you install it / have installed it independently, like the note in the instruction page implies
But it's also an option to you to reinstall the editor through the Hub and check the VS module during that installation
hey guys do you know what is making my animations so jerky? the float values of moveX and moveY keep going up and down which is set in line 101 of my code. i dont know why the values are so jittery. any help? https://pastebin.com/ngLea2Le
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.
(my agent is using root motion animations for movement)
(ps : i think this is more of a code problem then a ai problem so im putting it here)
// Low-pass filter the deltaMove
float smooth = Mathf.Min(1.0f, Time.deltaTime / 0.15f);
smoothDeltaPosition = Vector2.Lerp(smoothDeltaPosition, deltaPosition, smooth);
// Update velocity if time advances
if (Time.deltaTime > 1e-5f)
velocity = smoothDeltaPosition / Time.deltaTime;
animator.SetFloat(animator_DX_param, velocity.x);
animator.SetFloat(animator_DY_param, velocity.y);
This part is strange to me, not even sure what you are trying to do here.
Lerp means you Linearly Interpolate between 2 things, in this case smoothDeltaPosition and deltaPosition, both are changing constantly, and your smooth is changing constantly and not in a good way.
So you pick a point between 2 points at somewhat random.
what datatypes does a button's OnClick event support? I'm trying to use an enum but I guess it doesn't support that
oh that? its from here : https://docs.unity3d.com/550/Documentation/Manual/nav-CouplingAnimationAndNavigation.html
The Unity Manual helps you learn and use the Unity engine. With the Unity engine you can create 2D and 3D games, apps and experiences.
its unity official manual on how to use ai with root motion animation
i dont even know what it does
hey guys, how can I access inside a scriptable object the collider button to control the size of the collider ? I have an enemy prefab and use the a scriptable object to control things like HP, attack damage etc.. but each enemy is dif in size, how can I control the size of the collider for each?
by having the collider on the prefab for the enemy π€
i have it. but each enemy i spawn is dif in size, controlling the size via scriptable object and also sprite..
they need to have dif collider size.. but I cant control individually only in the prefab..
but in the prefab its one size for all
I honestly have no clue then, it makes no sense to me.
If the code is identical to the doc, the error lies with the animation setup and not with code
do you know what the problem is? because the animation works fine in inspector preview, and the jittering is caused by the values rapidly going up and down(i think)
also ive tried the animations in play mode on a model without any scripts attached and that works fine too
the blending, the looping
also there isnt a race condition happening with the agent and animator as far as i can tell
ive disabled the agents update position just like the docs said
When I click overrides -> apply all on an instance of a prefab, it doesnt apply the changes to the prefab!
does anyone have an idea of what's going on?
it doesn't seem to be able to reference the game objects from the prefab, but knows how many there are in each array
can someone tell me why this is glitching out when i move my mouse fast?
https://hastebin.skyra.pw/eqogahezur.pgsql
helpppp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Pickaxe : MonoBehaviour
{
[SerializeField] private float range;
[SerializeField] private float cooldown;
public Camera mainCamera;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
StartCoroutine(farm());
}
}
IEnumerator farm()
{
Debug.Log("Attempting to mine");
Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
yield return new WaitForSeconds(cooldown);
if (Physics.Raycast(ray, out hit, range))
{
if (IsMiningNode(hit.collider.gameObject))
{
Debug.Log("Hit " + hit.collider.gameObject.name);
// Add your mining logic here
}
}
else
{
Debug.Log("No hits");
}
}
private bool IsMiningNode(GameObject obj)
{
return obj.CompareTag("coal") || obj.CompareTag("gold") || obj.CompareTag("ice");
}
}
Assets\Scripts\Pickaxe.cs(24,30): error CS1061: 'Camera' does not contain a definition for 'ScreenPointToRay' and no accessible extension method 'ScreenPointToRay' accepting a first argument of type 'Camera' could be found (are you missing a using directive or an assembly reference?)
gpt and documentation says that it exists?
if gpt says then it must be true
Do you have a custom class called Camera?
if you didnt copy this code from chat gpt then maybe it would work
no
i tried to do it myself beforehand and it said its not defined
thought i missed something so i told it to rewrite it
omg i just realised what the error is
mb
You Lerp towards your rotation, so there is a delay.
If you move real fast, you go backwards to the same rotation, because that's closer to the desired rotation.
can i like limit it somehow?
maybe the speed of the rotation
You could have a float value outside of your rotation for example, and Lerp towards that float. So if you have a float with 3600, it will rotate 10 times towards the right.
And you make a rotation based on that float.
but after 10 times same thing would happen
No, if you want to rotate to the right another 10 times, your float would be 7200
Perhaps that works too. I don't know how that fares with different FPS for example.
Looks good
HealthBarScript has:
public void UpdateHealthBar(int CurHP, int MaxHP) { slider.value = CurHP / MaxHP; }
Unit/Player/AI/Enemy has:
private void UpdateHealthBar(){ if (healthBar) {healthBar.UpdateHealthBar(CurHP, MaxHP);} }
...and...
public void TakeDamage(float damage){
curHP -= Mathf.RoundToInt(damage);
healthBar.UpdateHealthBar(CurHP, MaxHP);
}
BUT My HP bar doesn't work, what went wrong, this was 100% functional yesterday
Wdym by "doesn't work"? What debugging steps have you taken?
I can see my vars curHP and maxHP and they work fine
but the HP BAR Doesnt ddraw the vars accurately ( very wrong drawing )
and its simple code
slider.value = curHP / MaxHP;
this worked 100% yesterday
i believe it wont work
your curHP should be always < MaxHP and return 0
my curHP = maxHP at the start
ONce taken DAMAGE ... My CurHP should be .. = MaxHP-Damage=CurHP
CurhP shouldnt NEVER be 0 (unless chaaracter is dead
curHP and MaxHP both integers?
I don't understan why it should retrurn 0
yeah both INTs
Then you are doing an Integer division, and always get an Integer back.
So its probably always 0 or 1
Or cast one of the values to a float.
or can I draw HP bar with INTS?
so I can make it work if only 1 var is Float ? thats easy
slider.value = curHP / MaxHP / 1.0f; should also work, as long as 1 of the values is not an int, it will do a float division.
(Kind of janky to do it this way)
π
TYVM bro!
i've got this name text
and i need to make it move with the head
how do i do that?
this is a texture image
the actual character is just below the map
the target would be the head and name would be the text
this doesnt work
why am I getting this error? my script has no compile error
Remove the script from the object and add it again
Text at the UI level, it naturally has no workγyou need use Camera.main.WorldToScreenPoint(targetPosition);
if you have ANY compile errors, fix them
Based on this: #π»βunity-talk message the filename is wrong
same issue, I removed component, deleted file, and then added new script and added the code
the filename?
Does your class have the same Name as your file?
You can potentially have multiple classes in a file so unity doesnt know which one to select
So its done based on file name
gotcha, thank you
Reference rewriter: Error: method System.String System.Web.HttpUtility::UrlEncode(System.String,System.Text.Encoding) doesn't exist in target framework. It is referenced from RestSharp.dll at System.String
Does anyone know how to solve this issue? got like 10 of these kind of errors regarding RestSharp when building
all i really need i think is the original position of the text, original position of the head, and then like a multiplier of how much the text moves with the head
and calculate how much the head moves from its original position
and apply those values with a multiplier to the text
Hello, using XRInteractionToolkit I'm currently trying to figure out a way to check if an object has been placed in the XRSocketInteractor, what I am trying to achieve is a way to set the parent of the object that has been placed in the Socket to be the object that has the XRSocketInteractor as a child
You need to convert the head world coordinate to screen coordinate.
could you please help me
im so confused
Camera.main.WorldToScreenPoint(targetPosition)
targetPosition is head position
and result is head position on your screen
script
yeah i have the same thing
Replacing rectTransform with transform
game view
You can't see the character's head, of course the text will be in that position
what
thats why i said i need to keep an offset
i need the text to stay in the position its at
so in start i should set a defaultPosition
and then i just need to add or multiply how much the head moves
with a multiplier
Did you use two cameras
yup
Replace it with the character's camera
what is that gonna do?
just do it
is this UI?
yes
you should be using anchors
Yo anyone know a good way to index transform? Should I just make my own array?
the character is a texture
so ?
i am using anchors
i have everything setup correctly
except the script
you said the text is moving ?
use mesh text instead
i want it to move with the head
like it is right now
but its in the wrong spot
but I can't tell which one is UI elements and which one is world item
I see
you want text to rotate with player ?
with the head
and the neck is here
use mesh text
the bottom circle is the object
they mean texmesh but its 3D object not UI
yeah
do you think its a good idea to just make a original position of the head and text in start
and then calculate how much the head moves from its original position to where it is in update
and just add that to the text
with a multiplier
so i can control how much it moves
thats what i suggested earlier
kind of
so this
and then i need to add the newHeadPosition to the text position right?
He has already tried it before
its different
whats error say
'Vector3' is an ambiguous reference between 'System.Numerics.Vector3' and 'UnityEngine.Vector3'CS0104
oh alright
delete using Systsem.Numerics
yeah i just realised
You've got two using statements that have the same class in them and it doesn't know which one you mean
Is using Mathf.Infinity more performance-intensive than using a smaller number?
why would it,? is just a number (constant)
You asked this like yesterday and got an answer...
yeah i forgot sorry
it's const, So there's no difference
Okay thanks!
so when the multiplier is at 0
the text is there
its not at its original position
looks like its at vector2.zero
the multiplier was also in the wrong place
because i was multiplying the final position
and not how much it moves
wait no its still multiplying the position
whats any number * 0
yeah i know
the multiplier works
its in the wrong place still
its something to do with this name.rectTransform.position = initialNamePosition + convertedHeadPosition;
do i need to multiply it?
when working with UI you probablu want .achoredPosition
also yeah
Why does my background move slower if my player moves?
My player logic: https://hatebin.com/ljrfqqjruk
My background logic: https://hatebin.com/wqbqtlgcvk
It also for some reason leaves empty space between my two backgrounds, even though I made sure they align.
to be honest i can't make heads or tails of how your player movement or your background movement works from these scripts.
I can see that at least for keyboard mode, you are setting a Rigidbody velocity, but you also seem to be constantly setting your position to some constant position each frame
In mouse mode, I set the player's X position to the mouse's X position.
The background just continuously goes down before hitting a specified position, then gets set back up.
you'd have to show that code - how is it moving?
the BackGroundLogic script only seems to do that "reset" logic
it doesn't seem to do the normal movement part
Here, it's in that same script
ok right so this is confusing me because of the transform.position.y - scrollSpeed
you seem to be subtracting scrollSpeed every frame with no framerate adjustment
meaning it's framerate dependent
Oh!
should be:
transform.position -= Vector3.down * Time.deltaTime;``` for example
Yup, changing it to```cs
transform.position = new Vector2(xPosition, (transform.position.y - (scrollSpeed * Time.deltaTime)));
Heya, is there a function that allows me to rotate something so it is always facing the cursor sort of thing or is it done with math / what math would i use? 
this is well trod ground, lots of tutorials for it. pretty simple though.
you don't need to use math but many tutorials will
What is it called?
I'd also like to know
how do i check if a trigger titled "SlimeAttack" stored in "rslime" animator is triggered
idk... "unity 2d look at mouse cursor"?
var dir = worldPoston - transform.position; var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
I need to encode a very large state hierarchy of booleans to validate a visual style set in inspector
I thought enum flags would be the answer for this but I can't find a way to make the flag enum have mutually exclusive values.
How do I solve this problem? My XY ask is 'how do I make it so when I hit A, B, or C in the flag enum that the other two get unset'? eg. mutual exclusivity
My deeper question is how do I encode a massive hierarchy of possible states that can or cant exist in conjunction, and store it all in a single place that can be passed around easily, and stored all in such a way that its extremely trivial to expand this?
The first time I tried to make this I just added a new enum every time I had a new use case for a new visual state but it rapidly balooned into unusability because there were just too many states, too many use cases with some kind of overlapping mutual exclusivity with some other element of the visual state
How do i create a clone of a gameobject foreach string in a list? foreach(string e in Resolutions) { GameObject AnotherChoice = Instantiate(Choice1); AnotherChoice.GetComponent<TMPro.TMP_Text>().text = e; }
This is done at start.
looks fine
what's wrong with it?
Assuming these are UI elements I would expect you to be creating these objects as children of some other UI element (e.g. a LayoutGroup of some kind). But this will definitely create the objects
The "AnotherChoice" gameobject is not in the unity editor.
Sure it is
If this code runs, it's creating the object
check your hierarchy
maybe the list is empty btw
which would mean no objects are created
Oh sorry, i failed to read the first time.
They are definitely there.
Thanks for the help.
Hello, i've been learning tilemaps a little bit and got stuck, is there any way to spawn new floor tiles while i run?
yes
What'd be the best way to go about it?
Tilemap api
get your current postion and spawn the tiles under it with WorldToGrid function and then tileMap.SetTile
Awesome, i'll give that a go
Seems like you need to eliminate some abstraction and just define a root set of elements which cannot be unset by the children. You don't want to run into edge cases where there is no state where a specific set of elements cannot exists with each other.
Crazy question. Does lists work in unity?
? Yes?
I'm trying to add an element to a list and it seems to just seems to crash my start profiler.
Using .Add(item)
Show the code
Adding things to a list is ubiquitous in games...
{
// At the start we can set everything to zero.
ZeroScoreBoard();
// Form childListPosition.
foreach (Transform child in transform)
{
childList.Add(child);
Debug.Log(string.Format("Child List: {0}", child));
}
}```
Something as simple as this
depends where you spawn it @twin bolt
I found the issue the clones are set at scale, 0,0,0.
Spawn it in the correct position to begin with. For UI elements typically you want to just use the Instantiate(prefab, layoutParent) overload
OKay thanks
nothing here would crash
Crazy since I can't even get Debug.Log to print.
Are you sure the add function is where it crashes?
Do you initialize the list?
show declaration of childList
you prob have a null ref and the game pauses so you think it crashed
private static List<Transform> childList; As a variable to the class.
yeah its not init
yes, not initialised
Mh i'm stupid thanks
dangerous to have a static List in a Monobehaviour though
Why is that? Ref accross all instantiations of Scoreboard class in this case.
I mean tbh i only have one instance of scoreboard so this might change, but I am currious as to why it is dangerous.
make a singleton
one List containing all the children of all scoreboards, I can't see the point
you need to be very careful with the static keyword
The scoreboard should be the thing that you have one instance of, not the list
just use a normal list in the scoreboard
Yea. I am gunna change it to non static.
do you want a singleton class?
Hey everyone,
In this tutorial we cover the controversial SINGLETON! Many people will hate me for teaching this but I think it is a useful tool to have, or at least know about when programming. Hope you learned something and thanks for watching!
Example video of singleton that exists in scene (Canvas Manager):
https://www.youtube.com/watch?v=v...
Now im trying to make my own culling system by make a grid of triggers based off chunck and map size, and on wake it gets all the objects that are in that chunck, and if the player isnt within a specified range then a for loop iterates through each obhect disabling them, and same for reenabling them when the player enters the chunck would this be effective, i have a feeling that this will cause a performance issue though later on when adding more clutter to each chunck
stress test first by just dropping a ton of crap into a few chunks
just take one thing, and copy paste for 10000 things
Appreciate it π
Yeah i figured thats what ill do, just checking and seeing if someone has already tried the solution
to use it, change from:
private void Awake() {
} ```
to
``` public class MyScript : Singleton<MyScript> {
protected override void Awake() {
// DontDestroy = false; // depends if you want to destroy on load
base.Awake();
} ```
can someone help me? My text color is not changing to the color i want:
Hello, I'm trying to implement native ads in my game but I'm facing an issue:
this is the code for requesting a native ad:
private void RequestNativeAd()
{
AdLoader adLoader = new AdLoader.Builder(nativeAdUnitId)
.ForNativeAd()
.Build();
adLoader.OnNativeAdLoaded += HandleNativeAdLoaded;
adLoader.OnAdFailedToLoad += HandleAdFailedToLoad;
adLoader.LoadAd(new AdRequest.Builder().Build());
}
private void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
Debug.Log("Native ad failed to load: " + args.LoadAdError.GetMessage());
}
private void HandleNativeAdLoaded(object sender, NativeAdEventArgs args)
{
Debug.Log("Native ad loaded.");
nativeAd = args.nativeAd;
}
however, the ad is successfully loading but the function of " HandleNativeAdLoaded" is not working and not debugging.
There's only a debug for the ad being loaded which is this:
not a code question, also use Text mesh Pro
Most likely only working when run directly on mobile
In unity timeline, it seems like control trsxk can do anything the activation track can do, so what's the point of the control track? Correct me if I'm wrong
!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.
Same case, it worked once on mobile but then nothing
Once in which timeframe?
Like I just tested it after re-building and it worked, then i tried replaying the game and nothing appears
Is there more events that you can subscribe to? sounds like the network did not have another ad ready for that instance yet
Yeah! It has at least THREE physics
there are those
I'm starting to feel the difficulty lol, there are so many concepts
you are br?
Am I what?
nothing, forget it
Brazilian?
Hello, guys! I have an error here in my code. Check what it says:
mainMenuVolumeSlider is null. Cannot load options. UnityEngine.Debug:LogError (object) SettingsManager:Start () (at Assets/Scripts/SettingsManager.cs:30)
yes
Looks like it's telling you what's wrong and where to look!
This is YOUR Debug.LogError it looks like...
Yeah, but I cannot understand why it is null? I am checking it in order to not be null.
well that would have nothing to do with what you've shared
it has to do with how you are (or think you are) assigning it to something other than null
"checking if it's null" doesn't make it not null
it just tells you if it's null or not
You're just gonna have to show code..
I keep getting this error when opening my andriod game project
Job failed with exception: GooglePlayServices.JavaUtilities+ToolNotFoundException: jar not found.
but i installed the andriod stuff when installing my engine version
i have some problems with my code; i have two audio sources, one for firing my gun and one sound for reloading
however when i initiate the reload sequence the "gunfire" sound is played instead of the reload sound
I have this code for my background:
https://hatebin.com/hkqvhtqpqq
It should move the background down, speeding up more and more until it hits 10000f speed, on the way always teleporting above the player's screen if it gets outside of the visible area. It should then, when it hits 10000f speed, reverse this. Going from the bottom upwards while decelerating at the same speed that it accelerated before. Once it hits 0f, it should go the original way down again, and that repeatedly. For some reason, my code just doesn't work. How do I fix that and make it do what I want it to do?
Also I got this on android logcat, idk if its relevant:
Then you're probably playing the gunshot audio source, not the reloading one
Show code
im using test ad unit by the way
Hey, guys! Do I have to have my Game Manager, UI Manager, Audio Manager etc game objects as prefabs? If yes why if not why not?
I mean if I have to use them on different scenes don't they have to be as prefabs?
You don't have to do anything

how do i show you the code
!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.
!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.
copy and paste your code in one of above websites
m_shootingSound = GetComponent<AudioSource>();
m_reloadSound = GetComponent<AudioSource>();
These are both going to get the same audio source
There's no reason to have two variables
how do i do it otherwise?
Use one audio source and change the clip it plays before playing it
Why not have AudioClips with the sounds, and pass those clips into the source
audioclips allows you to use numerous audio's?
do i then just change the clip depending on what button is pressed?
An AudioClip IS an imported sound file
So one per sound
Then you pass the one you want to the source and play it
