#💻┃code-beginner
1 messages · Page 40 of 1
jinx
probably alongside a Scroll Rect
thanks guys
got fixed , thank you for your time! THANK YOU! 😘😘🌹🌹🌹🌹🌹🙏🙏🙏🙏
a simple solution but annoying problem for noob like me 😅😅
i changed it to 20f and got fast
It seems weird that a speed of 12 was no faster than a speed of 6
Here's a hail mary: do you have "Apply Root Motion" checked on the Animator?
I am wondering if your walking animation included root motion that was making the animated object move forwards.
That could make you appear to move faster than you should while walking
is posible that animation speed is problem?
Animation speed should have nothing to do with movement.
But if "Apply Root Motion" is checked and only the walking animation has root motion, that could cause this weirdness
It would also make you appear to spin around really fast when turning.
i download both from mixamo , but ill check it with root motion
unless the animated object was the root of your character, in which case it'd just speed you up
Mixamo animations can definitely have root motion.
so:
- uncheck "apply root motion"
- set the run speed back to 12
- see how it feels now
sure
Root motion lets you move a character directly with animations. It can give you very realistic movement -- you aren't trying to match the animation to your own fixed move speed.
super useful for things like dodge rolls, too
I updated the script to this. The player has the right tag, and it has a box collider and Rigid body. The object with the collision logic also has a box collider with trigger on and a rigid body. A script as simple as this has never not worked for me. I have no clue whats wrong
But if you aren't intending to use it, you can get surprised
i did this and is much much faster than before
So running is now twice as fast as running?
wait i fixed it
yes
Ha, so that was it!
If you look at the animation clips, the walk cycle should make the preview model actually walk forwards
whilst the run cycle should not
😁 😅
You can either turn off root motion entirely, or you can check the "Bake..." options on the animation clip
Even when using root motion, I don't want my idle animation to make a character slowly slide around
so I check all the boxes
or else this happens https://www.youtube.com/watch?v=v2nRW3wKnVY
Twilight Princess has a speedrun that takes 25 hours called Low%, an incredibly strange speedrun with some interesting glitches used to complete it!
Follow Our Twitter: https://twitter.com/LowestPercent
Edited by: https://www.youtube.com/Gymnast86
link's "got an item" animation has a very very tiny bit of root motion
he slowly slides away
When you do this, the animation can still make the character model move around, but it won't move the object the animator is on
that's the key thing
if an office chair is the object, then root motion is rolling the chair around
non root motion is getting up and walking around your room
oh okay, thank you !
let me annoy you a little more with my questions :
i want my character change direction as my carmera dose .
im using cinemachin: virtual camera
how should i do that?
So you want the character's back to always face the camera?
one option would be to just rotate the character, and have the camera stay behind the player
alternatively:
transform.forward = Camera.main.transform.forward;
This would make your character face in the same direection as the camera. But that would be wrong.
Tilting the camera down would make you fall over
Vector3 forward = Camera.main.transform.forward;
forward = Vector3.ProjectOnPlane(forward, Vector3.up);
transform.forward = forward;
This will get rid of the up-and-down part of the vector
also, to make your character move in the right direction, since I bet you're wondering about that...
transform.TransformDirection(movementVector);
no i want if my camera turned right my character go that way .
just like resident evil third person games
This will convert movementVector from local space to world space
So if you hold W, the character moves in their forward direction
I'm pretty sure those games have you control the character
the camera just follows behind
so how should i make that possible .
with character control component?
The CharacterController doesn't really care abour rotation
So you'd just be rotating the player separately
I would suggest storing a float
That float will be the angle the character is facing.
use your X-axis input to add to the angle
then do transform.rotation = Quaternion.AngleAxis(angle, Vector3.up);
AngleAxis takes an angle and an axis and gives you a rotation
Someone know why I can't see my bird when im in game but in scene?
thank you i'll do what you said.😘 🌹
again thank you for your time . 🙏🙏
i annoyed you too much!😅
and thank you for your explanations i've learnd the things that i didnt knew.
no problem (:
i presume this is a 2D game
you need to provide more context or it'll be hard to help you
Perhaps the sprite has a weird Z position. It could be behind the camera
Yes, sorry for the little context. The sprite has 0 Y and camera 0Y
Y doesn't matter. Z does.
I'm talking about the Z axis.
That's the one that points into the screen in a 2D game
I meant Z sorry
Turn off 2D mode and have a look at your scene
If they're both at Z=0, then that won't work
the camera has a minimum distance before which nothing gets rendered
Put the camera at Z=-10 or something like that
I think the problem is that I added a gravity system so it just falls down so fast
Since when I play it looks like this
well, that also sounds like a problem
but if the camera and the bird are both at the same Z coordinate, you'll never see the bird
Fix that.
So now see about that gravity thing
pause your game, then hit play
I did that now
You may have a script that warps the camera to Z = 0, if you wanted the camera to follow the player
This is the only script I got
hello, in the video is code i wrote that check if a scene is the one loaded and then sets a bool to true, then if the bool is true it prints "interactable", i made it so the if statements only ran once using a bool to detect it, so why does it print "interactable twice? any help or direction will be appriciated, thanks
You likely have two instances of this script
i just checked, thats not the issue, there is only one instance in one scene, and the object with the script has dontdestroyonload so it moves on to the other scene
is it possible that the dont destroy on load resets the script?
If the new scene also has a copy of this object then you do have two. The one in the new scene and the DDOL
the new scene doesnt have a copy, it only gets it when the scene is loaded and the object from the last scene comes into the new one
and whenever there are two of the same, i made it so one gets destroyed
could it be that unity reads the script before destroying it?
Show the !code for it
📃 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.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DDOL : MonoBehaviour
{
public GameObject ab;
// Start is called before the first frame update
void Awake()
{
DontDestroyOnLoad(ab);
}
// Update is called once per frame
void Start()
{
int numberOfTaggedObjects = GameObject.FindGameObjectsWithTag("mainCanvas").Length;
DontDestroyOnLoad(ab);
if(numberOfTaggedObjects > 1)
{
Destroy(GameObject.Find("mainCanvas"));
}
}
}
the object that holds the script is the mainCanvas, this is the script that moves it from scene to scene and destroys it if theres a clone
you're finding things with a tag
then destroying things with a name
that seems odd.
yes since when you find things with tags it gives you all objects with that tag, i used name because i only one to delete one of the maincanvas, so theres one left as there should be
Also, if you ever have three objects at once this breaks. You would queue up three destroys on the same object
its impossible that there will be three objects, thanks for the heads up though
any idea if thats what causing the script to run twice?
probably because you have it twice in your scene
so how do i destroy the object before unity reads the script inside it
or is there a way to check if a script has already ran before?
wait
first of all, why the heck do you need a canvas to be DDOL? To your question, you would check in Start if an object with the tag mainCanvas already exists, and if it does you destroy yourself.
I assume not both objects get instantiated at the same time, right?
i need a canvas to be DDOL since u can opnly DDOL a root gameobject, so i had to get a canvas since i need multiple objects that are sprites, so they have to be inside A canvas
right
Explain what you're trying to make your game do here.
okay
im trying to move the maincanvas from scene to scene, since it has the player in it and all of the achievment ui, and i need that data to move between scenes, so i made it DDOL, i think the problem is that when you first start the game, the maincanvas already becomes a DDOL, therefore when you go back to the scene there are two canvass and the script runs twice, so it there a way to make the object DDOL only when you are not inside the first scene? is what im saying making sense or do i need to rephrase it
Your component should check if an instance already exists. If one does, it should destroy itself.
Awake isn't going to run many times on DDOL'd objects' components
It runs once, when the object is first created.
yeah i used awake just beacuse i didnt know what it did, i deleted it, the DDOL command is in the start function now
the thing is
Awake and Start will probably both work fine.
But what you can't do is just grab a random object with GameObject.Find
I'm not sure which object that'll wind up grabbing
yeah
is ab the object holding the canvas?
ab is the maincanvas yes
you should make a static field that references this canvas. If it equals null, put the canvas in there and DDOL it
If it's not null, destroy your canvas (and yourself)
Now, even if you create many copies of this thing in the scene at once (which probably won't happen), one will get moved into the DontDestroyOnLoad scene and the rest will be destroyed
This logic fails if two are created simultaneously, even if we ignore the part where it just calls GameObject.Find
one gets created at the start of the scene, when i press play, the other is the one that comes with me to every scene
what if i make it so when you press the move scene button the maincanvas gets destroyed so that when you come back its not even there?
if you can create a new one every time you load a scene without losing any data, then sure
one sec, im completely lost, nothing works, so we took it down to the issue where there are two canvasas in the scene after you load back, so is there a way to make sure theres only one canvas in the firstplace? so that i dont need to use destroy, so that the canvas wouldnt even be there and the script wont be called twice, im sorry i know this is confusing but im not really sure how to phrase what im saying, i just think if the second canvas iisnt there in the firstplace it would be easier
what part of this is unclear to you?
i dont get what you mean by put the canvas in there and ddol it
what do i do in here
public static Canvas canvasInstance;
public Canvas myCanvas;
void Awake() {
if (canvasInstance == null) {
canvasInstance = myCanvas;
DontDestroyOnLoad(canvasInstance.gameObject);
} else {
Destroy(myCanvas.gameObject);
}
}
something like this
I'm assuming that this component is attached to the same object as the canvas. If not, then it should also destroy its own game object afterwards, I suppose.
my dear freinds i need help with this,my code is executing a bunch of particles and I just want to generate one,the code: public bool isInFire = false; public GameObject fireParticles; private GameObject fire; if (isInFire) { fire = Instantiate(fireParticles, transform); if (!fire.active) { hitsReceived = maximalHitsToDestroy; } }
well, since you haven't shown any context, it's hard to say much
please share the whole script
ok
I'm guessing that the code is getting run many times, thus spawning many fire particles
ill run the script and see what happens, thanks
public GameObject explosionParticlesPrefab;
public int minimunHitsToDestroy = 6;
public int maximalHitsToDestroy = 12;
public int hitsReceived;
public float impactForceScale = 1.0f;
public float velocityOfImpactForExplode = 7f;
public float velocityOfCollisionByObject = 4f;
public bool isInFire = false;
public GameObject fireParticles;
private GameObject fire;
public int random;
public int random1;
public int random2;
public float maxDetectionDistance = 10;
public float maxDetectionForce = 5;
[System.Obsolete]
private void Start()
{
random2 = Random.RandomRange(1, 5);
random1 = Random.RandomRange(minimunHitsToDestroy / 2, maximalHitsToDestroy / 2);
random = Random.RandomRange(minimunHitsToDestroy, maximalHitsToDestroy);
}
[System.Obsolete]
void Update()
{
if (hitsReceived >= random)
{
//if (random2 <= 3)
//{
Instantiate(explosionParticlesPrefab, gameObject.transform.position, Quaternion.identity);
//}
Destroy(gameObject);
Vector3 position = gameObject.transform.position;
Quaternion rotation = gameObject.transform.rotation;
GameObject sherds = Instantiate(toiletSherds, position, rotation);
}
if (isInFire)
{
fire = Instantiate(fireParticles, transform);
if (!fire.active) {
hitsReceived = maximalHitsToDestroy;
}
}
}```
hey is there a way an image on an item can be completely nothing? i have it set to none yet it still has a square sprite
...why do you have [System.Obsolete] on your methods?
You need to disable the image entirely, or give it a transparent sprite
because the system recommended it to me
Or set the image's color to have zero alpha, I guess
yeah but then the item that takes its place is transparent
this will try to spawn particles every single frame. perhaps you should set a flag once you've spawned the particles
well, you would set it back to being opaque when you give it a sprite
Ideally, you'd encapsulate all of this in a method
wait,what means in particle system the simulate method?
ye i just trhought that
public void ShowItem(Item item) {
image.color = Color.white;
image.sprite = item.sprite;
}
i do not understand this question
are you talking about these properties of the ParticleSystem?
after running this, i see that when i go back to the first scene, it doesnt run the script twice, but it destroyed the canvas i needed, and kept the old one from when the scene started, is there a way to switch the canvas that is being destroyed? thanks for your time and help, since i know im just a begginer and i can be confusing
nothing, I thought that was the problem
The canvas being destroyed is the new one.
Do you need the one that's already in the scene?
yes i need the old one to get destroyed
Okay, you want the old one to die.
but that's the old one...
no
the old one is the one that's currently in the DontDestroyOnLoad scene
when you move scene, one canvas stays in the scene and the other moves with you. the one thats being destroyed is the one thats moving with you from scenes
In that case, if the canvas instance is not null, destroy the instance's game object, then overwrite canvasInstance with your own canvas
I do not understand this. When you load a new scene, everything in the old scene is destroyed, and everything in the new scene is created.
nothing "stays" in the old scene
the old scene is gone
let me remove the destroy and show you what i mean one second
i think that is because is on the method update
this is what i mean. the old canvas is the one that is staying in the scene and the player doesnt move correctly in, thats the one i want to delete
when i do that the canvas just destroyes itself as soon as i press play
your approach is just gonna give you more and more problems, notice how the old canvas lost it's reference to the camera? I still don't see why you need the canvas so persist, could you show us what's in there and needs to not be destroyed?
Having your player walk on a canvas is also a little strange, usually you would use SpriteRenderers and have them walk around the scene without a canvas
when is scriptableobject onEnabled called?
my animation is stuck at frame 1 (can transition to self is unchecked)
animator.SetInteger("State", (int)state);
animator.SetInteger("Direction", (int)direction);
this is the code for the animator
it's on update
show the transitions
I'm not even sure whats supposed to be what. im guessing having conflicting anystates with diff integers is causing issues
have you inspected the animator while in playmode if you click the animator you will see whats going on transitions wise
the anystates don't really conflict, up is for integer 0, side for integer 2, and down for integer3
i'll post it in a second
@rich adder
it's stuck on up's first frame
yes
im trying to make a way that when each inventory slots button is pressed it becomes selected, how would i make an int thats equal to the slot selected?
How can I add days counter to this script?
the slots are already in an array so i can reference all of them easily
but i cant figure how to let the code know which slot was clicked
make new timespan, add days
https://learn.microsoft.com/en-us/dotnet/api/system.datetime.adddays?view=net-7.0
nope, removed the code and just did it through the inspector and it was still stuck
🤷♂️
https://hatebin.com/qbqmyljlcs - line 63-66 is what needs added
how to destroy clones?
clones of what?
a prefab
put them in a list
k
but can I do it somehow simpler? Like when time gets to 24hours and starts counting again can i just add dayCounter++; This is also script to display how many hours have passed in game and WorldLight is script where I change gradient of light based on what percentage day is
wdym simpler?
nothing simpler than adding to a timespan
you could also just store ticks
then translate it to formatted time when needed
i mean its really simpler to do public int dayCount; and do dayCount++; when time reset to new day
can i do that?
how do you even define what a "new day" is
Complexifies it, since you now need to handle multiple variables, and not forget to increment them when needed
idk how to do as its in for loop
"as its in for loop"
whats that mean
I have no context to ur code and what ur trying to do
I'd store the time in one variable, as the smallest unit you care about (seconds? minutes? hours?) and then use computed properties to get the other time units for you
yea thats why i asked for ur help, i followed tutorial and i dont understand where in a script does it make that day loops and starts new day
I often just store in ticks since thats only an int
if there is a certain thing true, it will destroy all the clones Instantiated from a for loop, idk how to say which clones/ objects i want deleting
StartTimespan and then Timespan when you're checking gives you the elapsed time
it makes day cycle, it counts how many minutes and hours have passed and when 24 hour comes it will start again like a day and light gradient will change
thats reply to someone else
oh sorry
foreach(var spawnedObj in spawnedObjects){
if(spawnedObj.ToDestroy == true) Destroy(spawnedObj);`
}
example
or if you dont want to store a bool on the playerscript itself make a dictionary
idk what conditions u want for it set to destroy
do you know where in script does it do to make day cyle and start counter again?
all your doing istoring a result from one timespan to another, to display, get a day value or hours value etc.
you don't have to do any ++ counter
i just wanna destroy all those after an if statement basically
so what do i need to doć
do*
so do it in a loop
Store the time when it started. Display the result of CurrentTime - StartedTime
that will display whatever time has passed with timespan
lookup how timespan struct works, its very handy
yea but how? i dont get how to reference each object in those loops
look at the examples
https://learn.microsoft.com/en-us/dotnet/api/system.timespan?view=net-7.0
i told you how
you loop thru them in a list
{
[SerializeField] Transform EquipmentsParent;
[SerializeField] EquipmentSlots[] EquipmentSlots;
private void OnValidate()
{
EquipmentSlots = EquipmentsParent.GetComponentsInChildren<EquipmentSlots>();
}
}``` i dont understand what the error is, everything works fine but it has a problem with object reference
whats line 12
EquipmentsParent.GetComponentsInChildren<EquipmentSlots>(); ?
yes
is the second screenshot inspector in playmode ?
and are you certain you don't have a clone of this script?
type t:EquipmentPanel in your hierarchy's search
is this okay @rich adder
whats the end goal here ?
is there a reason you're manually adding time instead of just doing 1 datetime - another datetime
And why two TimeSpan, when one would be sufficient, since it can handle pretty much all time units at once
!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.
i want to have text days: 1 and after every 24hour in game it adds 1 day
how to make environment black , i removed skybox , still getting a plain blue sky ,
i am new to URP . changed the camera settings too .
Yeah but that doesn't explain if you're doing real time ?
is time in the game different as in faster/slower ?
Days will be your TimeSpan.Days property. Use one time span, it stores everything and is capable of spitting out every possible unit for you
need help with animator trigger
the customer has only 2 trigger walk and sit and i have set animation to loop
but the customer sit only for a .2 sec and start walking again
https://gdl.space/ebicebaquq.cs
am i not using trigger correctly
just this one
https://hatebin.com/cjdipjbppk
for lines 63-66 im trying to make it so that the code knows what item slots button was pressed
i have an inventory slots array with all of them in it
you have to check at runtime if that reference is changed or something
faster
like
var itemSlotSelected = inventorySlots[slotSelected]
does anyone know how i could achieve this
nothing changed
why it wont work like i did it now?
im not even getting said error now anymore so ig im good ty for help
was just trying to understand the setup
so it will add days like i wanted to right?
how do I instantiate prefab as like legit blue tinted prefab prefab with code
Don't add days, add minutes like you're doing. Then get the calculated days.
TimeSpan a = new();
a += TimeSpan.FromMinutes(51278);
Debug.Log(a.Days); // -> 35
It's not hard, so why make it hard by redoing it on your own?
This is direct compiler output, and I didn't know 51278 minutes would equal to roughly 35 days. You don't need to know and calculate yourself either, so let the runtime handle it for you
How do you write a method like TryGetComponent, where it has an out component that only gets written if it returns true?
With an out parameter in the declaration
The compiler will then force you to assign a value to that parameter before any return (or the end of the method) is encountered
so does TryGetComponent just assign null if it returns false?
yes
then how would Dictionary's TryGetValue method work? the output could be a struct
ah. I didn't know that keyword. ty
Hello there. I am new here also beginner. Can anyone help me for my camera script?
- use cinemachine
- you'll need to actually share the relevant code and say what is wrong
https://dontasktoask.com
i dont understand what should i change here
ouch! sorry :/
Get rid of the TimeSpan on line 11 and the entire coroutine on 27-33
For the third time, you need only one time span variable
so i only need to have TimeSpan currentTime;
As long as there's still 60 minutes in an hour, and 24 hours a day in your universe, you're good with one TimeSpan
whole day is minuteLength
That's not what I'm talking about
I'm not talking about how many real minutes a game day is
You're doing the math for that already, what matters is whether 60 minutes in your game is 1 hour in your game
And whether 24 hours in the game is a day in your game
yea but it still doesnt count days
It does
It's in currentTime.Days
Try and print it, after 15 minutes of real time it'll say 1
15 is in seconds, i set it for 15sec for test purpose
oky i will try
how do i referenece the object of the button clicked
Depending on where you want to get the object is should just be gameObject lol
just +1 lol
Yes because the first 24 hours is before the first day's end
or start it from timespan with an added day
Better method, so you don't need to do +1 everywhere
And forget it in one place, and wonder if you have a bug
thanks this helped
okay how to display that here, in dayText;
Probably with the d format string
You need to look at the docs mate, before using anything that's not extremely simple
what does the #2 mean ?
you should know its your asset xD
Hm, second touch screen lol?
maybe two finger touch buttons?
well thats kinda what I hope it is xd
Im just trying to get single vs multiple finger touch using unity input system
but I cant find documentation that says waht these mean
I've yet to use touchscreen with new input system 😮
doc isn't mentioning anything about a #
I just want 2 separate inputs for touchscreen that can be set to button
cuz I cba to write logic for dragging and I just want to test 2 different actions on mobile

ye im sure it is I just wondered if anyone knows waht those are
would save me some time figuring it out 😄
only foudn this way and not the input actions
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.5/api/UnityEngine.InputSystem.EnhancedTouch.Touch.html#UnityEngine_InputSystem_EnhancedTouch_Touch_activeTouches
maybe try #🖱️┃input-system
this doesnt work...how should i do it?
public GameObject ItemSelect() { GameObject slotSelected; //Object of slot selected int slotValue = EventSystem.current.currentSelectedGameObject.GetComponent<Slot>().slotNumber; //Slot number slotSelected = inventorySlots[slotValue].gameObject; //Slot Object return slotSelected; }
how would i then use the slotSelected variable? after returning it
three backticks, not just one
and you store the returned value in a variable that you can then use
in a local variable?
sure
outside of the method
GameObject slotSelected; public GameObject ItemSelect() { int slotValue = EventSystem.current.currentSelectedGameObject.GetComponent<Slot>().slotNumber; //Slot number slotSelected = inventorySlots[slotValue].gameObject; //Slot Object return slotSelected; }
so then would the slotSelected variable be what it returns in the method?
Well, you're overwriting the text you set one line above. If you want it to be aside the hours and minutes put the d inside the first string
why did you move the variable declaration outside of that method?
i want seperate text for days
Then use another Text variable
you're also still not formatting the !code correctly
📃 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
What's "not working" with it?
The format string is not correct and likely will throw a FormatException
You need to do something like @"'Days:'\ d"
GameObject slotSelected;
public GameObject ItemSelect()
{
int slotValue = EventSystem.current.currentSelectedGameObject.GetComponent<Slot>().slotNumber; //Slot number
slotSelected = inventorySlots[slotValue].gameObject; //Slot Object
return slotSelected;
}
there
Pay attention to what I'm writing. You missed a character
so i could use the variable outside of the method
then why are you returning anything
will the variable update to what it should be if i use it in another method?
after the ItemSelect();
can you explain what the fuck you're actually trying to accomplish here so that i don't have to try and guess what the actual intention is from your ever changing code?
okay it works now, thanks everyone
whats happening here it just goes back and doesnt do anything, I dont know anything about assembly definitions lol I could try referencing it in settings but wouldnt that mean I then include whole ass new assembly in my builds too? I wanted to try and use https://docs.unity3d.com/ScriptReference/PrefabUtility.InstantiatePrefab.html from that and put directive so it wouldnt include that class into a build but I cant use it in editor itself
yeah, basically each item slot in the inventory has their own number which is what the SlotValue is then the slotSelected is the object that the slotValue is set too
overall grabbing the selected Slots GameObject
this is all on a button click on the Slot
okay so waht are you actually trying to do
be able to move around the items in the slot in the inventory
itll select it, then eventually if you click the button while one is already selected itll either trade the item's in the slots or fill it in
i meant with the code you were asking about. what is that code supposed to be doing
wait but where should i put +1 so it counts from day 1 not day 0
You can't use any scripts in the .Editor namespace in a build, inculding PrefabUtility. That stuff only works in the editor.
i want to be able to use the Selected Slots game object in another method thats for moving them around
No, you start with a TimeSpan that has already one day.
okay so are you calling ItemSelect in that other method?
it doesnt, it starts day 0
but I cant use it in editor as well
no
You make it so by adding it manually, use your brain
AddDays(1)
then make the method return void and remove the entire return statement since that is 100% unnecessary
already did
then what is the current issue?
that goes in WorldTime?
ah nvm misread your question, I dunno why it doesn't work for you, it works fine for me
In the variable of type TimeSpan yes, like in Awake
Do it once, not in the coroutine
actually it compiles even though in ide its an error wtf
i dont think the GameObject slotSelected; variable is changing based on what the ItemSelect() method does
if it is a field and not a local variable then it will whenever that method is called
oh wait
i think its all good
thanks for your help
Hey, I saw this bit of code somewhere recently, and wanted to ask, what does the " : this() " do?
It calls the parameterless constructor
It's completely unnecessary here
It would matter if you had defined a parameterless constructor explicitly which I don't actually think you can do for a struct
Not for the C# version Unity uses, indeed
Just so you know, it shows red because the assembly being used in the IDE there is the .Player one, which does not contain editor stuff. Click the circled button and you can change the one to use for the file. Useful if you need some editor stuff wrapped in explicit #if UNITY_EDITOR defines. (I won't lie it took me ages to realize that button existed even after using Rider for a long time)
(for those using VS, it's the dropdown top-left of the code view)
Hey! :>
This isnt a question.
I made a Object Pooling script in which I create a generic pool object with some useful features.
I wanted to share it because I like it pretty much, so, if anyone wants to see it or use it I can send them the script with some instructions
Thank you :>
fun fact but unity 2021+ already has an ObjectPool<T>
Wait what
Also has pools for Dictionaries, Lists, HashSets, etc
guys how do i make my ground ghost-proof
Spread some garlic on it
send in the ghost busters
i mean i have basic code that i can walk on
Wait that's vampires not ghosts lol
Isn't that for particle systems?
sounds like you're moving in a not-very-physics-friendly way
it's for whatever you wanna use it for
example code should not be taken as a "this is the only way to use this" rule
scrap mechanic lore be like
you're gonna want to check #854851968446365696 for what to include when asking for help if you want some actual help with your issue
please learn to read
Well, I think its not too complex, mine has a few more features so at least I didnt waste my time
what features does your object pool have that unity's does not?
For what I saw I think Unity doesn't do this
For example, you can ask my pool to give you an object of an specific type which inherits from the pool type
And it implements IEnumerable so you can traverse it with a foreach
ah yours is one of those "throw anything in the pool and ask for specific types of things" in it?
Its more like a inheritance pool
I designed it for my game, I wanted a pool that stores enemies (the abstract class Enemy) and gives the enemies I ask it for
Howerever you can also use it as a normal pool
share it on asset store
It's too simple to be an asset, in my opinion
I mean, its just a script
thats not a thing if its free
u never saw
what kind of bs
people ask money for there
Well... I will research about it, thanks
One of the things I like most is that you can set default prefabs for the case you ask the pool for a type of objects and there are no objects of that type left in the pool. Then the pool instantiates it with the prefab
Unity one can do this too 
you provide it with a func to create an instance, so yes it does that too
yea so dynamic pooling I had mine instantiate around 50 upfront of what will be used and if its not enough resize it
unity's does that too
And Unity one implements IEnumerable?
unlikely because why should you need to enumerate over your object pool
You can give it a function to run when it gets the object as well, so not sure why I'd ever want to traverse the pool outside of that
plus unity's has o(1) insert and get from pool. yours sounds like it is o(n) because it has to search for the right kind of object which makes it potentially a lot slower, especially as the pool grows in size
it approaches o(1), yeah
Anyways, my game wont have so much objects so I think my pool worths it for my game
by all means, keep using yours. making it yourself is a good learning experience. i recreated unity's on my own to ensure i understand how it works and to use it in a 2020 project once.
but it also sounds like yours may not be a good general use one and is more purpose built
how do i make it so the collider gets disabled after a set amount of time after collision
What is collision there?
That looks like it should be in OnCollisionEnter, not FixedUpdate
Also, your !ide is not configured
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
thats a different code
thats for the falling part
?
you don't have errors underlined or syntax highlighting. having configured tools is a requirement to get help with your code here
ill do that later
then you'll get help later
It is a requirement to get help here
why
because we're not your compiler
because how are we meant to help you with your code if you insist on using variables that don't exist?
cant i just describe
See the readme here, and see the "answering questions" section
#854851968446365696 message
whatever dude, thanks anyways ill come back some day when ive done the configuring thing
can't you just try not to waste our time?
be nicer atleast
no
you can always ignore
Boxfriend is one of the nicest here ):
He's just tired of people with not configured IDE
Such as me my first time here
it literally takes 5 minutes of your time and save you hours of headaches in the future. You're only shooting yourself in the foot
im in a rush come on man
im sorry about that
Why?
coding is not something you do in a rush
i have an event
Then configure your ide, it will save you tons of time it is EXTEMELY important
no its fine, i got it anyways
Could have set it up in the amount of time you have been resistant against setting it up 
the time you spent saying you're in a rush could've been time spent downloading the dam extension
About what? Its good that he told me to configure my IDE, I configured It and it was so useful
about wasting time
If your FixedUpdate is the same, you should be getting an error
already do
Nice
since like fucking a year ago
clearly it didnt work
Oh. That screenshot is not configured
clearly
and a year ago things have changed
Its like programming blindly
And the extension from a year ago is obsolete
new Unity extension was dropped
well i was inactive
its lik 1 thing
busy with robotics
There is a new one since august, when Unity deprecated support of vs code
okok
cool. time to caatchup to the new extension then
Then Microsoft had to make their own extension
yeah i got the new extension when i came back last month what's wrong
theres a few more steps like updating your package manager
The errors aren't showing and the colors are wrong. So something in your setup is wrong
e
So you want the swaptype to show material when you have a material selected?
custom proprety drawer
Yes, show the material Active/Inactive on selection and vise versa
A property drawer does not sound relevant here.
that customizes how a single property is drawn
I guess you could redo this a bit, so that you have a struct that contains all of the fields
and then customize how that struct is drawn
I think that's what I've wound up doing in the past
could also use something like NaughtyAttributes and the ShowIf attribute. or odin inspector has something like that too
yeah, NaughtyAttributes could do this
yeah you're right myb I used that for my read only
i think I mean this one
https://docs.unity3d.com/ScriptReference/Editor.OnInspectorGUI.html
although i'm not 100% certain about recommending naughty attributes anymore. i've read that it force all types to use IMGUI for the inspector instead of uitk which is now the default in 2022+
I don't mean to be rude, but I am so lost right now
pretty sure it's for all UnityEngine.Object types.
and yeah looks like the relevant issue is still open https://github.com/dbrizov/NaughtyAttributes/issues/369
https://github.com/dbrizov/NaughtyAttributes/issues/147
its been a while since i I've done something like this 😅
ScreenCapturing myScript = (ScreenCapturing)target;
GUILayout.BeginHorizontal();
myScript.fileName = EditorGUILayout.TextField("File Name", myScript.fileName);
GUILayout.Box(".png");
GUILayout.EndHorizontal();
myScript.DefaultFolder = GUILayout.Toggle(myScript.DefaultFolder, "DefaultFolder");
GUILayout.Space(6);
if (!myScript.DefaultFolder)
{
myScript.folderName = EditorGUILayout.TextField("Folder Name", myScript.folderName);
}```
Just use Unity Recorder to do screenshots
wai this is a thing?
Yep
yeah it's an editor only tool for screen recording and the like
https://docs.unity3d.com/Packages/com.unity.recorder@2.0/manual/index.html
oh wow.. I was sleeping on this
Set it to capture images, set to single frame
yay no more obs xD
oh you're talking about the tool I made not the gif
like the script
yes
oh nahh its a bit more complex than that
Simple Unity tool for Sprite generation from screenshot - GitHub - navarone77/Screenshotie: Simple Unity tool for Sprite generation from screenshot
it takes screenshots of your gameobjects and makes sprites out of them
for like inventory icons n stuff
That url doesn't load
oh wops its missing dot
its so old.. i didnt even bother putting the script just .unitypackage :dolt
i also levarage this script https://docs.unity3d.com/Manual/DefaultPresetsByFolder.html
turns all the texture2D import settings turn into Sprite2D
should i put animation https://pastebin.com/2Qmr8f3P between every one ?
if (Input.GetKeyDown(KeyCode.Alpha1))
selectedWeapon = 0;
if (Input.GetKeyDown(KeyCode.Alpha2) && transform.childCount >= 2)
selectedWeapon = 1;
if (Input.GetKeyDown(KeyCode.Alpha3) && transform.childCount >= 3)
selectedWeapon = 2;
if (Input.GetKeyDown(KeyCode.Alpha4) && transform.childCount >= 4)
selectedWeapon = 3;
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.
im just working on game and i have 4 weapons and what do i do to make them animated
maybe there is a better way but idk any lol...
https://gist.github.com/navarone77/88abe3e302c26a366ed3276bc7da86e2
edit: i updated gist so you don't have to have custom labels for fields and grabs original name
ofc its an example , you could make i t better also prob use switch if you got mora than 2 enum values :p
page is no longer available
thx
@rich adder https://pastebin.com/dcvw8rM7 can u code me a program that makes the gun move to certain point that i can pick and rotate by 90 degrees and same thing in reverse
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.
note that, since this is a custom editor, it's completely replacing the default editor for your component
so if you have other stuff, you'd have to draw it yourself
a custom property drawer with a class/struct might work:
[System.Serializable]
public class FooInfo {
public enum FooKind {
One,
Two
}
public FooKind kind;
public float oneData;
public int twoData;
}
I did this with IMGUI in the past. You just draw the relevant properties and skip the others
Not sure what you'd do for UI Toolkit.
yeah this is probably better way to do it
just thought Id have some fun in Editor script, its been a while since i've touched it
cant u just do DrawDefaultInspector(); and u wouldnt need do draw usual stuff manually
Yeah I think so
ahh its tricky..no
it doesn't "draw the rest"
it draws all of them
Unless Im using it wrong
yea if its serialized in real script it will draw as well
ive got mine hidden and drawn from editor script what I need
do you mean like a animation rotation ? I dont understand what that means
ahhh just realized you can't even use nameof of fields that are private

yea
sum like that
public but with [HideInInspector] or [NonSerialized] idk which one is more correct I use first and didnt get into any trouble yet with default values or sum
yeah thats what I basically did and it kinda worked
[HideInInspector] public MyEnum myenum;
[HideInInspector] public Material mat1, mat2;
[HideInInspector] public Texture tex1, text2;
public float otherStuffs, otherStuffs2;```
yea
DrawDefaultInspector();
EditorGUILayout.PropertyField(myenum, new GUIContent(nameof(myenum)), GUILayout.Height(22));```
When would you need [NonSerialized] anyway
https://youtu.be/dDxWLsF3BM8?t=18 u see that animation when u change weapons i would like to do that but i have no clue
so it wont be null when it would normally be
[HideInInspector] doesn't serialize without [SerializeField] anyway which I'm not sure why
you need to do a base animation to your weapons holder
then any weapon parented to it will do that anim
ooh
i have no arms in my game just a gun
then idek whats NonSerialized for then lol
whats that got to do with what I said lol
NonSerialize is like when you want the editor to change a value on the editor, but reset to defaults when the scene is closed
I guess more tool utility?
but how do u make it show up in editor then
public or private + [SerializeField]
lol
wat
I don't believe you can make a non-serialized field appear in the inspector.
The inspector displays serialized properties, by definition
NonSerialized means unity will not attempt to serialize it. it will not show up in the inspector at all
^
so whats the difference between this and [HideInInspector]
HideInInspector will still be serialized so the serialized value will override whatever the default or field initializer sets. it just won't be drawn in the inspector
will this work ?
[HideInInspector] [SerializeField] private MyEnum myenum;
so i don't gotta make it public
you sure HideInInspector serializes? I thought the values reset if you don't serializeField it
yes. it just won't be visible in the inspector so you'd have to assign it via code during edit time to save a value to it
oh but you would use it on public data, so that would serialize it
oh wait I can't do that anyway
dam scripting editor is a pain
maybe it would probably work with strings , cause thats what the unity examples does
you wouldn't be able to use the nameof operator there, but hard coding it or getting the name via reflection would work
right, this is the situation im thinking of
You want to serialize a private variable, but don't want the inspector to show it.
I wanted to see if I can make it private but then display it manually with OnInspectorGUI
thats what im doing but I gotta change it from nameOf to string to work
manually typing all the field names
yucky
naughty has its own hide/show attributes (with conditions but can probably set false/true)
just imported the thing boutta see whats up
hmmm how do you turn this
myenum = serializedObject.FindProperty("myenum");
into a valid enum now because its a SerializedProperty
if (myenum == MyEnum.A)
now don' work
it's pretty good but can get a little messy. Good for just developing out the GUI.
but once you're set on what you want, you'd probably want to make your own custom editor
why messy? name implies im just gonna pepper attributes around no?
It can get messy with containers that need attributes
aaa
because then it needs to use some meta attribute to resolve
Unity editor stuff is honestly ok, it's just the workflow of editing two scripts at once because you decided to want to expand out the data (or edit previous data and types) is quite annoying.
So I have this Sliders script which I'm trying to use to update the speed, interval, lifespan variables which are being used in other script.
public class SlidersWithEcho : MonoBehaviour
{ public TravellingBalls TBall;
public Slider intervalSlider, speedSlider, lifespanSlider;
public TextMeshProUGUI intervalText, speedText, lifespanText;
void Start()
{
intervalSlider.onValueChanged.AddListener(HandleIntervalSliderChange);
speedSlider.onValueChanged.AddListener(HandleSpeedSliderChange);
lifespanSlider.onValueChanged.AddListener(HandleLifespanSliderChange);
}
private void HandleIntervalSliderChange(float value)
{
intervalText.text = value.ToString("F4");
TBall.UpdateTBallSpawnInterval(value);
}
private void HandleSpeedSliderChange(float value)
{
speedText.text = value.ToString("F4");
TBall.UpdateTBallSpeed(value);
}
private void HandleLifespanSliderChange(float value)
{
lifespanText.text = value.ToString("F4");
TBall.UpdateTBallLifespan(value);
}
}
This is the TravellingBalls script which uses speed, lifespan, interval.
I am not trying to understand why the sliders aren't properly bound to the variables. because when I try to change the slider value, my variables don't update
Are your methods getting the speed here
yeah I am able to access change in slider value in the SlidersWithEcho script methods
did u try logging at every part where it goes wrong it looks good to me idk
so you've debugged and it does give you a new values in
private void HandleSpeedSliderChange(float value)
{
speedText.text = value.ToString("F4");
TBall.UpdateTBallSpeed(value);
}
Such that it is then passed into UpdateTBallSpeed
yeah the speedtext.text is updated in the editor at run time when I move the slider
can someone adjust this code so reload sound actually plays after shot https://pastebin.com/w5enziKg
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.
I did
void Update()
{
Debug.Log(speed);
this.transform.localPosition += targetDirection * speed * Time.deltaTime;
if ((Time.time - lastSpawnTime) > spawnInterval && isCreated)
{
CreateTBall();
lastSpawnTime = Time.time;
}
else if ((Time.time - lastSpawnTime) > lifeSpan)
{
Destroy(this.gameObject);
}
}
How about here then? Does speed variable get updated?
Looks all fine to me honestly
Debug.Log(speed);
this doesn't update the speed, shows the default 6f only
debug log speed inside UpdateTBallSpeed does it get the change
yeah it changes there
so then u got more than one instance of that class?
it will change only in one u refer to in that slider script
Yeah 100s, those balls are being instantiated after every "intetval"
Either you're reading a different instance or something is setting it back to defaults is my guess.
ohh, I want it to change to all of those balls. How do I achieve that
is TravellingBalls controller of those balls or like each ball has one
yea each ball has one
Where do you actually change the "speed" variable though?
Guys, is there any way to detect when an object is destroyed?
in the slider script
OnDestroy
oh,thanks
Or just do something from the code that destroys it
so what I want to achieve is. the balls would travel at 6f speed by default. Once I update the speed using slider. I want the newly instantiated balls after every "interval" to have that new speed
lol sry for ignore I thought praetor gonna take over you need some sort of central place where balls are moved or they look up at what speed they need to move and move themselves
Debug it in the Start() method where you're setting listeners and make sure each new ball instance is subscribing.
better to just use VS debugger to set breakpoints if you're spawning a lot
If I debuglog the speed in start(). After every ball being instantiated, the log says 6 only. It doesn't change the value for any of the future balls being instantiated
look up what is singleton make one up
make a list<UrBalls> = new() in that singleton and in balls script in start add ball instance to that list and in that singleton when you change speed change speeds in all of the balls in that list
ur use an event idc
well I don't want to change the speeds of existing balls, only the balls instantiated after the slider updates
i have a question but it is for unity itself and not for code. where do i post it? 😄
its same thing u still want static float or singleton balls can get their speed from or a Setup method in a ball script to set their speed when u instantiate
if u paste code into hastebin I could plug that in ig
So do the balls get updated after they spawn and you change the slider?
balls spawn at current speed and dont change afterwards
because if that's the case then you have to probably read directly from* the slider after you subscribe.
ah, ok then I'm not too sure. I don't really use listeners but it sounds like they're the problems if they are sure they are absolutely creating these TBalls with this wrapper class.
I know what he wants he just needs to spawn balls from spawner with speed var and set speed in spawner with that slider he uses which would be used to spawn the ball with correct speed
bro dipped tho 
yeah, subscribing isnt enough after instantiating, but if it's not updating after the slider moves, then that's more of a subscription problem.
he didnt use events I just offered that previously but if balls care about the speed only once when instantiating u dont need event
can I somehow look through my assets folder for prefab by name ive got script I add and remove shortly after but it needs reference to prefab I dont want to keep dragging it in
Asset database I think had a method for that
yea that works ty
how can i make a button perform a method if its condition is met or another method if its condition is met
2 differents methods on the button
have the button call one method which checks the condition and calls the relevant method
i have it as-
public void ItemSelect()
{
if (isSlotSelected == true)
{
isSlotSelected = false;
int slotValue = EventSystem.current.currentSelectedGameObject.GetComponent<Slot>().slotNumber; //Slot number
slotMovingTo = inventorySlots[slotValue]; //Slot Moving To Object Image
Debug.Log("Slot Moving Too " + slotValue);
}
if (isSlotSelected == false)
{
isSlotSelected = true;
int slotSelectedValue = EventSystem.current.currentSelectedGameObject.GetComponent<Slot>().slotNumber; //Slot number
slotSelected = inventorySlots[slotSelectedValue]; //Slot Object Image
Debug.Log("Slot Selected " + slotSelectedValue);
}
}
in 1 method
but it ends up playing them both anyway
isnt it the same either way tho?
no, you currently check if isSlotSelected is true. if it is you set it to false and do other stuff. then you check if it is false, which at this point it is because you just set it to false so it does that stuff too
ohh i thought since it was read down it wouldnt go back to do the first one when the condition is met
is
if else, the same as an either or?
one or the other
they are two separate if statements right now and you don't return from the first so naturally it will check the second. you need to use else or else if for that second one so that it doesn't run if the first condition is true
alright
basically just
public void ItemSelect()
{
if (isSlotSelected == true)
{
isSlotSelected = false;
int slotValue = EventSystem.current.currentSelectedGameObject.GetComponent<Slot>().slotNumber; //Slot number
slotMovingTo = inventorySlots[slotValue]; //Slot Moving To Object Image
Debug.Log("Slot Moving Too " + slotValue);
}
else
{
isSlotSelected = true;
int slotSelectedValue = EventSystem.current.currentSelectedGameObject.GetComponent<Slot>().slotNumber; //Slot number
slotSelected = inventorySlots[slotSelectedValue]; //Slot Object Image
Debug.Log("Slot Selected " + slotSelectedValue);
}
}
or do i keep the condition?
however all but one line in both of the if statements is practically identical. use the if/else for just that one line instead of copying the code and just invert the bool
yeah they are nearly identical right now, but eventually itll be used to move the items around to the slotMovingTo from slotSelected
alright it worked
Does anyone know why i could be getting a null reference error from this code? https://i.imgur.com/aKkTLVS.png
on which line
2
did you actually put anything into the array?
Yes, the first line, actually work but for some reason it cant grab the length from it.
that's not what i asked. have you actually assigned anything to the elements of the array? or have you left them null? and no, i'm not referring to the instance of the array itself. the individual elements of the array
Oh, yep thats exactly what it is, the audiosources in the array, is missing the clip.
can someone point me in a direction in adding drag and drop into my inventory
is the inventory manager
if i have a scene where the ui isn't working what are the usual culprits?
UI isn't working is a little too vague homie
UI elements don't animate when clicked or trigger onClick methods
like on a Canvas type UI elements
public event Action<Item> OnItemRightClickedEvent; says this namespace cannot be found, is this not correct?
do you have using System
just System
alr
Your !ide is not configured
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
you should be using your IDE to add namespaces (on top of getting error highlighting and autocomplete)
Sprite slotSelected; //Selected slot
Sprite slotMovingTo; //Slot To Move Item Too
bool isSlotSelected = false;
public void ItemSelect()
{
if (isSlotSelected == true) //Moves/Swaps items in inventory
{
isSlotSelected = false;
int slotValue = EventSystem.current.currentSelectedGameObject.GetComponent<Slot>().slotNumber; //Slot number
slotMovingTo = inventorySlots[slotValue].sprite; //Slot Moving To Object Image
slotSelected = slotMovingTo;
slotMovingTo = slotSelected;
Debug.Log(slotSelected + " moved to " + slotMovingTo + " in slot " + slotValue);
}
else //Selects the first item
{
isSlotSelected = true;
int slotSelectedValue = EventSystem.current.currentSelectedGameObject.GetComponent<Slot>().slotNumber; //Slot number
slotSelected = inventorySlots[slotSelectedValue].sprite; //Slot Object Image
}
}
how come the sprites arent changing at all even tho they should be?
lines 12 and 13 of this
friend, learning how to debug is an invaluable skill
i tried
it showed that the sprite was moved to the new slot then
it never actually showed the sprite swapped
you tried how ?
have you used debugger before ?
step thru the code
slotMovingTo = inventorySlots[slotValue].sprite; //Slot Moving To Object Image
slotSelected = slotMovingTo;
slotMovingTo = slotSelected;
whats even goin on here
the sprites are swapping
trynna make custom attribute for better buttons and it all works fine but can I do anything about this https://hatebin.com/yvbveokhju ClickableCheck string I wanted to pass in func<bool> but that aint possible from what I can tell so what else can I use to point to a method 
Do you notice something missing
he just copied relevant part brackets intendation especially at the end implies this is not the last one
Lambdas. You can make basically anonymous functions in places that are looking for funcs or actions or other delegates. For example, if you need something that returns a bool and has no parameters, you could do something like this:
SomeFunctionRequiringAFunc(() => ThisReturnsABool(someParameter));
theres more in the script, but the rest is irrelevent to my question
The way to read this is like so:
bool ThisReturnsABool(object somethingOrOther){
...
return false;
}
Intendation was not what I was referring to
"Check lines 12 and 13" -> provides code with no line numbers
oh yeah
aaa mb
is there a way to have it with numbers?
This is why you use !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.
i usually only use hatebin for the entire code
but ill send the full
lines 59 and 60
im wondering how come the sprites arent swapping with each other
Let's talk about these two lines
Let's say slotSelected is currently something called "Sprite A"
alright
and slotMovingTo is something called "Sprite B"
then you run these two lines
The first line happens. What is the value of slotSelected and slotMovingTo
Okay and what is slotMovingTo
^
oh mb i read wrong
First line
So, before the first line, slotSelected is Sprite A, and slotMovingTo is Sprite B.
After the first line, slotSelected is Sprite B, and slotMovingTo is Sprite B.
its basically making one equal to it then making the other equal to what it already is
Now, what happens on the next line
slotMovingTo is Sprite B and slotSelected is still Sprite B
In order to "swap" two variables, you will need a third temporary variable to hold the original value of one of them
yeah
Hold the value in that, set one, then set the other to the temporary
to swap two variables these days I use a neat trick with value tuples
(a, b) = (b, a);
yea I tried but I dont get this
I want to move into attribute constructor a func<bool> I cant see where this helps me where the lambda go
||That's reserved for at least #archived-code-general ||
ye im a beginner
Well, what needs the Func<bool>
but i also come here like 5 times a day im grinding to learn super hard
should it just be a local variable to the method?
cause it has no use outside of it
Yes, no reason to keep it around
I disagree, personally you don't need to understand the type in depth to understand what the code does there
i already use enum and other stuff to manage data so idk if itd be a lot harder
but id rather just learn as i go and not force myself to learn multiple things to get 1 done otherwise i wont remember any of it
Sprite CSprite = slotSelected;
slotSelected = slotMovingTo; //A = B
slotMovingTo = CSprite; //B = A
yea so just theres full full script of what I want to do with comments tbh I dont mind strings that much I can detect wrongdoings but what if I want refactor or smthn + maybe learn something. I add attribute to method in class -> custom editor draws button but checks if you can click it right now running method returning bool which would be set in attribute class https://hatebin.com/rhflqouszb
Was looking at the official Unity Flocking tutorial. Between now and 2021 the Flocking tutorial itself seems to be out-of-date.
Specifically this line of code in the above screenshot. I've tested the Flocking tutorial's final code to work in the 2021 version of Unity but it completely breaks upon launching it in 2023.1.9f1 (I can't go to any newer versions).
Flock can't seem to reference the FlockManager, and I'm not entirely sure how to perform that. I tried creating a FlockManager object in the Flock script that is equal to the FlockManager object created in the FlockManager script (FM) but it doesn't seem to work.
is this inside Update?
or start
put FM = this in Awake()`
In FlockManager?
https://hatebin.com/fkalzybrnl
i debugged it and it showed that when you move an item in the inventory it swapped but it still didnt actually swap sprites so something must be locking the spriates into whatever slot their in
and i cant figure out why
You should always aim to initialise variables in Awake, so other scripts can use them in Start and not have execution order problems
Gotcha
you are swapping the variables, but you don't actually reassign those to the inventory slots do you?
i dont think so
oh damn
im trying to get the camera to follow the player. but when switch scenes i cant the cam to follow the player ```cs
public class CameraFollow : MonoBehaviour
{
[SerializeField] private Vector3 offset;
[SerializeField] private float damping;
public Transform target;
private Vector3 vel = Vector3.zero;
private void FixedUpdate()
{
Vector3 targetPosition = target.position + offset;
targetPosition.z = transform.position.z;
transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref vel, damping);
}
}
character selectcs
public class GameManager : MonoBehaviour
{
public static GameManager Instance;
public Character[] characters;
public Character currentCharacter;
public void Awake()
{
if(Instance == null)
{
Instance = this;
}
else
{
Destroy(gameObject);
}
DontDestroyOnLoad(gameObject);
}
private void Start()
{
if(characters.Length > 0)
{
currentCharacter = characters[0];
}
}
public void SetCharater(Character character)
{
currentCharacter = character;
}
}```
Obligatory cinemachine xD
like
fr
even tho it doesn't fix ur original question bbtw
hmm make a prefab your player + camera and persist them both with DDOL
(doesn't need to be prefab with DDOL)
ok i got half of it but im not sure how to use this variable
public void ItemSelect()
{
if (isSlotSelected == true) //Moves/Swaps items in inventory
{
isSlotSelected = false;
int slotValue = EventSystem.current.currentSelectedGameObject.GetComponent<Slot>().slotNumber; //Slot number
slotMovingTo = inventorySlots[slotValue].sprite; //Slot Moving To Object Image
//Swaps sprite for the one selected
Sprite CSprite = slotSelected; //C = A
slotSelected = slotMovingTo; //A = B
slotMovingTo = CSprite; //B = C
inventorySlots[slotValue].sprite = CSprite; //Makes the slot you moved the item too display the new item
//Here needs to make the original selected slot equal to the MovingTo Slot
Debug.Log(slotSelected + " moved to " + slotMovingTo + " in slot " + slotValue);
}
else //Selects the first item
{
isSlotSelected = true;
int slotSelectedValue = EventSystem.current.currentSelectedGameObject.GetComponent<Slot>().slotNumber; //Slot number
slotSelected = inventorySlots[slotSelectedValue].sprite; //Slot Object Image
}
}
i got the item to appear in the MovingTo slot, but idk how to make the original selected slot the MovingTo
what if i have visual studio code instead of js visual studio?
there are instructions there for VScode did you look at the big blue Link
and what is 'js' visual studio? lol
how can i change this value inside of the other section?
seems you're making ur whole inventory system backwards, you're using sprites for logic is little strange
i know
also do you know what a local variable is?
the normal way u change it from local to non-local
declare it outside the scope/method
but then it wont update to the slot selected
else //Selects the item
{
isSlotSelected = true;
int slotSelectedValue = EventSystem.current.currentSelectedGameObject.GetComponent<Slot>().slotNumber; //Slot number
slotSelected = inventorySlots[slotSelectedValue].sprite;//Slot Object Image
}
this whole method is on a button
each slot has slot number
then the slot is selected
if it was outside of the method it wouldnt select the slot at all
make a better way to manage your slots
so i should just remove all of this
no just need to make it less flimsy , also using if sprite == null to check for an empty slot is not so good
Slot should be its own class and you have a main script manage the occupancy of the slots and retrieve the sprite from an infodata , of the asset
Image[] inventorySlots
this should be Slot[]
then put more useful data in the slot
slotnumber is useless
the array is the slot number
like what item is in it?
that would be a start yes
right now you already managing two lists, when it can just be 1
Slot could just hold ItemData
sprite should be inside ItemData
(ideally this is a scriptable object ?)
yes
well ill just start working on it and will probably get stuck but probly tommorow
once you organize it better it shouldn't be too diffcult, less things to manage around
yeah i made htings harder for myself
yea lol
but im not very sure where to even start
i made that Slot class
and now ill give it to each slot
but then what?
[SerializeField] EquipmentPanel EquipmentPanel;``` ive imported both as it shows to do, but still says that its missing the references these scripts provide
like i said earlier, I'd have the slot itself hold the data . maybe make it easier and also keep the Image component reference in the slot
That's not what those errors say. Read them again
it holds whatever item is on it, so then the image sprite will just be whatever the item's sprite is
'InventoryManager' does not contain a definition for 'IsFull' and no accessible extension method 'IsFull' accepting a first argument of type 'InventoryManager' could be found?
If these errors are not underlined in red in your !ide you must to configure it
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
Yes that is the error
i did everything for that and it didnt do shit
right and thats inside the data, all you do from manager script is trigger that sprite change.
the way to determine the slot is empty would be as simple as check ItemData == null
but how will i then make the items be able to move around?
or should i ask that once i complete making the rest work cause it may not be the same?
and what does said error mean? there should also be two slots to import the inventory manager and the equipment panel if i am correct and those dont exist in the inspector
It means there's no function by that name on that class. You can't use nonexistent functions
The slots aren't there because you have compile errors
yes this comes later and deals with UI stuff.
You have to fix all errors first
ah okay
yeah, will i be able to implement drag and drop with this?
probably farther in the future
{
for (int i = 0; i < EquipmentSlots.Length; i++)
{
if (EquipmentSlots[i].EquiptmentType == item.EquiptmentType)
{
previousItem = (EquippableItem)EquipmentSlots[i].Item;
EquipmentSlots[i].Item = item;
return true;
}
}
previousItem = null;
return false;
}
public bool RemoveItem(EquippableItem item)
{
for (int i = 0; i < EquipmentSlots.Length; i++)
{
if (EquipmentSlots[i].Item == item)
{
EquipmentSlots[i].Item = null;
return true;
}
}
return false;
}
}
``` from equipment panel, which is called
ofc once an image OnBeginDrag or something is invoked you just null the data on the slot after it was dragged into another slot
if it didn't reach another slot you restore it back to old slot
None of this is relevant to the error you shared. Read the filename and line number of the error
yeah like if it got closed
You can't use a nonexistent function "IsEmpty"
thanks for the help im doing all that tommorow ive been working for like 6-7 hours today, but i gotta grind cause i wanna learn
from what i understand its complaining because the inventory manager script doesnt contain the functions i call
Yes
but i make a refernce to the scripts containing these functions
You can't use functions that don't exist
which should mean it works

