#💻┃code-beginner
1 messages · Page 383 of 1
i used the discord search feature. just using mentions:Justin Chou with the keyword "entrance"
Ahh, thank you that's super useful
yea, the search options are pretty good on discord
if u can vaguely remember something and who u were talking with, its pretty easy to find stuf
foreach (var asset in allAssets)
{
if (asset is AnimationClip clip)
{
Debug.Log("Found clip: " + clip.name);
if (clip.name.Contains("preview"))
{
break;
}
will break exit the foreach loop or go to the next loop?
im trying to store a vector 3 in a variable so i can then change the transform.position of a game object in a if statment
how would i store the vector 3?
using what type
I don't know how you could know the term "Vector3" and not know that it is a Type
What's the most elegant way to add a door here? The tilemap already has applied a collider, would I simply add another collider for use as a door?
My proposed solution seems clunky
i know like ints, string and other stuff but im used to not game dev
If it's a thing and you have a name for what it is, that's a type
📃 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.
how would i make it so when i run jump it keeps my momentum? this is the first time im using a character controller instead of a rigidbody one so.
https://hatebin.com/sedhirluyr
one side comment: you should only call Move once per frame
If you call it several times per frame, you get two problems:
- Your movement is split into several pieces, which could let you clip through a wall when you should've hit it (because you moved horizontally, then vertically
- The grounded state of the CharacterController might be wrong, because it's based on the result of the most recent Move. Not really relevant here, since you do your own ground check
also, I'm getting deja vu here -- are you following a tutorial for this?
someone else posted very similar looking code earlier today
yes i followed a tutorial, as i said this is my first time using this 😅
i know i can do this using if statements but i would like to learn another way to do this better
Whats the reference for the left click?
public KeyCode leftclick; //this is for you to choose when you are out of the script
//or
if (Input.GetKeyDown(KeyCode.Mouse0) )
{
//do something
}
//or
if (Input.GetKeyDown(leftclick) )
{
//do something
}
np
so you don't want to let the player control their horizontal velocity when in the air?
so whats happening is when i run and jump the run speed goes instantly back to walk speed, so i would like if you run jumped that your speed would be the same even if you let go of the run button.
i would like the player not to have to much air control but i can try and code that later.
What you can do is record your horizontal velocity from before the jump, and then keep using that until you hit the ground again
Or you could take the character controller's velocity, remove the vertical part, and then re-use that until you hit the ground
But you'd need to combine those two Move calls into one for that to work
GetKeyDown(KeyCode.Mouse0); is interesting, I use Input.GetMouseButtonDown(0);
i always used that, i mean they do the same thing
There is a slight difference. GetMouseButtonDown will also detect a touch screen tap. GetKeyDown only detects a mouse
ahh even better reason
There's reasons you might want to do either one, so it's not that either is "wrong", and 90% of the time you're going to know which one you want and being able to do both isn't very important
i have a gun that inialise a bullet on the guns spawnPoint. How would i make it so 3 bullet spawn spreading
maybe i could initialise 3 bullets and change there dirrection slightly
yes, do exactly that
by calling Instantiate 3 times such as within a loop
Maybe you won't need the loop if you aren't doing anything extravagant.
well the player will be able to upgrade the amount of bulletst they shoot, so never know
how would i change the angle? at the moment they fire facing the guns rotation. I know i would add like 3 to the z value but how would i make the first bullet - 3 then the second mnormal and the third plus 3
What exactly are you trying to do? Some variance in accuracy?
im making a upgradde where instead of shooting 1 bullet they can shoot extra not different accuracy but instead a extra bullet shooting of into a different direction
i suppose i could track if the last upgraded bullet was either positive or negative angle and then switch
What does green plus mean?
so if last bullet was-3 then next will be + 6 then next would be -6
well this is a code channel. but it indicates it is an override
https://docs.unity3d.com/Manual/PrefabInstanceOverrides.html
so if you're just trying to do like a fan of bullets, then you need to determine the angle of the fan, from that you can determine how many degrees you need to rotate each bullet
fan?
so yes, like a fan
are yeah, when you said fan i tohugh you were thinking top down three in each direction type thing
so how would i go about doing this
what would i use to rotate the bullets. And when you say angle of the fan what does that mean
look at this: #💻┃code-beginner message
now imagine that the two outer edges were the outer bullets.
yeah i get that
the angle between those
but the problem lies in changing the degree of the bullets
in what way
how do i calculate the angle difference
you determine the angle you want them to fire at
then from there it's literally just simple division to determine the amount of rotation needed for each individual bullet
okay
at the moment my bulelts are decided by the angle my gun is facing. How would i add a angle onto transoform.rotation
BulletInst = Instantiate(bullet, bulletSpawnPoint.transform.position, Gun.transform.rotation);
multiply the current rotation by the desired rotation offset
how do i do that? can you multiply a Quaternion
yes
does he want a randomized angle?
How can I stop player from spazzing out when it collided with another object?
You'd need to provide more context
the answer is likely to constrain the rotation on the rigidbody. but yes, more context is needed
Well I got a plane which is supposed to fly through rings. When I fly the plane through the ring, it will like rotate and move when it is supposed to stop.
Im having trouble imaging tgat can you send a video of it
Like in this photo it was supposed to be going straight but when I hit the ring it started flipping itself
constrain the rotation on the rigidbody
The plane is meant to tilt when I move left and right, so wouldn’t that stop it from doing it?
Should it physically hit the ring or simply fly through? You may want to have the ring as a trigger if there isn't supposed to be a collision.
My script checks if the player collided with the ring in which they stop moving and the game ends.
are you rotating it left/right with physics? if no, then constraining the rotation will not prevent that. if yes, then you can either constrain only the axis you don't want it to rotate around, or you need to accept that if physics is supposed to work on the object then it will be affected by physics
I locked the position and rotation of the rigidbody and it kind of works but I am still bouncing off the ring when I hit it
It hits the ring and doesn’t move around like before just moves backwards
Wait nvm fixed it
Tysm 👍
I’m not sure I understand the question, but I like to assign as much as possible in the inspector on the prefab so I don’t have to grab things using GetComponent during runtime. In your script it seems like enemy is the current object, so might as well prepare what you can as early as possible!
my character keeps falling throught the floor and i have tried rigid body and it doesnt work any advice
wdym and you tried rigidbody
there is nothing here that would make this fall through floor
you have a misunderstanding what rigidbody is
thats what gives it Physics
without it nothing falls
make a video of what is happening, because whatever objects you're showing isn't whats falling
ok now screenshot the inspector for Player
you don't have a collider
oh wait
ur mixing character controller too
pick on or the other
wait between what
rigidbody is physics n needs collider.
Character controller works with physics already has collider
i was trying to do a shooter for my friend
but only simple
im just trying to test it out for now
just use character controller so you don't have to deal fighting the physics to learn how movement works
the only difference you have to code your own forces such as gravity
do i still keep the colliders
character controller needs no other colliders
but does the ground
im still falling
let me see your script
📃 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.
!screenshots
No
Be mindful, if someone requests your code as text, don't send a screenshot!
let me see how far is your player from the ground when you start the game
make sure you can see the collider green gizmos lines
make sure both colliders can be seen
how do i do that?
Hold Ctrl and select both objects in hierarchy
select your Player and press F real quick
I have a feeling your Mesh is higher than your main player
you probably only moved the child mesh
thank you how do i fix
well first of all reset the child capsule position to 0,0,0 then move the PLAYER transform until its above the floor
how in the world did u drag all those in different places? 😄
i think i undertsand but he is in he floor
so don't put him in the floor
well raise the gameobject up above the floor..
also keep this in Pivot/Local as to avoid confusions later on
it works thank you so much
one more question sorry
it works but the actual player is still below me slightly is there a way to fuse them
wdym by "the actual player"
fuse what exactly
that is you actual root gameobject yes what about it
is there a way to bring this inside of the capsule
well you're doing it backwards, you should probably do the !learn essentials path before doing anything further
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
i told you before, the capusule is the Child/Visuals its position needs to be 0,0,0 relative to the parent
you don't move parent into a child object
the pathways will at least show you how to do basic hierarchy navigation and whatnot, this stuff is important
sorry man i thought this was the some of the first stuff you should learn ill look more into it
at very least knowing the interface and what everything is yeah
the parent / child relationship is also very important as it plays large parts with each object
Yeah that makes sense. I'm trying to do that as much as I can. With my setup, I'm importing assets that have materials with the color in them so I can't set it up like that. I'd be interested in your thoughts of what I have and if there's a different way of doing it - https://pastebin.com/0UqAtnPJ
I think Unity is doing something weird in the background so this is what I've done to set it up; I don't want to duplicate every material and swap them (too many assets). If I don't set the material to "transparent" in the inspector then it doesn't work. My code gets the settings for all meshes on a gameobject, changes the mode to opaque so that the mesh renders correctly when playing (it will look like you can see through them gameobjects), then when I need to hide the enemy I set everything accordingly.
I’d be happy to take a look if you named the methods and properties to something more verbose and descriptive, it’s hard to understand what you’re trying to achieve from looking at the code right now. For example, you’re not getting meshes, you’re getting mesh renderers. The mesh is a separate concept, the renderer just renders it. And HideMe doesn’t hide anything as such, it just sets a property block on a mesh renderer. The code should read like a short story in a way, so that someone new can go through it and be like ah, this is what the intent is.
Also you don’t need a separate alpha value, Color has r, g, b and a
Cool, thanks very much. I'm still getting used to all the actual differences between the names and things so hopefully it'll stick lol. That's good advice, I will have to think a bit more when I'm writing it 🖖
When I'm trying to make a prefab should I finish all the logic completely for 1 instance before trying to create copies of it using a prefab. My example is making an enemy prefab, should I first finish all the script for the enemy OR if I change the Enemy script, the prefab will change as well? Sorry for the rough explanation
Im making a script to end the game when the player is touching only one of two objects they must pass through. Both objects are placed in the same position so the player will hit both. The player is required to hit one of these objects to continue playing, but if they hit only the other object, the game should end. When I test out my script, the game ends when I hit the objects because they are placed together. How would I only end the game if the player misses the main object they are supposed to hit?
did you set the tags set correctly on each one ?
also you should configure your IDE
The contents of the script don't really matter at all, actually
All that Unity cares about is:
- which script asset each component uses
- what values you've stored in the serialized fields of each component
So no, you don't have to finish writing your code first
Both Have Their Tags
For clearer picture here is what I am looking for
When I hit the two objects it ends it, of course because I hit the purple ring as well.
ohh I see what you mean, you want to hit both but not just purple ?
if hit only purple, end game
Thank you !!
Essentially I am always going to hit the purple ring, which is why I added the hidden green ring. So long as the player hits the green ring and stays within it, they are allowed to continue
Hitting only purple should end the game yes
could I see what the colliders look like
is it spheres or something?
The box collider is the visible ring, the circular ring is the hidden one
I am basically trying to make a "hole" in the box collider to allow the player to pass through
You can't. The box collider is a box.
I know I cant actually make a hole
I see, basically you want that bool to make you "safe" if you hit the inner collider
Yea
that sounds reasonable, assuming the player doesn't turn around and try to crash into the ring
(which they probably will not)
Player is forced to fly forwards with only a certain area to move around so that should not be a problem
Yeah, definitely do that then
You'll have a smaller collider that sticks out ahead of the game-over collider
indeed offset it a little forward
hits first, bool goes safe, now on the second tag check if already safe return
You just need a way to reset the bool back to false once you passed the checkpoint
maybe OnTriggerExit or something
or do it per-ring
do classes inheriting from a abstract class need to use the same namespace as the abstract class?
No, but they have to include it in the usings.
hmm, im not understanding why my state system causes null reference exception errors when a certain line is not commented out
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UnitDrawState : UnitBaseState
{
float stateTimer = 0f;
float drawTime = 1.5f; // temporary, will be based on attack type eventually.
//float randomDelay = Random.Range(0f, 0.5f); // PROBLEM
public override void EnterState(Unit unit)
{
unit.material.color = unit.drawColor;
stateTimer = Time.time; //Start the timer
}
public override void UpdateState(Unit unit)
{
if(stateTimer + drawTime /* + randomDelay */ <= Time.time) // also commented out
{
unit.ChangeState(unit.rangedAttackState);
}
}
public override void OnCollisionEnter(Unit unit)
{
}
}
abstract class:
using UnityEngine;
public abstract class UnitBaseState
{
public abstract void EnterState(Unit unit);
public abstract void UpdateState(Unit unit);
public abstract void OnCollisionEnter(Unit unit);
}
Share the error details
And the !code in such way that we can see the line numbers
📃 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.
like this? https://hatebin.com/pyqtpqdlfs
Yes
Hello, so I have a function that's suppossed to be running every 300ms, but for some reason its ever so slightly off each time. does anyone know what could be causing this? https://hastebin.com/share/jexeviyaha.markdown
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Would OnTriggerEnter work the same as OnCollisionEnter?
it gives me a Null Reference exception error where the UpdateState() is called ;
works perfectly when random number is not generated
Unless your framerate is such that it can land exactly on 300ms, you won't get it to be precise.
not exactly, one is for triggers and one is for solid colliders
you probably want the trigger
I'm still waiting for you to share the error details
that was the error, and I solved it by not generating a random number outside of a function 😩
sometimes brain no work good lol
By error details I mean a screenshot of your console with the error selected
Guess I am not using OnTriggerExit correctly. It doesnt seem to detect that I have exited it at all. Only thing I can think of is that this script needs to also be a component of the hidden ring.
next time I will be better about posting error
Searched up online but not very helpful imo
in what way its not correct?
is there a way could make the next 300ms conpensate for the amount of time the other 300ms went over by then? For example: theres a point where it takes 531ms to debug 1 line, the next line would debug 300 - (531%300)
or would it just always be slightly off no matter what i do?
531 probably means there was a performance spike or an issue with your logic.
It should be off no more than a frame's worth time.
Well I wanted to test if it was actually registering that I am no longer touching the hidden ring with a debug.log, but it does not log it meaning it is not checking if I left it
Maybe simplify the logic such that it really only prints every 300ms and see how it goes.
First things first, do you have a rigidbody on your plane
Yes
and how are you moving the plane in code
does plane have a collider? and are both "rings" collider set to trigger
yeah that wont give you accurate collision manipulating the position directly
Didnt remember to set triggers to on
well both the rings colliders need trigger set on collider, the plane can be solid collider
Ok it is regestering that I left it
but you should not move position directly
set Rigidbody velocity. it appears to work ok but its gonna be jank and inconsistent.
I added in the code to set the bool to false upon exit, but it seems that the inital code that sets it to true isnt working anymore
because your original code was using OnCollision, did you switch it to OnTriggerEnter
Oh no I didnt
Ooo it works
Hopefully now it should end game when it set to false
you shifted the green collider slightly forward btw ? to ensure that always gets hit first to set bool true
Yes it is forward by 3, but it does not log the code where I am going to end the game. Maybe because I have set it too close?
The first log works
Just not the second one
put a Debug.Log(other.name) before the Safe tag comparison if statement
also your IDE doesn't look like its configured
Not sure how to configure it. Will try to get that handled soon
I just noticed something
the instructions are here !ide
(if you did all steps try Regen Project files in unity or you might have to fix it in VS via reload with dependencies)
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
My plane is set to move within a certain distance. I increased how far I could go, which then logged the second code
like I said
you should not be moving rigidbody transforms directly, that also contributes to jank trigger messages
Wouldnt technically shrinking the hiddenRing make it more accurate when colliding witht he actual ring. Since it is nearly the same size as the visible one, it will look that you did hit it but the game didnt end.
Think it actually looks correct. I think it should work how I like. Thank you so much!
!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.
Hey there.
I picked up development on a game that I didn't build. I'm an animator by trade wanting to branch out into designing/coding as well. One of the things I want to do is to take the ultimate move and extend the invulnerability it gives player by a few seconds. Here's the code in question, with a few sections of it removed to avoid discomfort of others.
protected override void OnDisable() {
base.OnDisable();
input.actions["Ultimate"].performed -= OnUltimateButton;
waiting = 0;
attackCount = 0;
doneAttacking = false;
//player.SetFreeze(false);
player.invulnerable = false;
}
From what I know or looked up, I know I need to add a coroutine using yield WaitForSeconds(); But I don't know if it should be written as:
protected override void OnDisable() {
base.OnDisable();
input.actions["Ultimate"].performed -= OnUltimateButton;
waiting = 0;
attackCount = 0;
doneAttacking = false;
//player.SetFreeze(false);yield WaitForSeconds(1);
{player.invulnerable = false;}
}
Or something else...
you'll need to make a separate method and theres examples on the docs below. but considering this happens OnDisable you probably wont be actually running the coroutine.
https://docs.unity3d.com/Manual/Coroutines.html
Read the section on Stopping coroutines, because you might need this coroutine to run on a separate object if you're actually disabling the game object this is on.
this is probably something that should be running on the player anyways
Yeah, I was reading through that page, and that's where I got the yield WaitforSeconds();, but... sorry if I'm not describing or hell, even understaning it well, but this specific section is what happens at the end of the ultimate. It runs the OnDisable thing, which turns off several of the main things it's using. The player.invulnerable state is one I want to turn off as well but just a little later. The problem is that it's lumped into everything else, so I'm not sure how to handle it.
There are several chunks there that I cut out of that section just to help avoid making people uncomfortable. But if need be, I can paste the entire script and you can look through it to see what I mean. I have it in a paste.ofcode already.
Where would I find audio files for say a plane engine or background music?
i understood what you were trying to do, but maybe you should start by just copying one of the examples and running this on a test script. You are missing the actual coroutine part, a method returning IEnumerator and something calling StartCoroutine on it. And my message was to tell you if the game object is being disabled, the coroutine will stop running. This is something you'd want to run on the player, like by having the player start the coroutine.
this is a coding channel
(In case I haven't made this abundantly clear, I know quite literally next to nothing about C# coding. I'm literally only like 5-6 lessons in on codecademy. Sorry for the inconvenience.)
So, to make sure I understand that correctly you're saying I need to create an IEnumerator that will run when the player activates the Ultimate ability, (on.Enable() in this case,) that will then end on disable?
For reference, this is what the two of those look like.
no, if you need the player to be invulnerable from OnEnable to OnDisable, you can simply set the values in each of those methods there. No need for coroutines at all. Your initial question seemed like you wanted the player to be invulnerable for a few seconds after OnDisable finishes.
That is correct
Oh wait a minute, yeah, I just realized that OnEnable isn't where it starts. Would that be part of the problem?
🤷♂️ that depends on your game design. Do you want it to be invulnerable when OnEnable runs?
i dont think theres a better way I can word it than i already have above, if you arent familiar with how to call methods then you'll really want to do some c# basics first. Or at least test how coroutines work on a completely separate test object and just have it print out values from 0 to 1 for example.
Ok, so it doesn't particularly make a difference in terms of the game design, as basically they seem to run at the same time. Also, I do apologize, as it seems OnEnable is actually not even particularly relevant to the parts we're talking about. In this case, it's the section just above it.
void OnStateTriggered(string name) {
if (name == "TypeAttacked") {
if (attackCount < stats.projectileCount.GetValue()) {
Character target = AquireTarget();
attackCount++;
if (target == null) {
OnPostSlam();
return;
}
// Hack, just keep things from ending too early-- let them stack up.
animator.SetTrigger("Chomp");
animator.SetBool("ultAttack", true);
waiting++;
Score.AddDamage(weaponCard, target.stats.health.GetHealth());
attackTarget.Vaccum(target);
//player.SetFreeze(true);
player.invulnerable = true;
//float progress= (float)i/(projectileCount.GetValue());
//yield return new WaitForSeconds((1f-progress)+0.8f);
}
OnPostSlam();
}
This is the section in question. I've replaced certain names that would be sensitive.
Wait a Minute! I just noticed there's a WaitForSeconds in there already commented out for something else!
that commented out part wouldnt run regardless, this isnt a method that returns IEnumerator
Would you like me to just send a paste.ofcode so you could look a bit more at it?
Also, I am still trying to learn on codecademy, But I'm going between doing that and trying to fix/work on this game simultaneously to try and keep both motivation and attention up for both.
honestly this code is pretty bad, im surprised anyone would really require you to block out parts of this. I assume this is a friends project rather than a company NDA.
You can post more of the code if you want but there really isnt anything more that i need to see. It doesnt change what I said about how to run a coroutine. I strongly recommend re-reading what i said above and step away from this code for now. Make a new script, a new scene if you have to, attach the script to an empty game object and just have a coroutine print out values from 0 to 1 over time. Experiment around with it and what you can do. Then once you understand how to actually run a coroutine, come back to this script and apply the exact same logic. Theres nothing special about these methods that changes anything.
The only thing that would affect a coroutines logic is if the object is actually disabled or destroyed. Don't worry about this yet.
You could even start by literally copying the docs in your test code. The example with IEnumerator Fade()
The reason I'm blocking out content is for viewer safety/comfort, rather than any kind of secret. It has more to do with the content and the fact that it is ||A pornographic adult game|| and while I didn't see anything in the Code of Conduct for the discord server here saying that wasn't permitted, I don't want to take any chances currently.
understandable, not really sure either if any words get flagged. I can only imagine what seemingly 3 letter word prefixes "Attack" in that snippet above 😂
Anyways i assume that commented out //yield return new WaitForSeconds((1f-progress)+0.8f); was probably left in there because this method used to be a coroutine. Really dont worry about the current code right now, it is confusing you too much where to put the coroutine when you arent sure how to write one yet.
Four letters actually. xD
And I want to do that, but like I said, I'm going between learning and working on this game to help retain my attention for both. I've been able to successfully fix a number of bugs in the game already, but this ultimate weapon is one of those problems that needs to be fixed ASAP. It has a lot of problems, including that it's not even entirely clear what it's supposed to DO. But this is the most identifiable thing that needs to be fixed.
If you're curious or willing to look through it to see if you can figure that out, here's the full script: https://paste.ofcode.org/vgDzRX6BJPZcw4VMEP4x6e
is there a specific issue thats not working in this code? if you need to delay the player.invulnerable = false; even more then you can always add another WaitForSeconds or similar logic to above where it yield return null while some condition is true.
Outside of that specifically, it's not really obvious in game what this weapon actually does. It's not giving off damage, and I'm not seeing the enemies being defeated by other means. To top it off, it seems to be very weak given the close proximity to enemies it requires you be at. Which is why I can at least identify the invulnerability delay as an issue.
it is kinda hard to help if you arent truly sure what the issue is, or if you cant point to a section and say definitively "this value isnt what its supposed to be" or "this code isnt running". Add debugs in your coroutine if you think its an issue with the invulnerability like at the start and the end of the coroutine.
Also yea theres a lot of logic here that i just dont really have the time to go through to point out if i see flaws
There is also the part i mentioned above, where coroutines will stop running on disabled game objects
A-Hah! Finally heard back from the creator(... After I realized earlier in this convo that i forgot to actually ask...) And it is in fact bugged beyond that invuln issue. It's supposed to ||suck in|| every enemy within a certain radius and it's not doing that.
Hey is Photon 2 PUN in maintenance or it is working to create some multiplayers for a game ?
that's more of a #archived-networking question
Yeah you're right my bad
Hi all, so once again I'm trying to get my head around Scriptable Objects. I'm looking to use SO's for my enemies so just a question if you would indulge me.
Can you assign values to variables in the SO at runtime? In my use case, each enemy 'targets' the player as they spawn, so 'finding' the player on spawn would be necessary.
You can, but you shouldnt really. SO's are mainly just immutable data containers.
Consider what you are doing here, as an enemy spawns you want them to reference the player. Instead of using an SO, the same can be achieved in ways that doesnt involve creating an asset to hold this "middleman" of data. Like when you instantiate an enemy, you are directly given a reference to any component you want. You could easily create a method that accepts a transform (or whatever you wish) and plug in the player data.
I want to also make it clear, what you asked will work but its just like a weird alternative to using a singleton or directly plugging in the data you need. Then every single enemy needs to reference this in inspector when really its always gonna be the same asset
how can I make it so only a single class has access to a variable from an other class?
the only way i can think off, is making the variable protected and put the class you want to use as a child class and make it inherit from the base class
Put them in a namespace and use internal, is what comes to mind
^ is probably better
This works too, just depends how you wanna organize it
not just over classes
basically
I want to have a class called Ability which other scripts can inherit from
if I do it like this then yeah it can just be protected
but like
god this is so fucking hard to phrase
if Ability had a function called void StartAbility() as an example
and I had a script which is inherited from Ability
or like
omg
im struggling so hard
well here, ability would just have access to every single thing inside ActionHandler
You can try to give a code example of how you would like to use it
inheritance like this doesnt really make sense, or its just something ive not seen done.
but I want to have different Ability scripts
thats even harder
I think this just falls into "if you dont want something accessing your variables, just dont give it your class"
although unity does kinda make it easy for anything to grab components, it could just be something you document like "dont GetComponent this and destroy it!!" Likewise how you cant prevent yourself from just randomly destroying every game object in your scene, something which is publicly available to do but you know better
well yea what instance are you trying to call it on?
wdym
im not calling it yet
its literally in the same script
do I need to make StartAction static
that is what your code is trying to do, call it.
im trying to call it in its own instance
then pass the instance into Ability from ActionHandler, an instance of Ability does not magically get created because you create one of ActionHandler
how do I do that then
look at the same thing you do for enums, you have an enum declared at the top there PlayerState. But you also have a
public PlayerState playerState
though really, i dont see why this needs to be a class within a class
StartAction is already public
I had this discussion in #💻┃unity-talk
basically
I don't want to have the scripts for stamina handling and the abilities to be separate
cuz whats the point
at that point the stamina handling script's only reason to exist would be just to store the stamina value and thats it
putting them in 1 file does not change anything here
i wont have to make all my variables public
Putting them in one file doesn't change the access modifier requirements.
then how come I can now use internal and not public
nested classes can access private variables but you also said you want inheritance, im not sure how you plan to handle that
You could always use internal
I think you could really just be fine with this mindset #💻┃code-beginner message
Dont pass around instances if you dont want something accessing that instance's data
Internal allows access in the assembly. Two different files in the same assembly works just as well as two classes in the same file with internal
Now if you put the two different files in different assemblies that's a different story
But that would only happen with assembly definition files or with special folders like Editor
I do need something to access those variables
basically
then pass around the instance to whatever needs it
I want to have a class called Ability
other scripts can inherit from it, and be able to set things such as stamina cost, ability key, cooldown, etc
the other scripts can then write their own behaviour for what happens when that ability gets executed
im guessing ill need override to get the last part going
None of that requires putting the classes in the same file or nesting them
That's just a standard abstract class/derived class setup
Abstract is a class that defines a function such as Execute() but allows child classes to Implement it without providing its own implementation
A derived class is just a class that derives from another class
Like Example : MonoBehaviour
Or MyClass : MyOtherClass
A child class if you will
See example here: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/abstract
You would also use protected so derived classes can access values from the base class
I want something like this
but it says i cant because its contained in a non-abstract type
Yes, you can do that
Yeah because you didn't mark the parent class abstract
and Ability is also abstract then?
you should read up on abstract classes first before guessing at to write though. And hopefully this isnt a nested class anymore
Look at the examples in the link I sent
man this is complicated
yeah no I get it
its exactly what I want
basically have a class that has different uses depending on what it's called by
I just don't get why here it wasn't abstract yet still works
Not by what it's called by.
By what it is
this is from the override part
This is virtual
whats the difference
Virtual is the same as abstract except you provide a default implementation in the parent class
Classes also dont have to be abstract at all, although you likely want it in your case
I could use that too for debugging reasons
but I think I get an error anyway if its not implemented
A class has to be abstract of it contains at least one abstract member
Yes this is the appeal of using abstract. It doesn't let you accidentally not implement it.
good day everyone. I am wondering, if there is a workaround to call interactable = true and false including the button being changed visually? Right now, if you select the toggle in inspector, its working, but by setting interactable to false and back to true does not turn it back on full color for example.
also why doesnt my intellicode realise that I want to use the Input type?
or whats going on here
Yea theres a lot of extra details to type here, like what can be done and when. so I think it's just best if you just experiment with this on test classes to understand it.
thats actually perfect because I never want to have an ability that does nothing
like I could write all this code in a much simpler way
which is what i had until now
but I guess this is good practice to learn these keywords
plus if I get asked in the future to show code that I've written before, like at a job interview, I can look just that much smarter
here comes another issue though
what if I want to make it so you cant use other abilities when you are in the middle of using one?
but I do want to be able to use the same ability
I don't see how that is related to the question of polymorphism
well its less related
but basically if I have 2 abilities, a parry and an attack
I want to be able to continue attacking if I'm attacking
but I don't want to be able to parry
Keep a reference to the ability you're currently using. Don't allow a new one to be used while using one
Just a few if statements and variables
This could just be from the transition colors you set in inspector
I could have an "isBusy" or something inside the ActionHandler class but that wouldnt tell me what ability is being used so yeah
how can I keep a reference?
i dont want to use integers or strings
The disabled color is just alpha 0.5. So it is using that when disabled, but when set backon, its not turning back to normal color
because I could have a [SerializeField] internal string actionName
wait I can do that?
Why not?
I found this thread seems related. https://forum.unity.com/threads/interactable-true-doesnt-change-button-color.472299/
because I am inside of Ability?
oh wait im not
Well first off that wouldn't matter anyway but second I don't see why you would be
This would be some other class
Not really, cause its like the default button. And if you set the interactable toggle via inspector, its updating correctly. there have been bugs about this years before, maybe its still an issue
ability?
Looks like ability is null
Assign a value to it?
What is the point of the ability reference?
Oh this is in ActionHandler, not in Ability
So in the end it was my fault of calling on a timer elapsed event, which is threaded, so I had to enqueue back to main 🙂 Thanks for the help tho!
yeahh
Why would you have that logic in the ability anyway? Shouldn't that be in your ability manager that you mentioned earlier?
You tell us - which ability do you want to use?
oh true i guess
what's the point of abilityRef? If this class is supposed to be a singleton, it should be a static member
its not a singleton
i mean
youre going to have multiple abilities
and i dont want to be able to use multiple abilities at once
The fact that Ability is a MonoBehaviour is pretty sketchy to me
Not sure what the instance management will look like
Also why a separate variable for this?
if i dont have a reference to handler I get an error inside of the classes that derive from ability
What's handler even?
the class that contains Ability
Why does the ability need to know about it?
I mean abilityRef that variable seems really pointless
appareantly it isnt
It definitely is
because the compiler shits itself if i remove it
Define "the compiler shits itself"
also you told me
Yeah if you needed a reference somewhere. In this case you can just use this
But the logic where you're using this variable seems like something that shouldn't be living in the Ability class in the first place anyway
Seems like something that should be in ActionHandler
You already are using this as well where you assign abilityRef
so something like this?
Yeah but again I feel like all that code belongs elsewhere anyway
Most of that logic should be in the ability itself imo
dude yall just told me that having Ability be a monobehaviour is sketchy
how else am i meant to detect input
thats literally what im doing??
Which is what I'm guessing ActionHandler is?
yes
Can't you have multiple abilities?
ActionHandler only has a single instance existing at all times
Isn't this in the Ability class?
I can
check the highlighted text
void ActionHandler.Update()
Last I saw was this which was Ability
Maybe start sharing the !code correctly, so that we don't get confused
📃 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.
well i just sent this
and you said this
The suggestion wasnt even related to input, I was saying that you shouldnt need to check an abilities stamina and cooldown from outside the ability
Misread then sorry
oh, all good then
stamina is a part of ActionHandler
oh wait
i get what you mean
how else am i meant to check if I can cast an ability
I mean I think that's debatable
If they All are always stamina based, this can work.
If this is literally the only place thatll call abilities then sure it's fine. The stamina part I misread I guess, but the cooldown part can just go directly inside the ability class since it's being compared to 0
If you need polymorphic behavior on whether it can be cast that's a different story
ActionHandler
https://gdl.space/uvahilomek.cs
For example by defining a CanCast method in the ability and calling it from wherever you want to cast the ability.
Though I dont see the point of that if ability[0] != this because that should basically always be not equal
an example for an ability
https://gdl.space/cijidewiha.cpp
Sure, they just have to be an instance of a derived class in reality
well rn CanCast is just all of those if cases
I'm assuming you're assigning derived objects to that Ability[]
if(ability[0].handler == null) ability[0].handler = this;
well I certainly want to
I don't like this
Resonance derives from Ability but it isn't Ability
Well, then put them all in the method. The point is encapsulating access. Objects outside the ability don't need to know about specific details of each ability. Only wether it can be cast or not.
idk how to serialize it
if you want abilities to be able to reference the event handler, you can have a static reference to the ability handler in itself
without ever needing to assign the reference to the handler in each ability
Software design by committee let's go.
Alright I'm gonna go about my day.
too many cooks. Ironically, I showed up last
Maybe we should give them some time to figure out how they want to design it first.
if(ability[0] != this){
``` what is this line doing?
This is just worse and throws static at something that doesnt need it
when will an ability ever be of type eventHandler?
there you go
what are you talking about? eventHandler is a singleton
in theory
oh ig that works, ty
Now you can make most of the internal stuff private
I basically want to check if the ability I want to use is equal to the ability being used right now, but that line is messed up completely
I dont even know what code you're referring to. Their code is ActionHandler and it is not a singleton and really doesnt need to be
true ty
ActionHandler is a singleton, if by singleton you mean only a single instance of it exists at a time
I guess a better name would be AbilityHandler
okay I updated the code, ill send it again to keep things fresh
The code you linked is not a singleton. Please google what the singleton pattern is
Guys, the inspector doesn't show anything to know if a default property changed?
which one? I linked 2
ActionHandler is a script that exists on the Player and is responsible for handling all the abilities
like I said, singleton in theory
there can only be one of it at a time
am i missing a keyword
objects deriving from Ability, however, are not singletons
you can have multiple Ability scripts
Literally nothing you've linked has a singleton in ActionHandler. Although I truly dont feel like trying to correct another person's questionable suggestions as it just feels like working backwards. Really assigning the reference directly is better but I too will step out now.
i dont understand
having a static instance of a class, and an assignment to it in Awake, and a check to prevent multiple instances from existing at once is enough to fulfil the design pattern, right?
if im making big log file does it matter if i gather info in string[] or string
Although I truly dont feel like trying to correct another person's questionable suggestions as it just feels like working backwards.
what is your suggestion then?
You can google what a singleton is, yours simply isnt one and does NOT need to be. You are already directly telling the ability what the handler is, so the suggestion to randomly throw in static there achieves nothing. Singletons shouldnt be used purely because you dont want to assign a reference properly.
Keep the handler part as is if the ability even needs it. That doesnt need to change
As in gather to write it to the file? You should be using a Stream and StreamWriter to write them sequentially, that does not overload your memory
shouldnt be used purely because you dont want to assign a reference properly.
it's not?
ok other question whats better writealllines or writealltext
You're evading the problem
im evading code i cant use
to be fair I only really need it for one line
None, if you plan on writing a lot of text
ill remove the static part
also i still dont know how to get a reference to the scripts that are derived from Ability
That's definitely not where you would even want it to be static. Theres more pressing issues to worry about though like actually implementing your abilities. One thing I'll reiterate before I gotta go is that this likely shouldnt be a nested class. This will just be more annoying in the future if you want like AI to use abilities too since you wouldnt be checking if via Input
AI wont be using abilities like this
like actually implementing your abilities
that's why I have theAction()
I can tell the ActionHandler what to do like that whenever I want to use an ability
but yeah how can I get a reference to Resonance?
yep
are you able to click and drag the monobehavior to the array slot
damn im stupid
yeah ty
also, do I even need to have Resonance as a monobehaviour?
you had the assets submenu(?) thing open instead of scene
couldnt I just have a script that I put there from assets?
I personally use scriptableobjects for this exact case
no it didnt show up there either
yeah thats a scriptableobject moment
what
No you need an instance of the class
That error is likely because you changed it from a monobehaviour
well i cant drag it in anymore
I changed Ability not ActionHandler
but it fixed after I made Ability be a ScriptableObject
yeah idk i think its better to keep it a monobehaviour
yeah using MonoBehaviour it works
yeah ive no clue
still @eternal needle tysm for the help
also @teal viper @wintry quarry @wheat wave @verbal dome thank u all very much
Okay cool. Thank you. Yeah I'm currently holding my enemy stats data (speed, health, damage dealt etc) in the SO, so was just curious if it would be more efficient to hold the 'target' data in there as well (I currently have the target inside the Enemy script)
does anybody know my I'm getting thousands of these errors in my console? I haven't even ran my code
hey
Restart the Unity Editor. Likely memory leak from a previous play session crash
i need some serious help
consider there is a children assigned to the transform of every gameobject
now i get the transform of a gameobject
and loop through its childrens and display their names
but it would only show the childrens of that transform
not the childrens of the transforms which i got from their parent transforms
i want to create a loop that will show me the names of all childrens in the transform and then their childrens as well until there are no children left
how can i achieve something like that?
recursion 
how does that work?
any examples
You have to enumerate through all the Transform's children, get Transform of every child and call the method on them
for example?
Level 1
- Level 2
- Level 3
- Level 4
- Level 5
- Level 6
- Level 4
Level 1
- Level 2
- Level 2
_ Level 3
-
In this case, Level 1 is the original transform
You enumerate through its children, which are Level 2s
yep
it only gives you level 2
you cant run a loop
such that it goes on and finishes on level 6
Then you call the enumerate method for every Level 2, then for every Level 3 inside of them and so on
private static void EnumerateThru(this Transform value)
{
foreach (Transform child in value)
{
child.EnumerateThru();
print($"child: {child};");
}
}
is this possible
This is already the whole method to print all the names of the children
to run the same void inside a void
Yes, why wouldn't it?
waaaaah
never thought of this
haha
thanks
you put me out of my misery
its not really transform
its a pretty complex thing which i am trying
Also make sure you have mentioned my edit. value.EnumerateThru() was a typo.
but it pretty much looks like unity transforms so i gave example of transform
Well, its the same for whatever you have. Just make sure you now how to enumerate through a single level, then call a recursion
AssetTypeValueField GameObject = manager.GetBaseField(afileInst, Info);
// #Transform
{
AssetTypeValueField data = BaseField["m_Component.Array"][0];
AssetPPtr pptr = AssetPPtr.FromField(data["component"]);
if(pptr.FileId == 0)
{
AssetTypeValueField transform = manager.GetBaseField(afileInst, pptr.PathId);
}
}```
this thing pretty much works like unity transforms
so yea
anyways thanks for the help
its really appreciating
Hi, does anyone know why my code does not work?
void OnMouseOver()
{
Debug.Log("Mouse Over");
if (currentScale.x >= originalScale.x * (1 + scaleModifier) && !invertCheck)
{
bounceSpeed = -bounceSpeed;
invertCheck = true;
}
else if (currentScale.x <= originalScale.x && invertCheck)
{
bounceSpeed = -bounceSpeed;
invertCheck = false;
}
currentScale = new Vector2(currentScale.x + (bounceSpeed * Time.deltaTime), currentScale.y + (bounceSpeed * Time.deltaTime));
transform.localScale = currentScale;
}
```It doesn't even print the "Mouse Over".
I have it on a Button on a Canvas. I made sure to also add a BoxCollider after it didn't work the first time.
Is the Button on a Canvas?
Yes
The method OnMouseOver only works when you have a Collider and a suitable layer
The OnMouse methods do not work for UI objects, you need to use the IPointer interfaces
The Internet suggests
You don’t use OnMouseOver for UI elements, use IPointerEnterHandler
I tried that before unsuccessfully, but I'll try it again. Is there a quick guide on how to use it to check a hover over instead of whether the mouse is moving?
Yes, derive from IPointerEnterHandler and implement its method by clicking Alt + Enter while hovering the interface with the error
Thank you very much!
Okay so it only checks when the mouse enters, not when the mouse is over the GameObject. How do I do that?
if you want to do repeating work during mouse over.
Start a Coroutine on PointerEnter
Stop the Coroutine on PointerExit
Pretty good idea. I would have suggested a bool to be set true on entry and false on exit with some code evaluating said bool in Update.
works just as well, i find Coroutines cleaner for this kind of thing
I don't know coroutines and never worked with them so I will use Dalphat's solution. Thank you!
pretty simple really
Coroutine cor = null;
void OnPointerEnter() {
if (cor != null StopCoroutine(cor);
cor = StartCoroutine(OnPointerOver());
}
IEnumerator OnPointerOver() {
while (true)
// Do stuff
yield return null;
}
}
void OnPointerExit() {
if (cor != null) {
StopCoroutine(cor);
cor = null;
}
}
Is that essentially a second "Update" that can be started and ended at any time?
you got it
Ah okay! Thanks, I will try that!
How complex of a problem is it to be able to get the two zombies behind to go towards those spots?
I forgot the yield return null; part and now my Unity Editor is frozen and won't come up. What do I do?
use the VS debugger to break the loop
and, sorry, that was my bad, I forgot it first too
although IEnumerators should not compile without a yield statement
can anyone tell me why the points system doesn't work
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Objectbehavior : MonoBehaviour
{
[SerializeField] GameObject prefab;
bool _gameOver = false;
int _points = 0;
public void spawnObject()
{
Instantiate(prefab, new Vector3(Random.Range(-8f, 8f), 6f, 0f), Quaternion.identity);
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Player" && !_gameOver)
{
spawnObject();
Destroy(gameObject);
_points += 1;
Debug.Log(_points);
}
else if (collision.gameObject.tag == "ground")
{
_gameOver = true;
Debug.Log("GAME OVER! YOU LOOSE!");
}
}
}
Does the point system not work or do you simply get no collision detection?
point system
If you're wanting points to persist between instances, you ought to have something that isn't destroyed hold the point variable.
The dirty solution would be to have points be static and assigned in Start - bandaid solution.
bool canMove = !Physics.Raycast(transform.position, moveDir, playerSize);
if (canMove)
{
transform.position += moveDir * moveSpeed * Time.deltaTime;
}
im trying to prohibit to passing into the wall but i cant see any problem but still can pass through to wall
raycast may be originating inside of the wall
but how can i fix that
any advice ?
well, are you sure it's detecting the wall at all first
yes
idk what should i do
wall isnt detecting
what I would do is make a larger raycast and make sure it's pointing in the direction you're moving
and debug that it's hitting something first off
i fixed with decreasing value of movedirection * movespeed and delta time
if (canMove)
{
transform.position += moveDir * moveSpeed * Time.deltaTime;
}
else
{
transform.position -= moveDir * moveSpeed * Time.deltaTime;
}
Debug.Log(liquidType.maxFill / liquidType.viscosity + " this is min fill");
"maxFill" = 1f", and "viscosity = 9" why does Unity somehow output 0.133333?
I understand there is a float point error but where does Unity pull the 0.133333 when the true answer should be 0.1111111, even if it's not fully accurate an entire 0.02+ off seems excessive.
this is not floating point error; your numbers must just be wrong
oops, wrong reply
verify that your numbers are actually what you think they are
I'd just let the zombies shove each other a bit, tbh
I have checked prior, but I will triple check with the results quickly.
log the values immediately before you use them
Yeah no you were 100% correct, I am realizing the reason my prior checks weren't working is since I was checking in a class declaration even though the actual "maxFill" was altered in a scriptable object which was actually being evaluated as "1.2" even though the class declares "1.0" initially.
Appreciate the help!
that'll do it (:
Log early and often when you're getting weird behavior like that
(or attach a debugger)
Yeah, I didn't even think to question that declaration ahah. I was very misled by ai when asking the same question which was saying that it was very likely floating point error. Which I was thinking if true would be insanity haha!
GPUs can emit a lot of very creative text.
haha, that's for sure!
AI can be extremely insightful and give some pretty good direction on where to go a lot of the time, and other times it assumes my code is Chinese and will respond in Chinese, there is a lot of variability lol.
Hello, Is making an idle game easy? I have a slight programming knowledge but on game development im still a begginer.
conceptually yes, but any game you decide to make can be as difficult to develop if you'd like it to be. There's a lot of documentation which can push a beginner to creating an idle game if that's what you'd be referring to.
idle games have the advantage of not involving movement, physics, etc.
However, if you're using Unity a lot of people struggle with UI which is 90% of an idle game.
at least, they don't have to
UI is actually pretty easy if you take a bit of time to read the manual 
Unity doesn't help with its bad defaults, though
layout groups should absolutely not default to force-expanding children
Haha, I agree. I actually quite like creating UI, however a lot of beginners I've spoken to seem to unanimously dispise creating UI seemingly haha.
all you need to know is:
- RectTransform anchors and pivots
- LayoutGroups and LayoutElements all the way down for auto-layout
The problem is that these bad defaults make broken UIs kind of work
until you do something that makes them fall apart and explode
and then you have to fix all the bad defaults to get something that actually behaves
Haha, yeah.
setting transform.right or transform.up to a direction will rotate the transform
Hm how do i set them up tho?
set what up?
to make 1 object face the other mathematically id assume youd do this
?
as the simplest way
hey guys, i have a little question
how i create a simple script for instantiate any props like a Tetris in 2D game ?
i'm begginer 😅
theObj.transform.LookAt(otherObject)
this is 2D
oh
then
theObj.transform.right = (otherObj.position - theObj.transform.position);```
positioon
Just make sure that both objects have the same position in the z axis
wouldnt the trig method work too?
sure but - then what do you do with AngleToRotate?
feed it into more stuff
I like to keep it simple
if you don't know how to instantiate things at all, you should be using !learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Wdym the obj and the other object ?
how do i get theobj do i just do gameobject? or give it its own self?
You said you want to look at another object
So surely you know what object you want to look at, right?
theObj is the thing you're rotating. If it's the object your component is attached to, you can just use your own transform
theObj is the one that looks
otherObject is the one being looked at
If you want "itself" then that will just be transform in a script attached to it
Mhm let me try
transform.right = (Player_Object.position - transform.position);
like this?
but if this is 2D as someone said above you'd want more like this #💻┃code-beginner message
but im getting an error with that
what error
ive added these buttons, resume should disactive the menu and quit should make you go back to the main menu but the buttons when i click them it doesnt work. i did the same thing in another scene and the buttons worked.
Player_Object.transform.position
the error is gone wait
I don't see an Event System in your scene
GameObject -> UI -> Event System to add it
it works tysmmm i learned smth new lets go
ive added it and it works thanks a lot i didn't notice that
Uhh hi
as someone who's not familiar with Unity's Syntax at all
Where should i start?
Should i memorize every basic command or there's a place where i can find the syntax that i need to do what i want?
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
ok thx!
Hello I have a problem with a collision script : I have an invisible box and a player. I want the box to teleport the player somewhere upon contact. In solo mode, everything works because the player is already on the scene. However, in multiplayer mode, since i use Photon 2 and my player is a prefab, it doesn't work since the players aren't on the scene yet since i have to spawn a player each time someone logs in the room. Here's my code for the collision script and if someone could help me i'd be grateful.
The person who prepared the video has three places in the on value changed section. The object with a piece of code is the name of the second function, but I also have a place where it says 0. I guess that's why I can't print the slider value on the screen properly.
Why do I have 4 parts and the guy has 3?
Unfortunately I'm using CharacterControllers and not rigidbodies
Hey im trying to make interract two prefab together, so I put them as siblings of a prefab "ball+ui", but when I do .Transform.GetChild(0) and .Transform.GetChild(1) to interract with them it uses the two prefab that are outside my "ball+ui" so I can't make them interract together, anyone got any ideas ? 
Hey all, I'm having a really weird issue and I'm not sure what the problem is, as this was working perfectly as of this morning.
I have a turret controller that points at the player. The problem is, the whole turret (base and turret) rotate to face the player, and I'm really at a loss as to why.
Turret Controller Code
https://hastebin.com/share/uwiluxadux.csharp
Turret setup image attached.
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Aaaa I think my problem is a photon problem so im going to #archived-networking
Assets/Scripts/CustomNetworkManager.cs(6,26): error CS0115: 'CustomNetworkManager.OnServerAddPlayer(NetworkConnection)': no suitable method found to override
using UnityEngine;
using Mirror;
public class CustomNetworkManager : NetworkManager
{
public override void OnServerAddPlayer(NetworkConnection conn)
{
base.OnServerAddPlayer(conn);
if (numPlayers >= 2) // 2 veya daha fazla oyuncu olduğunda sahneye geç
{
ServerChangeScene("SetGame");
}
}
public override void OnServerSceneChanged(string sceneName)
{
if (sceneName == "SetGame")
{
// SetGame sahnesine geçildiğinde, burada oyunu başlatma veya ayarlama işlemleri yapılabilir
// Örneğin, SetGameController'dan seçim UI'sını etkinleştirmesini isteyebiliriz.
GameObject setGameControllerObj = GameObject.FindWithTag("SetGameController");
if (setGameControllerObj != null)
{
SetGameController setGameController = setGameControllerObj.GetComponent<SetGameController>();
setGameController.EnableSelection();
}
}
}
}
can someone help me i cant figure out my fault
As it says, you're trying to override a method that doesn't exist or doesn't match the signature you're using on line 6
ok, a method signature is the method declaration in the code.
the base is NetworkManager.
so post the NetworkManager.OnServerAddPlayer declaration
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using System.Diagnostics;
public class NetworkManager : MonoBehaviourPunCallbacks
{
void Start()
{
// Connect to Photon servers
PhotonNetwork.ConnectUsingSettings();
}
public override void OnConnectedToMaster()
{
Debug.Log("Connected to Photon servers");
}
public void CreateRoom()
{
PhotonNetwork.CreateRoom(null); // Create a room with default room options
}
public void JoinRoom()
{
PhotonNetwork.JoinRandomRoom(); // Join a random available room
}
public override void OnJoinedRoom()
{
Debug.Log("Joined room");
// Load your game scene or lobby scene 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.
No it doesn't. You'd have to launch separate processes
damn
It supports multi monitor but not multi window
And do you see a method called OnServerAddPlayer there?
idk how to go about changing this then ty for the info
No
I am using Mirror but this code import photon?
Do you understand even basic C# ?
Yes i got the error there is no OnServerAddPlayer there
the NetworkManager code you posted is Photon but it is not in a namespace, why do you have Photon scripts in your project if you are using Mirror?
why does my Vector3.Lerp stop at 5.9998 instead of 6?
because you're lerping wrong with time.deltaTime * sumNumber I bet
I really don't know about this.
exactly
https://unity.huh.how/lerp/wrong-lerp read this
okay thank you
So you dont understand even basic C#. Why are you even trying to do networking?
this is for my final project
i dont even make games
Im just working on Java Spring boot
Im not fan of C# and Unity
We can tell
Then I suggest you go and do something else because you will get nowhere like this
Submit deadline is tomorrow 
Well, you are not likely to make that deadline. Sorry
Seems rude of them to give you a project like this with no teaching about unity or c#
yes our lecturer did not use Unity even once in class only made us watch videos.
another quack then?
thats why i dont understand anything
there is no way you were given a Networking project without a great deal of tuition
Listen, even very experienced game devs quake in their boots at the mere mention of networked games
on a scale of 1 to 10 in difficulty they rate about 1,000
using Mirror;
using System.Diagnostics;
public class NetworkManager : NetworkManager
{
void Start()
{
// Start the network client
StartClient();
}
public override void OnStartClient()
{
Debug.Log("Connected to Mirror server");
}
public void StartGame()
{
// This method could be called to start the game once all players are connected
ServerChangeScene("GameScene"); // Change to your actual game scene name
}
public override void OnServerAddPlayer(NetworkConnection conn)
{
// Override this method to handle player spawning
GameObject player = Instantiate(playerPrefab);
NetworkServer.AddPlayerForConnection(conn, player);
}
public override void OnServerSceneChanged(string sceneName)
{
// Override this method to handle scene changes on the server
if (sceneName == "GameScene")
{
// Perform game setup logic here
}
}
}
it aint gonna happen buddy boy
Theres definitely something else going on here lol, the professor definitely wouldnt tell the class to make a networked game when the course didnt even teach c# or unity. You must've chose this yourself
private void Update()
{
Vector3 target = pointB;
Vector3 currentVelocity = Vector3.zero;
transform.position = Vector3.SmoothDamp(transform.position, target, ref currentVelocity, Time.deltaTime, maximumSpeed);
if (transform.position == pointB)
{
target = pointA;
}
}
it goes to pointB successfully but then it wont go back to pointA for some reason
Did he?
I don't want to be rude, but you literally cannot get to where you need to be from where you are in 24 hours. So just stop
And you chose unity? Theres absolutely no way they said use unity and the whole class doesnt revolt against this and go to the dean.
show the assignment then
lmao what
Add a debug to see if it ever enters that if statement
okay
it does enter the if statement
At this point you are just being a troll
Can I use the Animator to call functions using UnityEvents somehow?
well yeah, Animation Event lol
I've seen this but im not sure how to use it
you dragged in the script from Project, you need to drag the object that has the script
Multiplayer phone game for four and a half year old girl
Only the network communication technology will be mirror and will work in the local network. In the network, the client will be able to find the server. There are codes for this in the mirror
Those who use libraries other than Mirror or those who do not use any network remain the same.
On a smartphone, the game should fit well on the screen and the interface should not be overwhelming. There must be at least 4 levels and each level must be one level harder. If the game is time-based, the time should be optimized, neither too fast nor too slow. Two people must be in the same game. There may be other styles of play, such as against each other or both against a common enemy.
However, in order to unite the players online, an intermediary server that uses a technique called network punchthrough is required. For this, you can use a unity service called relay server.
You can search for unity relay server and see the details.
We want a local network in the final assignment. The other player must be able to find the server on the local network. Mirro has the necessary sample and source codes for this.
So they will not communicate by entering the IP number.
Lol
Check the first line in the update method
it wont let me, im in the animator
oh thank you lol
didnt notice that
wdym it wont let you
Xd
Not gonna lie my brain skipped over that one
has the script that I want to call a function from, right?
the object that has the script
drag that one, not the script from project folder
yes
Ask other classmates cause this is very weird
that was the original question
well yeah but its confusing question
I thought you first wanted Animation Events to call a function lol
Can you ask your teacher then?
nope
He didnt know
😸
There is why im asking here
well that doesnt work either tbf?
it does work, what are you trying to do exactly
altho im pretty sure im misunderstanding
You cant drag scene event because the Animationstate is isolated from scene
yeah I know
still tried tho lol
what do you mean then by AnimationEvents
or like
You have to modify the version of the animator thats on the object
how can I make it so at a specific point in an animation, a function from a script gets called
version of the animator?
yes the Instance thats playing the controller
aka the gameobject that has the animator
when you do so it will give you a dropdown of all the methods that are on a script on the same object
yeah cause its read only
its part of the FBX
clone animation clip to modify them
that sounds really bad
or just make the FBX read/write
this is a specific unity thing that has nothing to do with animator, its how FBX are packaged
how can I do that
Please help me about NetworkManager 😿
you should be able to just select the FBX and in the inspector check read/write
Tell him that this is beyond the scope of what you can do and will not be completing it. It is inappropriate to assign an assignment based on something that has not been taught and without being explicit about prerequisit knowledge before the class starts.
Tell him you will be taking this to the dean if he doesn't remove this assignment from your grade
would this mess anything up when updating the fbx?
no but if ur paranoid just duplicate the clip u want to modify
lol after that im getting FF
now i cant even do anything
Then take it to the dean
the animations are still readonly
after you made it read/write ?
just duplciate the clip then
Hang on, how can he assign a project, and then expect to grade it if even he doesn't know how to do it? I smell bullshit tbh.
cause its a troll post
wasting time and flooding chat
doesnt that mean that if I decide to update the animation, I'll have to delete the duplicated clip, re-duplicate the original clip and then set up the events again?
Yeah, pretty obvious.
BECAUSE U HAVENT TAKE LECTURE IN TURKEY
Stop
Go to the dean. You WILL NOT receive the help you need here. It is beyond what we can do
yes
Any game in 24 hours is virtually impossible (I stress virtually).
let me see if I missed something on how to make animation not-read only directly in FBX
yeahh fuck that I'll just use an animatorhandler like I did before and just use import events
Imported animations are read-only unfortunately. There are a couple of assets iirc that 'unlock' imported assets.
this isn't a big deal if you really break it down, how often will you be changing the FBX
I would avoid this at all costs.
It means that if you modify the animation, you have to completely replace the existing animation clip asset
Now all of your references to it are broken, since you deleted the existing asset
I guess you could manually copy all of the new data into the existing asset
Look at the model importer.
specifically, the Animation section
You can attach animation events to the importer animation clips there.
You can also configure stuff like Loop Time, add custom curves, etc.
I never pull animation clip sub-assets out of imported models.
i have a different method for it
I already had events working
I was just hoping i could do it easier
what could be easier than this?
yeah thats what im doing
I just need to have this animator thing which actually calls the function
i cant directly call any function sadly
i wish you could somehow reference without this workaround but yeah
You never "directly call a function".
If you get a dropdown to pick a function name from (I believe that appears when you're editing an animation clip with a specific animator selected?), that's still just filling in the Function field
whuh
its the same thing, one gives you a dropdown and one doesn't
dropdown shows up when you selected the animation when you have object with said Animator selected
Either you haven't applied your changes in the importer or you're using the wrong animation clip
Or you have multiple animation events
i forgot to apply appareantly
i didnt even know it allows you to enter playmode without applying import settings???????
It only complains if you try to leave the importer settings.
(and you have to manually apply them because that triggers a re-import of the asset)
You aren't directly editing the animation clip. You're editing settings on the importer.
and i left them too lol
i entered my gameobject thing multiple times to check other stuff
normally it prompts you
actually, I also got a warning when I tried to enter play mode with unsaved changes