#💻┃code-beginner
1 messages · Page 341 of 1
I have created a ScriptableObject named SOWorld, and I built a ScriptableObject array named SOWorldDataSet[]. The World scriptable object has a Sprite named encounterBackground.
I have a Canvas with a GameObject called Battle BG which includes an Image and a Canvas Renderer.
BattleHandler.cs should take the encounterBackground sprite from this scriptableobject Worlds, and apply it to the gameobject Battle BG.
Somehow I'm doing this very wrong. What's the best way to make this connection?
i didnt really want the battle starter script being a instance if thats what you mean as static because each enemy would have on on the scene
make my variable public Transform target; be = at my gameobject balloon in the previous screen
Why? Is there any particular reason why you'd want the prefab to reference an object that will not exist in the next scene?
a static member is literally the exact opposite of an instance (:
You would stash the list in a static field, then read that list in the battle scene
because i need the transform location of my target for my clone
public static class BattleData {
public static List<Enemy> enemies;
}
a minimal example
explain what you are making your game do
Save the necessary data and use the data elsewhere - the position.
ok cool thanks, so i can use a static list in the battle starter, and call it in another scene? does static get stored in unity memory or somthing
a other script spawn homing missile and the target thing is for follow the player balloon
sits and waits for his turn - everyone is puzzling on other requests
Okay, so you need to assign a reference to the missile (so that it knows where the balloon is) after you spawn it
Have a look at this page
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/static
A static member (field, method, etc.) is not attached to instances of the class. They're part of the class itself.
A major effect of this is that you can access static members from anywhere, since you just need the class name
BattleData.enemies = ...
Log the value and see if the function is called. You'll also see what the value is and why it might not be doing what you're expecting it to be doing.
so just Debug.Log(Health.value);?
Where does Debug.Log show up in the interface?
it writes to the Console window
Console
I tried to use this earlier but the app was full screen
I assume since it's a log it should go somewhere even after it closes
i just did that and well it does what i told it, i changed the value to 5 then it told me that in the console
I think I am missing that tab. I'll try to get it back
The console won't clear after running unless explicitly
Window > General > Console
Cool.
that will reopen it
go to window then general the click on console
Also, when you have the time I have a main question
ask it!
It's back up at 7:50
Did you place it in Update and did the value decrease?
Should I repeat it?
yes i placed it in update and no the value only deacreased when i deacreased it manually
Here it is
Show your update method
this sounds fine; what is the problem you are having?
{
Debug.Log(Health.value);
Health.value -= 1 * Time.deltaTime;
ScoreCounter.SetText("Score: " + Score);
}```
are you unsure how to give a SOWorld to the BattleHandler ?
the ScoreCounter Thing you can just ignore that works as planned
Can you show the logs?
I am a 30 year programmer but I am new to unity.
My various attempts to drag-and-drop, set sprites and images... are all failing me
I do not know the basics. =w=
If you're experienced with programming but don't know Unity's interface, I'd check out the documentation
Remove 1 *
the whole "Working in Unity" section will be useful
and what was this error?
What error?
You have to actually read error messages..
i also tried to have it like this
Subtracting zero isn't going to be very productive
well that's just completely mangled syntax
you didn't add 1 *
you added 1
Health.value -= * Time.deltaTime; would produce that error
get rid of the * operator.
You've done more than just remove 1 *
you multiply by deltaTime in many cases
My last attempt saw me create an Image in the BattleHandler.CS named BattleBack, then access that image via dropdown in the UI and link it to the actual background image on the canvas... but when I went to say "battleback.sprite = WorldDataSet[a].Worlds.encounterBackground.Sprite;
The UI said 'Images do not have sprites, you silly bean.'
you don't literally slap * Time.deltaTime everywhere
oh ok
well that still didnt fix it
This is trying to apply the unary (one-argument) * operator to Time.deltaTime, which is an error
If you just want to subtract one per second, do Health.value -= Time.deltaTime
If you want to subtract by some other rate, do Health.value -= rate * Time.deltaTime;
oh
so i was subtracting by 1?
You probably have the wrong using directive
There are a lot of classes called Image
If value is an integer, it'll not retain the accumulated decrements.
You want using UnityEngine.UI;
Is there a better way to do it then the general method I'm attempting?
the code looks fine
Or do I have the best/a "good enough" method? I guess it's ok
Okay, let's go learn more about the various types of Images
Thanks again
There are only 2 Image classes by default. The Image component and the UI Toolkit Image
oh good heavens!
still didnt fix it btw
Uh System.Drawing never shows up when I do stuff
Yeah I use VSCode too
I'm assuming Health value is an integercs private float value;``````cs //Start value = Health.value;``````cs //Update value -= Time.deltaTime; Health.value = value;
... typoes?
so i should change it to a float?
Is Unity case sensitive??
What exactly in Unity
Yes
C# is very case sensitive
coding in unity is Case Sensetive
Is it possible to change a public variable of a script from another script that resides in another gameObject?
If you get a reference to that GameObject yes
case Sensitive
How do i access the script after referencing the gameObject?
<reference>.publicMember
Either reference it as the correct type or call Get Component
uhm i dont have a health value 😠the Health is the slider
📃 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.
bruh so ur saying that i was so close to fixing this code my self?
i tried doing the value = health.value and the Health.value = value myself but i tought that it would be wrong
https://unity.huh.how/references
Have a look here.
I accounted for that thus why I suggested you make a float variable to retain the precision
You probably want to create a serialized reference, where you drag one object into another object's inspector
You'll want to update the float variable if you change the health's value elsewhere
I'm guessing you had whole numbers checked.
https://docs.unity3d.com/2020.1/Documentation/Manual/script-Slider.html
yep
Is there someway i can change a gameObject's scale without having its children be affected as well?
Container
-Renderer
-Everything Else
If you separate the renderer, you'd be able to modify it alone without affecting everything else
These would all be Game Objects
Have it unchecked and you won't need to maintain any extra variables. You'd be able to simply decrement itcs Health.value -= Time.deltaTime;
did unity remove their new monetization policy?
This is the coding channel, try #archived-pricing-updates-talk message
my apologies
someone can explain me why when i build my game i dont see the wind in the horizontal side and why my player are soooo slowww https://cdn.discordapp.com/attachments/1149752436681080952/1238893268901560452/20240511_183803.mp4?ex=6640f0c4&is=663f9f44&hm=7fb6ea930a3a95df3c1e8b18c8d74dfd9bad819fea7430b91468b579e984d781&
depends on the code etc.
video alone doesn't help
but the camera dont depend of the code...
have you guys noticed ontriggerenter sometimes responding to non trigger collilders
depends, how do you move the cloud, cam whatever
i dont move the cam and the cloud move by himself
only if neither has a rigidbody
show how you move cloud
using UnityEngine;
public class cloud_controller : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
StartCoroutine(move());
}
// Update is called once per frame
IEnumerator move()
{
while(true)
{
for(int i = 0; i < 140; i++)
{
transform.Translate(new Vector2(0,-0.2f));
yield return new WaitForSeconds(0.05f);
};
transform.position = new Vector2(Random.Range(-10, 10),9 );
}
}
}
What is that
Your canvas scaler is set to Scale with screen size or constant pixel size? Your aspect ratio is different on each play, so the wind effect just stays out of the screen
-
- Why are you not using the default naming conventions?
-
- Why are you moving the cloud in a
Coroutine?
- Why are you moving the cloud in a
-
- Why are there no serialized values?
i dont use canvas i dont have ui
what is up with that for loop
that too me seems 100% a choppy behavior waiting 0.05 each iteration
that not my problem i know my code is bad
how you know thats not the problem
Right, that my problem
ty for the help
just put this in Update
transform.Translate(Vector2.down * moveSpeed * Time.deltaTime)
you don't need anything else
but i need to tp back the cloud
🔃
transform.Translate(moveSpeed * Time.deltaTime * Vector2.down)
like tp on top
Then check for its position to be sure
Basically have a bottom edge, and when the position <= edge, move the cloud to the startPos
This way you don't have to care about its speed
how can i get the position of my cloud
What?
ok no i got it
I hope so
ok i patch this but the problem is the same
- send current code.
- show what is currently happening
i think i understand why my balloon are slow
i dont * by time.deltatime
but how can i do for the camera?
wdym for the camera?
are the objects moving down or is the camera moving up
unclear
look i dont have the same view when i play and when i build
Hi I’m new to Unity and I just want some tips for the Visual Scripting since I have worked a lot with Scratch when I was younger.
you're not answering, and I think extracting info is a waste if time. So idk
i'm not in mood to play 20 question, you should #854851968446365696 on how to properly get help here by being clear and descriptive
its the object moving down if you talking about cloud like i say before my camera dont move
so if it doesn't move why the hell would you want to apply time.deltaTime to it
i dont say that ðŸ˜
i patch the problem with time.deltaTime
As far I know if you dont use the UI you have to consider the screen width (in your case) and height to ensure your objects are always inside of it
but my other problem is my camera screen size are not the same in build
yes i say i have patch the speed problem with * time by time.deltaTime
sry if i have bad explain i'm not english
you asked how you can do it for the camera
hence why I said, why would you want to do it to camera if its not moving
yes mb
Because when you are playing it on the Editor have the Free Aspect set ( and it looks so extended) and when you play on fullscreen is 16:9 frequently
oh yes its true i forget that
ty
Hi, i am making a space shooter game, and I am uncertain whether to use object pooling or instantiate + destroy.
So far I know object pooling helps performance, by having duplicate objects ready and just reusing them, but if I want to shoot a bullet every 0.5s and deactivate the current bullet when it's outside the screen, for this I will need to create 50+ or more duplicates.
If my game has many bullet types, I will need to create thousands of duplicates, is it worth having better performance but a larger game size?
Please give me some advice, thanks.
Pooling hands down
make a prewarm of 150+ and you should be fine
Instantiating and Destroying will cause much more garbage
Can the pooled objects be reconfigured to be different bullet types easily?
If so do that
Otherwise make a pool per type
you need a good structure first. Talking about bullets, you need a parent class called Bullet and some subclasses that inherits from Bullet (maybe ExplosiveBullet, FastBullet...) so you just have a pool with objects of type Bullet, but at the end each one can be from a different inherit class
Thanks all
ScriptableObject is also another way to just make the Bullet class flexible with multiple data
Why not both.
I'm trying to make a very basic player character for my VR project. I want the player to have a ship model attached to them, which matches the players position and head rotation (minus up and down). But I'm not sure what the model of the ship should really be parented to
Currently my setup is like this, with the "Blue Viper" prefab being the ship model. Everything else is self explanatory I think. Does this parenting hierarchy seem logical?
perhaps you should just copy the head's position and rotation with a script
The XR Origin is the center of your playspace. Parenting to that means the ship is not following the player's head
Wouldn't player camera fit the best then?
Should the XR Origin not be moving along with the player when the player moves ingame (not in real life)?
No
I made a Gameobect/prefab that was outisde the canvas. But now I want it inside the canvas visable. How do I make the gameobject visable in my canvas? I hoped adding the Canvas renderer would fix that lol. but no.
just make a new object in the canvas
your object is still in Transform and not Rect Transform which is what happens when it becomes part of canvas
So to be clear, you think the XR Origin shouldn't move when provided ingame input like from a controller? I'm not referring to head movement IRL
Cannot instantiate objects with a parent which is persistent. New object will be created without a parent. if (activeBattlers[currentTurn].isEnemy) { activeBattlers[currentTurn].ChildPartickleEffect(activeBattlers[currentTurn].zoneHighlight); } the parent object is now an instaticated prefab. but i dont understand the error
I went on unity version control once now I can’t get rid of it, how do I get rid of it?
Oh yeah in that case it should move I think? Tho I don't know about this package you're using
I believe it's called the XR Interaction Toolkit. The XR Rig might be considered a starter asset from it, I'm not sure
which line ?
i have two errors
what is ChildParticleEffect() method
what does that underline yellow on transform say
if i use paint trees i seem to lose the tag of the tree prefab, how else can i check if the object is a tree?
sorry what yellow line
ohh
Looks liketransform belongs to a prefab
thats where im lost i dont understand
but the prefab is a game object, so would it belong to the gameobject
Dont call ChildPartickleEffect on a script component that is on a prefab
Use an actual instantiated object
You are trying to parent it to a prefab, that can't work
If it's still unclear, show how you are calling that method
{
foreach (var battlers in StaticBattleEnemys.enemies)
{
activeBattlers.Add(battlers.gameObject.GetComponent<BattleCharacters>());
}
if (cubes.Length == StaticBattleEnemys.enemies.Count)
{
for (int i = 0; i < cubes.Length; i++)
{
// Assign the enemy to the cube's position
Instantiate(StaticBattleEnemys.enemies[i], cubes[i].position, Quaternion.identity, cubes[i]);
}
}
else
{
Debug.LogError("Number of cubes does not match number of enemies.");
}
}``` So my game objects are instantiated objects of a prefab
But where are you calling the ChildPartickleEffect method from?
Oh here
So these SS level 1 clones hold a script called BattleChars
thats where that method is
Looks like you have added prefabs to activeBattlers
You should add the instantiated objects instead
yes
let me expalin
so a npc holds a script called Battler Starter it holds a list of BattleCharcters(scripts). Im using a Static Class to pass this to a new scene
Then on my battle manager im Adding the static list to a cleared New list
then im getting this error
so yes they are prefabs to start off with then i instaciated them in the battle scene
Ok but again, activeBattlers should have the instances, not the prefabs
How are you adding stuff to activeBattlers?
this one here
So they come from battlers
2 secs let me make a video
I mean StaticBattleEnemys.enemies
And those are prefabs. Dont do that
yes those are prefabs
So the goal was to pass active batters to the battle scene .ie the models and attached scripts
Instantiate returns the newly created object. Add the BattleCharacters from that, instead of from the prefab.
i understand, so the ref from the Instantiate, use that?
Instantiate(StaticBattleEnemys.enemies[i], cubes[i].position, Quaternion.identity, cubes[i]);
make this a new list
and do my work to that?
Something like this cs foreach(var battlers in StaticBattleEnemys.enemies) { var instance = Instantiate(battlers); activeBattlers.Add(instance); }
Hey guys :D i need help On unity with my game
I basicly need a object to always follow another object
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.UIElements;
public class player_move : MonoBehaviour
{
public GameObject bullet;
public float jump_power = 1f;
Rigidbody2D RG;
// Start is called before the first frame update
void Start()
{
RG = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
if (Input.GetButton("Jump"))
{
RG.AddForce(Vector2.up * jump_power, ForceMode2D.Impulse);
}
if (Input.GetKeyDown(KeyCode.R))
{
GameObject newbullet = Instantiate(bullet);
newbullet.transform.position = new Vector2(-10f,0);
}
}
private void OnTriggerEnter2D(Collider2D collider)
{
Debug.Log(collider.name);
if (collider.name == "smallpipe")
{
Application.Quit();
UnityEditor.EditorApplication.isPlaying = false;
}
}
}
this is the code basicly
You can see it spawns the bullet
but not where the player is at
only the middle
and i want to change that
any ideas
I suggest you read the Instantiate documentation and look at all of the method overrides
also !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.
Thank you for your help works a treat
where did you get this position from then
Vector2(-10f,0);
if you want to spawn it on player, pass in the player position..
Hello all, I am placing my character on a moving platform but I am getting two issues.
1: The character isn't sticking on the second moving platform.
2: There character mesh gives off weird stretching when it stands on the moving platform as you can see above.
I have been at this issue for nearly 2 days now, any suggestions are appreciated.
2 the stretching is probably if you parent this to platform and plaform is resized
- is probably you not properly un-parenting and re-parent to second platform ?
(just assumptions based only what you give so far, show the code / setup)
you need the following setup
Empty GameObject
-- Platform
-- Player
!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.
show also how you setup the triggers
If I want to make a question about the asset submission process, which channel should I use?
there is no special channel so #💻┃unity-talk
Hmm pretty sure, I am using the platform as the parent of the player~
Oh yeah, that's one part figured out
yes, dont do that
Isn't this the only way to keep the player on top of the moving platform?
no because the platform and player are children of the empty so when you move the empty they both move
Its starting to make sense, a moving/deformed platformed will deform the player set as a child as well, giving weird results
any object which is scaled will pass that scale to their children
I see, well what about the script? It only works on the first platform but the player will slide like ice on the second one, even though the script is on the other one as well~
this one
is the player getting parented on the second platform?
ok, what do your debugs tell you?
This is jumping onto the moving platform then jumping back to the normal one
This is jumping onto the moving platform then jumping to another moving platform (Player doesn't stick to the second moving platform for whatever reason) ¯_(ツ)_/¯
then your platform setup is probably incorrect
Perhaps, I have multiple collisions and rigid bodies on the Jumping character, might that cause this problem or its def the platforms?
I would say it's the platform. put a debug outside of the if to see if the code is being called at all
I think I got it, there are multiple collisions working against each other lol
I feel so stupid
cant get smart w/o feeling stupid first 😉
glad u fixed it.. platforms are always a Bich
how can i remove a gameobject from a parent in code?
Destroy(transform.GetChild(indexHere).gameObject)
you don't have a reference?
sorry i mean like
how can i change it so an object has no parent is what i meant sorry
.SetParent(null)
yes transform
Yo guys, call me crazy but what the hell is a constructor? Why do we need this guy? Is it a class? Is it a function? Why does it have to have the same name as the class? This is driving me insane!
also constructors do not apply for Monobehaviour
Why is that??
because Unity creates them internally
Why hides things from me?
huh?
I'm having so much trouble man
Learning C# first then trying out Unity Logic is driving me loco
Thank you though, I'll check out the documentation
yes there are differences between unity objects and regular c# objects, but in the end they all are objects
This is what confuse me the most, the fact that MonoBehaviour is an "autoconstructor"
When in C# I need to define the constructor
MonoBehaviour is part of a bigger system
Because a MonoBehaviour must be attached to a GameObject.
You are forbidden from creating a "naked" MonoBehaviour that isn't part of one
It would be bogus to do Component oopsie = new MyCoolComponent();
You can define a constructor for a MonoBehaviour -- but it will execute before Unity applies serialized properties
public class Whatever : MonoBehaviour {
public int x = 123;
public Whatever() {
Debug.Log("Value: " + x);
}
}
This will log Value: 123, even for scene objects / instantiated prefabs that have a different value saved for the field
This is why you have Awake: it runs immediately after Unity creates the component and restores the serialized properties into it
(assuming its game object is active, at least)
Unity has less power over your code than most people think.
consider this example:
public class DestroyMe : MonoBehaviour {
public int val = 100;
}
public class Destroyer : MonoBehaviour {
public DestroyMe target;
void Awake() {
Destroy(target);
}
void Update() {
target.val += 1; // completely fine
target.transform.position = Vector3.zero; // throws an error
}
}
Destroying a Unity Object just tells Unity that it should go away from the game world. You are no longer allowed to use things Unity provides you (like the transform property), but everything else is fair game.
am i a ding dong orrrrr, its saying PlayerLook aint a thing
ur referencing a class called PlayerLook..
unless you have a script called PlayerLook.cs
it show an error
public string[] lines;
```What does [] at the end of string word do
I tried looking on google but i dont know how to phrase it correctly
array
theres probably more to the tutorial or something you've missed @rancid zenith
Nice thanks
i legit know nothing, i just started, im using it the same way im using playerinput & playermotor
possibly
consider !learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
ya, thats what it is.. ur project just doesn't have a class called PLayerLook yet..
once you make one.. that error will go away
alr lemme rewatch the past couple mins of this video
care to share the video? ill skim it
The first video in a series where we are creating a First Person game!
In this video we look at setting up our characters movement.
I've setup a Discord!!! and I would love to have you help me start up a friendly community where we can all help each other grow as game developers!
Discord invite link:
https://discord.gg/xgKpxhEyzZ
Can't wait t...
he creates it around here..
so just keep doing the tutorial.. and it'll work out.. not sure why he wouldn't create the script before trying to access it in another script
or perhaps he does..
important part.. thats what defines the name of the class
noted
Going back to the constructor thingy, there is this stuff called "Primary constructor" where you can put parameters to the class no?
It's a preview feature nah? sorry I'm a noob
future man!
A primary constructor is just used to reduce the amount you have to write.
yeah I figured
But man the "instance" thing is my demon
everytime I see the "new" keyword, I have a panic attack
simple, an instance is just a creation of a thing..
take a chill pill and go follow some Unity tutorialsl
I'm around 1 year and a half of Unity tutorial
I need courses
So much stuff badly explained or plain wrong, now I only do official doc lol
But this is where the real journey start I guess hehe
i learned with tutorials..and yea lot of stuff can be wrong.. but thats when u learn to fact check.. or get a 2nd opinion..
good skill to have in general
Never try c++ then hahahah, this is the real hell
Yeah I'll stay away from this devil's creation
Is it possible to add an entire string array to an already existing string array?
Arrays cannot be resized after creation.
public GameObject Coin;
[SerializeField] float RespawnTimer;
[SerializeField] bool isCoinGone = false;
private void OnCollisionEnter2D(Collision2D collision)
{
Coin.SetActive(false);
SS.Score++;
SS.HealthVal++;
isCoinGone = true;
}
private void Update()
{
if (isCoinGone == true)
{
RespawnTimer -= Time.deltaTime;
Respawn();
}
}
public void Respawn()
{
if (RespawnTimer <= 0)
{
Coin.SetActive(true);
}
}``` why is the respawn void thing not working?
wait leme make it so only the important stuff shows up
it should work.. after isCoinGone gets changed to true
it doesnt tho
are u sure it doesn't get called? or rather Respawn Timer conditional isn't true
public void Respawn()
{
Debug.Log("RespawnFunctionCalled");
if (RespawnTimer <= 0)
{
Coin.SetActive(true);
}
}```
try debugging
i put a log in the if isCoinGone statement
and ive noticed that its always on
theres a bug
if i turn it on manually the timer goes down but if it turns on from the collision it doesnt start
so the code should work?
like the code isnt the issue?
use debugs and find out.. put them everyhwere so u can trace whats happening
yeah i found alr an issue thats kinda wierd
but idk how to fix
possibly ur collision isn't working correctly
On Respawn I think you should reset your RespawnTimer
^ thats 1 thing i noticed as well..
so if RespawnTimer = 1 RespawnTimer Return;?
Your RespawnTimer just go down and down but it is never reset
public void Respawn()
{
if (RespawnTimer <= 0)
{
Coin.SetActive(true);
Debug.Log("Coin respawned.");
// Reset the RespawnTimer
RespawnTimer = initialRespawnTimerValue;
Debug.Log("RespawnTimer reset.");
}
}```
as you can see all coins are present, the isCoinsGone bool is set to false yet the Debug.log is happending
ya, after that first respawn.. ur timer is already lower than the threshold..
gotta reset it for it to be useful
That's it, the condition will be always true if you do t reset the timer
so if i have a variable and i put initial then the variable name it will reset the variable to the set number?
sorry im still learning the inital thing is new to me
ya, at the start of the script u should cache what ur starting value is..
and then once u trigger the respawn reset the timer back to what it started as
Add this log in Update:
Debug.Log$"{gameObject.name}'s IsCoinGone = {isCoinGone}, Respawn Timer = {RespawnTimer} Coin = {Coin.name}");
i usually count upwards.. that way i dont need an extra variable..
oh this is not what i tought
i just reset the timer to 0..
so in my case i just do RespawnTimer = 3;
if 3 is the value u want..
i tought if i put initial it would like reset the value of the variable to the value i gave it by default
theres a tiny issue tho
my float is Serialized cause i have multiple and i wish for them to respawn well at diff times but thats kinda hard to do so i gave each coin a diff value
digi's debug is a good choice imo shows all ur data in 1 string/sentence
nothing wrong with that.. b/c each coin is it's own instance.. (version)
so u can use different values if u wish..
and thats y i said to cache the value..
u shoulnd't need to hardcode a value
yeah but how do i reset it the to preset value?
[SerializeField] float initialRespawnTimer;
float RespawnTimer;```
if i do RespawnTimer = 3; then every coin will respawn every 3 seconds
wait im kinda stupid
nvm
RespawnTimer = initialRespawnTimer;```
private void Start()
{
// Store the initial respawn time when the coin is instantiated
RespawnTimer = initialRespawnTimer;
}```
bro, how fast can you type?
b/c i already have the script in a notepad
copy and pasting
thats y we urge people to post code.. instead of screenshots 😄
no but i tough if i do do RespawnTimer = 3; then they all would respawn at the same time lol, that would only happen if all coins were picked up at the same time
you can set ur initial value for each coin however u want..
the private variable cache's whatever you use
soo if u use a coin with a 4 it'll reset the timer to 4.. if u use one with 3. itll reset to 3
public GameObject Coin;
[SerializeField] float RespawnTimer;
[SerializeField] bool isCoinGone = false;
private void OnCollisionEnter2D(Collision2D collision)
{
Coin.SetActive(false);
SS.Score++;
SS.HealthVal++;
isCoinGone = true;
}
private void Update()
{
if (isCoinGone == true)
{
Debug.Log("You picked up a coin");
RespawnTimer -= Time.deltaTime;
Respawn();
}
}
public void Respawn()
{
if (RespawnTimer <= 0)
{
Coin.SetActive(true);
RespawnTimer = 3;
}
}```
this is the whole code
because it just caches the value in start
Each coin has her own timer, they don't share the variable
^ 
nah its fine
yep thats why i serilized the Variable
sorry i forgot
so this code should work?
It should, but is better to don't use magic numbers on your code like the 3, is better how spawn says
magic numbers suck
what are magic numbers?
hardcoded values..
myCar.color = blue; vs
and then u can set desiredColor however u want in the inspector ```
the first one would be a magic number / color..
uhm so i did smth and now smth else happened
Yep, you can use direct values to initialize a variable, but no far from there
everytime i ran the game this if (isCoinGone == true) { Debug.Log("You picked up a coin"); RespawnTimer -= Time.deltaTime; Respawn(); } would always go on now i turned smth off and it doenst spas out anymore
the isCoinGone bool was turned on in the inspector
which is wierd to give me an error since i made it so the bool is false by default
hm wierd
the if statement isnt working
this is interesting
if i start the game and i check the isCoinGone bool on in the inspector the code works
but if i pick up the coin which still turns on the bool it doenst
You should also write the statement like if(isCoinGone) since is a Boolean itself
my game feels like its running in like 30fps, its very choppy when i move, i.e: i can see the cubes skip frames when I move
public class TimerScript : MonoBehaviour
{
[SerializeField] private float startingTimer = 10f;
private float currentTimer;
private void Start()
{
currentTimer = startingTimer;
}
private void Update()
{
currentTimer -= Time.deltaTime;
if (currentTimer <= 0)
{
currentTimer = startingTimer;
}
}
}``` here is a timer that i could use for different objects all having different values to count to... in the start method we just cache w/e we have set in teh inspector
```cs
using UnityEngine;
public class TimerScript : MonoBehaviour
{
private float currentTimer = 10f;
private void Start()
{
}
private void Update()
{
currentTimer -= Time.deltaTime;
if (currentTimer <= 0)
{
currentTimer = 10f;
}
}
}``` this version uses a hardcoded value... it can only ever work if our value is 10
what does boolean mean?
true or false... (on or off) (0 or 1)
bool
but if i write if(isCoinGone) how would the code know to check if it should only run if the bool is TRUE
oh
The type of your variable, like int (integer), float, bool (boolean)...
so just remove the == true?
You can see the FPS if you press stats once you play. Start from there to see if there is a problem of optimization
k lemme check the fps
well nothing really changed
what if i move the if statemnt into the OncollisionEnter Void?
😈 like my FPS counter?
that did smth
well im getting like 600fps, but it looks fuzzy when im moving for some reason
Don't set timers directly to to their start value if you keep them running like that, since u would accumulate some difference over time. Instead add it to the timer, then you will have more constant intervals.
the edges become a little fuzzy and less defined
ohh true, ive heard this before but i always forget about it
i use coroutines more often than not myself
any idea why this occurs
i so i put the if statement into the oncollisionEnter method and it fixed smth
now it works but not rlly
theres a gameobject in ur scene that had a script on it.. that got deleted or renamed..
if i pick up a coin it tells me that and it also only goes off once
Some object has a component (script) that you have deleted
but the RespawnTimer only goes down by 00.2
its whenever i add a script
its cause it only happends once
it occurs
if i maybe add another if statement then i can make it so it goes down
what if i make it so if the respawntimer is smaller then 3 it should make it even smaller
ðŸ˜
RIP
it gone..
remove that
thx
To ensure, shut down your pc and change the hard disk, it doesn't look ok
what
idk lol
Just joking, I thought the file of your script was corrupted by a bad hard disk
i think theres an issue with my update method
I have a public array(X1) in a script(Y1) and i have another array(X2) in another script(Y2),
Is there someway i can replace array X1 with array X2 while using script Y2?
Theyre both string arrays
You want to use the same one so both want to modify the same array or just a copy of the array?
What's the best way to get an object to ignore collisions with another specific object, but collide with everything else?
Use the tag of the objects
How?
Array X1 is just there to be modified, its empty most of the time. I want to replace the contents of array X1 with the contents of array X2
Set a tag on you object and in the method OnTriggerEnter2D(Collider2D other) just add a simple condition like: if(other.CompareTag("Player")), so it will only work if the object that start the trigger is the type of player
public GameObject Coin;
[SerializeField] float RespawnTimer;
[SerializeField] bool isCoinGone = false;
[SerializeField] bool TimeStart = false;
private void OnCollisionEnter2D(Collision2D collision)
{
Coin.SetActive(false);
SS.Score++;
SS.HealthVal++;
isCoinGone = true;
if (isCoinGone)
{
Debug.Log("You picked up a coin");
TimeStart = true;
}
}
public void Update()
{
if (TimeStart)
{
RespawnTimer -= Time.deltaTime;
Debug.Log(RespawnTimer);
if (RespawnTimer <= 0)
{
Respawn();
}
}
}
public void Respawn()
{
Coin.SetActive(true);
isCoinGone = false;
TimeStart = false;
RespawnTimer = 3;
}``` why is this code not working 😩
so i started making my game work for multiplayer, but then it kinda messed up the single player, this prob related to the player or whatever having netcode properties while the scene doesnt have an object woth a network manager, but i dont know exactly what to od here, here is the error:
what is liek the best way to make a scene not think of the multiplayer stuff?
You should be able to change the reference as in this little example: https://hatebin.com/rvcyivyyej
First of all, your condition on the OnCollisionEnter2D will be always true because you set directly to true on the line before, so this doesn't have too much sense
yeah i put the if statement there because if i put it in update it breaks
idk why
yeah now the debug isnt even working
public GameObject Coin;
[SerializeField] float RespawnTimer;
[SerializeField] bool isCoinGone = false;
private void OnCollisionEnter2D(Collision2D collision)
{
Coin.SetActive(false);
SS.Score++;
SS.HealthVal++;
isCoinGone = true;
}
public void Update()
{
if (isCoinGone == true)
{
RespawnTimer -= Time.deltaTime;
Debug.Log("You picked up a coin");
Respawn();
}
}
public void Respawn()
{
if (RespawnTimer <= 0)
{
Coin.SetActive(true);
isCoinGone = false;
RespawnTimer = 3;
}
}``` this is the original code
and it still doenst work which makes no sense
Your console show any error? Maybe you think the error is in this code and something is just breaking the game and make it stop working
if i pick up the coin then the bool should be set to true and every frame it checks if the bool is true
no error
it doesnt break the whole code
and if it is then the if statement should go off and in the if statement it always checks on the respawn method which has a if statement that only works till the Respawn timer is smaller or reaches 0
private void OnCollisionEnter2D(Collision2D collision)
{
if(!iscoinGone){
Coin.SetActive(false);
SS.Score++;
SS.HealthVal++;
isCoinGone = true;
}
}
try changing this method, this way it will just iterate once
then it should spawn in the coin then set the isCoinGone bool to false shutting down the if statement in the update method
but then wont the code only work if the isCoinGone bool is true? which by default is off and gets turned on in that method/
I add the ! at the beggining, that just make the opposite
It's translated like a not
Try changing like this:
public void Update()
{
if (isCoinGone)
{
RespawnTimer -= Time.deltaTime;
if (RespawnTimer <= 0)
{
Respawn();
}
}
}
public void Respawn()
{
Coin.SetActive(true);
isCoinGone = false;
RespawnTimer = 3; // Reset timer
}
So it's the update the one that checks if the timer is less than 0
i tried that too
but i found smth interesting
{
if (isCoinGone)
{
Debug.Log("Coin isnt there");
}
else
{
Debug.Log("Coin is there");
}
}```
i added this to my
update method right
well it works as intented
but it only says Coin Isnt There if i pick up ALL the coins
Your code is not that complex, something may be wrong in other part
yeah but shouldnt this be smth we should look at?
the Debug.Log("Coin isnt there"); only runs if i pick up ALL the coins
it may be there but being pushed out of view by ur debugs..
shuld collapse ur debugs so duplicates just get a number added to the side of it
i do have that
doesnmt everyone?
add private to your variables
[SerializeField] private float RespawnTimer;
[SerializeField] private bool isCoinGone = false;
lol.. somepeople dont
just checkin
🤮
can't remember if its default setting or not
but isnt SearlizeField just Private? but it shows on the inspector?
its not
a private variable w/o serialized field can't been seen in the inspector
so i cant see my variables in the inpector now?
by using serialized field on a private variable.. u keep it so other scripts still cant access it. but its visible in the inspector (as a public field would be)
Nop, it doesn't, you have to specify
Yep, as the parse of the variable. Use the same for all your variables, it's better if you start with lowercase, so you can easily difference the classes from the instance of the objects
i dont even understand the issue tbf
{
if (isCoinGone)
{
Debug.Log("No more " + Coin);
RespawnTimer -= Time.deltaTime;
Respawn();
}
}```
this isnt running
it should run when the isCoinGone bool is set to true
true
which gets set to true if i collide with a specified thing
show that part
{
Coin.SetActive(false);
SS.Score++;
SS.HealthVal++;
isCoinGone = true;
}
this works tho
when i collide with the specified game object the isCoinGone gets checked
Coin.SetActive(false); if the coin gets set to InActive.. the update loop wont run anymore
so the code stops with it too?
how.... do fix it tho?
where should i play the Coin.SetActive(false);?
i cant place it in update can i?
😷
that way u can delay the setactive part.. until the rest of hte code finishes
idk what that is
lets back up..
what is it that you want to happen?
and also !code share ur code in a paste-bin link so i can see the entire thing
📃 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.
when i collide with the Coin i want it to dissapear then i want to get 1+ in the score and an extra second to live (u get 5 at the start) then i want the coin to respawn after 3 seconds
pretty simple
yeah i wrote the code myself with no issues so ofc its simple
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
here
can someone walk me threw on how to export your game as a apk
its easy?
you go into build settings and switch the platform to andriod
tbh i should also ask why i couldnt export my game i had some issues with gardle and i couldnt export it
which sucks but maybe i can get help here
sure/
ok i made a call
You can use the same code, but don't add it to the object that it's your coin. You can have a parent (we could call it Coincollider for example) that will have the component Collect and the Collider and a child object inside of it that will just have the sprite of the coin
oh
alright check this out
the graphics are seperate from the coin.. that way i can disable the gameobject..
you could use a single object. and just disable the meshrenderer instead.. meshRenderer.enabled = false;
so i make an empty gameobject with the collider of the coin and when that collides with the player it turns off the coin but not the collider
wont that make it so you can always colide with it?
but what happens is i enter the trigger:
- the coroutine starts
- it disables the graphics
- and disables the collider (so now we can't collide with it anymore)
- it then waits 3 seconds
- and re-enables everything
i used a child for the graphics... so i could just disable the graphics (this keeps the script running because i dont disable the main gameobject with teh script)
orr.. u could reference the Mesh Renderer.. / sprite renderer/ or w/e and disable that instead
but i disable the graphics and the collider <-- thats the main point.. b/c we want the gameobject to still be active and run the Update()
It worked, thanks man
u could also
- Coin Object
- Graphics + Collider <-- just disable this gameobject
to disable both the graphics and the collider at the same time
many ways to do it. but the idea is to keep the Coin (Script) running
just disable the collider intead
and i Use a coroutine.. b/c its better than a timer.. (imo)
alr
how can i repeat a block of code a set amount of times? i know theres a for loop, but what if i want a delay between loops?
what if i make a gameobject put the code there?
it should still work right?
if it collides with the GameObject specified in the inspector which is coin 1 it should turn it off but its not the gameobject running the code
Collision events have to be run from a script on teh same gameobject as the collider
oh
u can't put the script else-where and expect it to log collision events
from a different collider
the reason i referenced the collider is just so i can disable it.
how can i turn the collision off on a gameobject?
now u can disable other colliders and things from different scripts.. but the Collision events dont work that way
u either set the collider to isTrigger or on the collider itself u can chose a layer to exclude
and put ur objects on that layer that u want to ignore
u can also do it globally from here
u can uncheck certain layers.. soo entire layers ignore each other
huh?
but cant i dissable the collider of the empty GameObject Thru Code?
float SpeedX, SpeedY;
Rigidbody2D RB2D;
public SpriteRenderer SR;
void Start()
{
RB2D = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
SpeedX = Input.GetAxisRaw("Horizontal") * MovSpeed;
SpeedY = Input.GetAxisRaw("Vertical") * MovSpeed;
RB2D.velocity = new Vector2(SpeedX, SpeedY);
if (RB2D.velocity.x > 0f)
{
SR.flipX = true;
}
else if (RB2D .velocity.x < 0f)
{
SR.flipX= false;
}
}``` as u can see here im turning the FlipX thing on and off at will
you can disable any collider u have a reference to..
If it will always be the same delay you can do with a Coroutine where at the end of the loop just do a yield return new WaitForSeconds(x);
[SerializeField] CircleCollider2D CC; this is how il refrence it but how do i call it?
CC.enabled = false;
oh
i tought smth like CC.Collider = false
wait im so stupid it makes more sense if u say it idk
no.. ur referencing a collider..
yep i just realized
aCollider.aCollider doesnt make sense
yeah i just realized
CC is the collider itself not the game objects that contains it
affermative i just realized
^ if u referened a gameobject with CC
then it would be
CC.GetComponent<CircleCollider2D>().enabled = false;
which would get a CircleCollider2D from the gameobject thats called CC
ok
omg it works
dude @rocky canyon me and 4 other guys have been stuck on this issue for 8 hours
glad i could help
im not kidding i started making this feature at like 15:00 now its 00:27
ive asked in brackeys in the gamejam server
😅
and it was such a simple thing ðŸ˜
ya, i figured once i wrote a script and showed a video.. it'd kinda start to make sense
heres a tip to keep in mind..
keep ur graphics and ur logic seperate
always!
- Root Gameobject
- Graphics
oh
it'll save soo much trouble in the long run
if u want to do stuff w/ ur graphics u shouldnt have to worry about ur scripts stop running
same w/ the colliders and whatnot..
its not always the case.. but its easier to know that ur script is running on its own gameobject
and physics and rotations go crazy when ur scales are different than 1:1:1
so thats another reason..
ur root object should always be scaled to 1.. and that way ur graphics can be resized as a child object and it wont affect the way physics interact w/ ur object
like the example i sent earlier.. my coin is actually a squished sphere..
thank you
but i squish the child object.. so the Coin object is still scaled to 1:1:1
Quick question, is there a Physics.SphereCast equivalent for Physics2D? All I'm trying to do is to check if there's a collider in the specified area but they all require to provide a Collider2D list, or RaycastHit2D list, or they return a RaycastHit2D/Collider2D result, I don't know how to check if there's an object or not in the specified area
You could just use the return value and check for null. The ones that return Collider2D will return null if nothing hit
I have to filter or check if there's more than one collider 'cause it detects the 2d capsule collider as well, I have the controller as a children
so far everything I've tried always returns true so I'm trying to understand what's happening
coming from the 3D side this is quite weird for me x)
I believe in 2d, casts will hit the object it started inside of. Maybe do it based on layer, or just use the list and check if the length is greater than 1
Does anyone know how to input small float values in the Unity inspector?
I can't fade the image out smoothly because small steps are visible during the fade
0.001 seems to be fine, but steps of 0.0001 aren't visible
show the code you are using to actually fade it out. because it seems like you are hard coding the steps rather than gradually fading over time
if (heartcounter == 4 && SceneManager.GetActiveScene().name == "Level2")
{
SceneManager.LoadScene("Level3");
}
This code works sometimes but sometimes the other scene doesn't load
Does anyone know why that happens
well for starters, why do you need to compare the active scene's name instead of just incrementing the current scene index and loading the next scene with that? also have you done any debugging to ensure this code is actually running and that your conditions are what you expect them to be?
Would it make a difference if I used an index vs using the scene name
Is it for performance?
no, it would reduce the amount of very similar code. because i'm just gonna go ahead and assume you have a very similar check for moving from Level1 to Level2
and it would remove a mostly useless check
this is the fade out code?
that is someone entirely different
I have debugged it and it works but sometimes the scene doesnt load
have you confirmed that code is running at the time you expect the scene to load but it doesn't?
Yes it usually only doesnt load when its built. It works fine most of the time in the game view
and have you done any debugging in the build to ensure the code is running and your conditions are what you expect them to be?
you've also not shown the context for this code, so this is really the only advice i can provide
How do i debug in a build
build as a development build and attach the debugger. you can use breakpoints and tracepoints to see what your code is actually doing
Ok thanks i will try that out
The code is a bit complicated, but here it is:
float opacitySpeed = CalculateOpacitySpeed(Mathf.Abs(OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, ovrGrabber.GetM_Controller()).y));
//Checking for controller input, that's just the example for the downMovement of the stick:
if (downMovement)
{
currentColor.a = (Mathf.Max(currentColor.a - (opacitySpeed * Time.deltaTime * 0.8f), 0f));
controllerItemCollection.opacityDownIcon.transform.localScale = Vector3.Lerp(controllerItemCollection.opacityDownIcon.transform.localScale, downIconScale /*the target*/, Time.deltaTime / scaleLerpTime); //TODO: put the code from the bottom from scaling inhere, this seems more responsive
}
float CalculateOpacitySpeed(float thumbstickPosition)
{
if (thumbstickPosition < activationAmount) return 0; // No scaling below 20%
else if (thumbstickPosition >= activationAmount && thumbstickPosition <= 0.95f)
{
float normalizedPosition = (thumbstickPosition - activationAmount) / (0.95f - activationAmount); // Normalize position to range 0-1
float speedFactor = normalizedPosition * normalizedPosition; // Apply quadratic curve for more noticeable speed change
return minOpacitySpeed + (maxOpacitySpeed - minOpacitySpeed) * speedFactor;
}
else return maxOpacitySpeed; // Use maxSpeed above 80%
}
The whole code is in the update method
put the 'cs' on the same line
hi
i have this simple issue where i cant call a function from my other script
don't ask to ask
that's what i have done, it's weird
i just said hi
yours is on the next line
fair enough
but your second statement definitely lacks information
yep i was about to provide it
sorry, go ahead :)
as you can see i am trying to call on my script SoundManager but it gives me an error, the thing is ive called ScoreSystem the same way and still no error
ah, fixed it
it just says the namespace couldnt be found
show your soundmanager script
using System.Collections.Generic;
using UnityEngine;
public class SoundManager : MonoBehaviour
{
public AudioSource Shark;
public AudioClip eat, die;
}
simple code
it says that cuz it assumes that u wouldnt try using a script that doesn't exist
so.. if it does exist.. its probably a simple mistake like u forgot to add the namespace
but most newbies.. the script is just missing
very tiny
does this error happen when you try and run the game too?
i didnt try to run the game im trying to add sounds
okay but will it let you run the game?
and whilsts i was calling on the sound manager script it just gave me this error
does this error show up in the editor?
no
has this been saved?
yes
odd
by that i mean i fixed the formatting in discord
y u have so many problems
yeah
ask my parents
oof
try going back into unity and letting it recompile
then just ignore it or re set up your ide idk
By the way, I don't think there is a problem in the code, since it logs the values correctly. They gradually increase, but in very small intervals. Unity just seems to round them up for the opacity
what
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
oh yeah found the issue
if you try this again it might go away
what was it
its set as a misc file
lol
how... do i change it?
everything else is in asemble.C#
leme just reboot visual studio
yep there u go
if unity used doubles instead of floats, would that glitchy effect not happen when you get far away from the world?
If the method returns Collider2D, you'll get null if nothing was hit.
If the method returns RaycastHit2D, the collider field will be null if nothing was hit.
If the method takes a list, it will return an integer that tells you how many things it hit.
It would take much longer for it to happen, yes
Although, that glitching is caused by rendering
you'd have to be using doubles on the GPU
why does unity use floats again?
because floats are smaller (4 bytes vs. 8 bytes), and float math is much faster
right
it's the same reason that you use half-floats for machine learning
are there any engines that use doubles?
dunno off the top of my head
Unity does have a Double4x4 matrix struct that you can use to do all of the usual transform math with doubles
I've experimented with using that for one of those "scale of the universe" visualizers
you know, where you zoom out from a cell to the size of the universe or whatever
everything stored its actual position as a Double4x4, which was then used to set its actual position, rotation, and scale
hey
kinda need some help. Made my items persistent by attaching a dontdestroy on load script to them the items are children to the dontdestroy script
found this bug that i have no clue on how to fix for the time being where if i pick up one in the room it shows up in the slots but if i leave with said item come back to said room pick up another the 2nd item does not show up in the 2nd slot
is float3 still a thing?
getting hastebin code now
https://hastebin.com/share/vuyenegila.csharp
the onitempickup from the inventory view selector
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
and the itemData stuff
https://hastebin.com/share/livezarika.csharp
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Yes. It's part of the Mathematics package
Doesn't shaders use it?
i think so..
thats where im seeing it
wasn't sure if it was outdated
but it is indeed in the mathematics lib
float3 is more performant.. i think
im still reading on it
are rooms different scenes?
yes
@ashen niche What happened after you did it?
nothing rlly tbh, just made movement a bit smoother
How do I have an object instantiated after the game starts running set a reference to an object that's existed since the game started running?
Also, I saw you had been multiplying with Time.deltaTime. You don't need it if you think it is making the Movement stable for every system. Time.deltaTime is only needed in Update, not FixedUpdate as it already uses it at default.
I have a grid whose tiles are prefab objects, and I'd like them to have a reference to the gridManager object that created them
that's not entirely correct. you still do need to multiply values by deltaTime when you need to increase something overtime at a specific rate of time
Thank you for the corrections. I'll keep that in mind 
I'm creating the player controller and Im using a CharacterController to have the player walk around. The thing is, I want to have the player fly on a broom occasionally. Can I still use the CharacterController for that? or do I just disable it and enable a RigidBody?
You can use the CC still
I don't really see an issue with the code that you sent, outside of the using Transform to move. Is there another place where you add movement?
moving via the transform is 100% the cause of their issue. doing so does not respect colliders so they are more easily able to penetrate into other colliders even with continuous collision detection
you've likely omitted the code that actually causes this behaviour
I'd think most likely you're clearing the _slots list/array somewhere
yeah i honestly dont know why i only highlight the pickup part let me fetch the rest
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
here the whole inventory select
is this on a DDOL GameObject?
he mentioned his items are children of a DDOL i think
the menu no
the way it works is the player, misc controllers and inventory are children in a dontdestroy object
i do it this way cause the script has an object index
as to destroy duplicates
//In Tile.cs used by the Tile prefab within the Tile class object
public GridManager grid;
//Class header in the script used by the GridManager object present in the scene
public class GridManager : MonoBehaviour
Why am I getting a type mismatch here?
are you trying to drag a scene object into an asset like a prefab? because that's not possible
I am making a game where the Player can turn into two types of forms (outside of their default), a Gear Form or a Super Form. I am wondering how I should keep track of these two Groups. Should I use GameObject arrays or Lists. I ask because I won't have more than 10 forms for each Group. Which method would be more effective and easy to navigate for this concept?
That's about what I'm trying to do. I would like the instantiated objects to be able communicate with the scene object after they're created
How do I do that in code?
if it helps this is how the ddol is laid out
Ah thank you
I'm also curious why Type mismatch is the error it gives me
Or why it lets me try to select a scene object for that field
why are you choosing between arrays and lists? they are practically the same, except that List can have things added and removed at runtime while the size of an array does not change without a new array being created
I'm not totally sure I follow to be honest, but there's not a lot going on I'd say - you've got one list and it's clear there's a mismatch between what is contained in it and what you expect there to be. I'd add some debug lines to check what is actually in that list as you pick up an item, leave the room, re-enter the room, etc
it just uses the same menu for all unityengine.object assigned fields, including the ones in the scene. so for the ones in the scene you need to be able to select an in-scene object
Well that makes things easy. I never use Lists so I was just checking if I was going to have technical debt in using GameObject Arrays. Thanks!
i mean your arrays should also not be GameObject type but rather the type of component you actually care about using
ok to explain before i got back and try with debug logs
if i start to play and pick up item A it shows up in the inventory slot not problem the problem arises when i leave the room to next scene and come back to pick up item B thats were the problem is im able to pick it up cause the object disappears as it pickup code tells it to do
its that item B upon pickup wont show up in the second slot
even tho i picked it up
and now that i think about it i might need to look at the pickup code
to be clear I understand the problem, but I don't follow your explanation of which script is which
if InventorySelectController is not on a DDOL object, that is your problem
this is the inventory ui controller
this is the ItemData script
if it is, then I'd add some debug logs to check what the status of that list is as you change rooms
yeah, sounds like a reasonable next step if the data structure is correct
this snippet of code is the source of my trouble
pick up item before leaving room
debug log tells me a slot has been filled
leave room and come back and pick up test cube
debug log says nothing
only the first log of a slot being filled
this is a location in the gameworld right? Im tryna lerp toward it but it seems my object just goes endlessly
show the full line of code and surrounding code
this gives absolutely zero information
err...
I dont necessarily need a direct answer to the problem
because its like 250 lines long
I just need to know what Im doing
(I dont)
a lerp is not 250 lines long
and no one can help of saying
"this is my add force is it correct?"
transform.postion + 65f + other.position - 32.0005f
show the line of code with lerp, and where is it placed, in Update? or how is it called
I think the problem Im having is I have multiple areas where I call lerp, and Im finding out that stacking lerp calls doesnt work that great
impossible for me to know the problem by just seeing a bit of maths
so i cant really help either
I think Ill try a different solution
I dont rlly want you to have to read 250 lines of spagetti
i wouldnt read 250 lines anyway 😂
just find the lerp and what i need
Like you can see from the vid, I am lerping to a bunch of positions
I changed it now to a timer, but it still looks jank
why not use an animation?
Am compsci student and thought it would be fun to do it that way
because if I animate it its not a "coding project"
well theres probably better ways than lerping anyway
also isnt procedural better to be able to apply recoil patterns to a bunch of things? Instead of animating them individually
Like I can just change some numbers and have a different recoil strength for a dif gun
this is the opposite of procedural im pretty sure
huh
sooo, show the code we actually need to be looking at?
(Im tryna figure out the difference)
wym
just imagine the movetowards is a lerp and that is the code
the current code, the one with the lerp, the one your trying to fix
So the issue Im having is that because (as you can see from the video) I am lerping/movingtowards a bunch of different positions, and they dont work well with eachother
ive never seen if(UnityEngine.Input.GetKey)
you import Unity for a reason so you can do just Input.GetKey
Yea I had it like that and then VS kept flagging it
I am pretty sure it works either way
i guess, just unnecessary and long for no reason