#💻┃code-beginner
1 messages · Page 408 of 1
I'm not even sure that would compile
You need to pass some parameter to the debug log method.
hello there, so another error occurred with the game, now the player flies among the camera orientation, can i send a short video of the movement?
like this?
would taht work?
I have no idea cause i have something spamming in the console
how does it not exist
did you set a bool in the animator window for wall sliding
no
i deleted it and it fixed it
idk then maybe you 2 or something
okay, debug log now shows me it works but the roll itself does nothing
does it "yes" get loged in console
yes;'
ok so now you know its prolly something with the animation
no you need to set one
The parameter has to exist.
Did you actually create a Trigger parameter called "Roll"?
bool/float/int parameters do not count
Yeah I have one
show us
like, in Unity?
Show us the animator window with the parameter list visible.
yea like a screen shot
Ensure that there is not a space at the end of the name
Then show me the inspector for PlayerMovement.
yo Fen i also have a rq question
this one?
Oh, right, Animator is private and assigned in Awake
Make sure that the Animator on the same object uses the correct animator controller
Double clicking on the "Controller" field should open the Animator window
This is my Animator
double click the "Controller" field and ensure that the animator window is still showing the same controller
i.e. this one
yeah its showing
Clear your console, make sure you are not in play mode and that there are no words in the console, take a screenshot of the console.
The unity console where logs are displayed . . .
If it's empty, then it's fine(assuming you don't have errors hidden)
Yeah I know?
yeah there are no errors
If it's empty then start the play mode again and see if the warning appears.
when entering play
Take a screenshot of the whole editor window
Was the name of that script changed or deleted?
ok so rq before anything this code is just me testing and prototyping ideas, but baically the function run is to check if there is a tile next to this tile and if not the it returns null, in the if statments im checking if the return comes back null but and return a false if it does the timer max is set to 10, anyways im getting back a null error and idk if im just stupid or what so do you guys know why this is comng back as a null error and not a true or false?
I deleted the script but it was from an object i tried to do something with before
sorry ik its a lot
which one's that 😅
The unity editor. The whole thing.
Which line is line 42?
Okay, so you are no longer getting the warning about the trigger not existing?
Share the !code via a paste site such that we can see the line numbers.
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
yea
We can't tell which line is 42 from the pics. That is the error line. Use the links from this post: <#💻┃code-beginner message>, to send your code . . .
else if (GridManager.GetTileAtPosition(new Vector2(transform.position.x, transform.position.y+ 1)).tag == "Water")
Something in here is null.
I presume that GetTileAtPosition returned null
and then you tried to access the result's .tag member
yep sorry i walked away for a sec
here it is tho
and it changes based off of where the null tile is
it has to do with it not recognizing the null yk
this is the entiriety of my rolling code, is there something wrong with it? https://gdl.space/qusiseqaxi.cpp
it gives no velocity whatsoever
If you attempt to access a member from a null reference, you get a null reference exception.
MyClass x = null;
x.foo = 1; // error
x.Bar(); // error
I put a debug.log into the part after private.void StartRoll() and it doesnt show up so maybe theres something wrong with that part?
That sounds relevant, yes!
If the log message is the very first thing in the method, and the log message doesn't appear, then the method isn't being called at all
but even if the function should be returning null
I don't understand what you mean by that.
If the function returns null, and you try to access a member from the resulting null reference, you get an error
wait i see what you mean
okay so actually it stops working at if (Input.GetAxisRaw("Roll") > 0), 1 line before it sends a message after it doesnt
Will this hurt me long term or nah?
It fixes the error though I'm not sure why it happened to begin with.
What is AnimationTriggerType?
I'm guessing you declared AnimationTriggerType as an enum inside of Player
using static lets you access things from a type without explicitly using its name (much like using lets you use stuff from a namespace)
Wait, so you have the same type (enum) in both of the Enemy and Player classes?
If they're meant to be the same thing, then you should not be declaring them inside of other types.
you should declare the enum once
also would there be a way to change the collision while rolling?
That's kind of the head scratcher as there is no reference to the Enemy in my Player script. That does answer my question though so thank you!
as there is no reference to the Enemy in my Player script.
That has nothing to do with what I said
I think you need to show us your code here. You're probably doing something wrong here.
gotcha
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
hey guys is something wrong with this lin e
(Input.GetAxisRaw("Roll") > 0)
presumably you meant to put an if somewhere in here
Wrong in what way
the script doesnt work after that line
before all's alright
define "doesn't work"?
doesn't run, debug.log doesnt show
Is your console window open?
yes
Do you have errors?
no
You sure? What Debug.Log are you expecting to show?
Code doesn't just "stop running" silently
If the code after that line doesn't run that usually means you have an exception happening
for example maybe you didn't define an axis called "Roll"
that would show as an error in your console at runtime
Show the rest of the code and show your console window when the code runs
Share the entire script.
add them back
aight
it's important to know which logs are not running as you expect
Always show the code you were running
don't remove things
(especially don't try to "simplify" your code)
those are not errors, they are warnings
Apologies my code is a bit of a mess. 😔
I don't see why it wouldn't be able to find the AnimationTriggerType enum. The enum is a nested type inside Player, and the function is also a member of Player
oh right, but still only things ive got
what is this in reference to?
Do you have another AnimationTriggerType defined somewhere else?
It sounds like you might have three of them
Share the code with the logs back in
https://gdl.space/uvowacajij.cs
the code works up to line 116 (or at least thats what debug logs show)
Then Input.GetAxisRaw("Roll") > 0 is simply not true
the entire point of an if statement is to guard a block of code based on a condition, yes
Debug.Log($"Roll axis value is {Input.GetAxisRaw("Roll")}");```
This has absolutely nothing to do with your problem
C# is unaware of what objects exist in your scenes
Someone could help me with a problem with a terrain generation?
Doesn't show up
where'd you put it lol
put it BEFORE the if statement obviously
No I have a third script that applies that cube where I tested the code to begin with. It also has that AnimationTriggerType.
If these are all meant to be the same enum, then you should declare it once.
Roll axis value = 0
Mystery solved
Right now, these are three completely unrelated types:
Player.AnimationTriggerTypeEnemy.AnimationTriggerTypeAnimationTriggerType
They are not interchangeable.
0 is NOT greater than 0
how can I fix that
did you actually create an axis input called "Roll"?
Yea
Where and how?
presumably press the button that you assigned to that axis
the button is R and i press it doesnt work
show your axis configuration
clearly not bound to the R key
removed it by accident rn
but it was
i was rolling to get to the debug logs no
pressing r
fix it then show screenshot again
also wouldn't you jsut do GetButton("Roll") if all you want is a button?
That makes more sense actually. Which is why I had to declare it as a static variable like you said.
Yeah I have 3 different ones. Test Cube wasn't at all related.
Thank you. Noob question it feels like.
Quick question, instead of Navigation(Obsolete)
How should I reference Navigation?
Is it the same or have some values been replaced?
i should point out that the component being attached to "Test Cube" doesn't matter here at all -- all that matters is that you wrote a C# script that declared an enum type named AnimationTriggerType
It sounds like you want to delete the AnimationTriggerType types from Player and Enemy, so that everyone can use the same enum type
i dont know
Yeah I understand that now. Completely wrong assumption on my end. But I appreciate you reiterating so I don't misunderstand going forward in the future.
I know. You would.
Man don't be so harsh on me I just started
Almost took the wrong lesson from it. So again, thank you!
Not being harsh
Just giving advice
Where do I place the GetButton
instead of GetAxis
what do i do
if (Input.GetButton("Roll"))
everything goes red after that
Input.GetButton
just like this, ya?
oh, that Dragon Age ripoff? 🙄
and now i flee
Yah
Okay it works after that line but still isnt propelling my character forward
debug log shows everything works but still it doesnt
Well i mean you have like 8 different places in your script that are directly setting the velocity of the Rigidbody
Time to add more logs and see which of them is running and when
Seems like this would certainly do it:
if (wallJumpCooldown > 0.2f)
{
body.velocity = new Vector2(horizontalInput * speed, body.velocity.y);```
I don't see how rolling could work when that code is running
I mean wall jump cooldown will be <0.2 no? so it wouldnt be running
cause you dont wall jump before rolling
or am i missing something here
oh shoot you were right it works without the code but when I delete it I can't movexd
there are any way to make charactercontroller.SimpleMove to jump or i have to switch to .Move 🥺
what should I do to be able to move again im eepy slepy
I don't believe so, since SimpleMove ignores the Y component
To switch from SimpleMove to Move, you need to make two changes:
- Add a negative number to
characterController.velocity.yto calculate the new vertical velocity - Instead of passing a velocity, pass a change in position. You can do this by multiplying your final velocity by deltaTime
float verticalVelocity = characterController.velocity.y + Physics.gravity.y * Time.deltaTime
This would do the trick.
what should I do with this line:
body.velocity = new Vector2(horizontalInput * speed, body.velocity.y);
it interferes with the rolling
what can I switch it out to
// Normal movement
if (wallJumpCooldown > 0.2f)
{
body.velocity new Vector2(horizontalInput * speed, body.velocity.y);
if (Input.GetKeyDown(KeyCode.Space))
Jump();
}
else
{
wallJumpCooldown += Time.deltaTime;
}
this is the full
perhaps you can stop setting the velocity during a roll
hey yall so I'm working on moving a clicker game I made in Javascript to unity, and for once trying to organize the code. I'm new to unity though and I'm not sure how the best way to handle upgrades would be. I want to have a scrollable list of buttons to buy upgrades with a simple function like buyUpgr(tier), but how would I go about making the upgrades in a succinct way, I don't need separate objects for the upgrades I don't think, I just need a way to store the price, name, tier, and amount. this should be simple but I have no idea and have been stumped lol
thanks you save my life
in Javascript I literally just had an endless list of integers for prices and how much the player had and it worked but it was so clunky for no reason
Are you going to manually define all of those values?
Rather than using a formula to calculate them
well once you buy the upgrade, it's gonna be formulaic for the next price as part of the function
but all the starting values would be manual, unless there's an easier way
Will all upgrades use the same sort of formula?
e.g. they all double in cost for each tier
no so I could probably also store the multipliers they use
but it would be a simple multiplier
like some being 1.7, some being 1.5
As long as you aren't using totally different formulas for different upgrades, then it'll be pretty simple
So, I'd suggest creating a class like this:
[System.Serializable]
public class Upgrade {
public string name;
public float baseCost;
public float costGrowthMultiplier;
public int level;
public float CurrentCost => Mathf.Pow(costGrowthMultiplier, level) * baseCost;
}
you can now create a List<Upgrade>
CurrentCost is a property, so it gets calculated each time you use it
oooh alright, and then just how would I go about getting and setting data from that, just make a new() and do that[tier].price?
You wouldn't create any new Upgrade instances at runtime
you'd just set this up in the inspector
How are you going to actually use this upgrade data, though?
Right now, this is just a list of "upgrade" objects, each of which has a:
- name
- level
- cost to upgrade
whenever i click one of the assorted buttons in the upgrade shop, i would want to run a function like buyUpgr(tier of upgrade)
Who else is going to use this upgrade data?
I imagine it's not solely used by the upgrade button
cuz like in Javascript how I had it as buyUpgr(0-whatever for index) I figured it would be the same
other parts of your game care about the upgrades too
the upgrade buttons, the prices and amounts are showed on the upgrade buttons
right, but you use these upgrades somewhere else, right?
but other than that I'm not sure off the top of my head, more just trying to plan for the future
the upgrades themselves are gonna be handled through varying timed functions in the game manager
An issue with this design is that you can't easily reference the upgrades in the inspector. They're just plain old objects.
You can't drag them into fields in the inspector
But you could adapt it a little.
For example, you could create a Dictionary<string, Upgrade> that's stored in the game manager
When the game starts, you do this:
does someone know why the math doesnt activate?
Dictionary<string, Upgrade> upgradeMap = new();
[SerializeField] List<Upgrade> upgradeDefinitions;
void Awake() {
foreach (var upgrade in upgradeDefinitions) {
upgradeMap[upgrade.name] = upgrade;
}
}
public Upgrade GetUpgrade(string name) {
return upgradeMap[name];
}
This would be in your "Game manager" class
An upgrade button could store the name of the upgrade it's for
It can then ask the game manager for the Upgrade
alright I think I've got it now
The only problem here is that you could use the wrong name
e.g. you could have a typo
Well, when you subtract 0 from 10, what are you expecting to get?
i just saw that damage was not set to any number ðŸ˜
ty man you saved me like probably an hour searching
i need help with my player movement, it doesn't recognise the keys, and i'd like to know why is that happening and how am i suppost to fix the error (i've set comments in the lines with an error to help identify)
!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.
it exceeds the limit
Huh? You mean your code has too many lines? How? What's the count?
Only very few people can see your code (it doesn't appear on mobile) . . .
the PlayerMovement + CameraController are in the same script with current 700 lines
auch
i've only sent the base movement block
i will break it down for you
before i send the code, these are the 3 errors i kept getting
you gotta use the link.
what?
did you read what they sent you .
#💻┃code-beginner message
sending only a snippet when showing null references we can't see lines accurate anyway.
well you would ideally send the whole class as is..
whatever is on line 145,294, 390 is null
i didn't get it
let me get this straight
are you asking for the complete code?
the 700 lines?
thats what the websites are for
so you can send whatever size they are
your error seems to be NRE anyway
(Null Reference Exception)
https://unity.huh.how/runtime-exceptions/nullreferenceexception
check the Troubleshooting
Not sure why you have both classes in the same script each class should have their own (script) . . .
ok you don't have to add the `` cs`thats all only for chat
and yes why is an editor script in another script..
i've never used it so i didn't knew it would recognise the language
anyway looks like you got multiple things that are null so fix it
indeed
doesn't look like crosshairObject was found on whatever object has that script FirstPersonController
and sprintBar, sprintBarCG
this code also handling UI 
wdym by that?
its messy and bad practice to mix UI code with something that should be controlling your character controls
but its code beginner so you are forgiven 🙂
not every fuction, that would be insanity
hahah
ideally for every " purpose "
the SOLID principles calls them "**Single **Responsibility " 🤓
"Im just responsible for this "
anyway you understand the original issue though you had ?
you haven't sent that one out, have you?
insanity
yes, and i am going to solve it
yes insanity principles are my main goto 🙂
i will be back with more news
ok good lol
at least you don't say "Teams only supports files up to 250Gb" 🤓
@summer stump
Don't do that.
But because it is wrong
There is a reason it is the single most quoted and followed principle in software engineering
as a joke?
Do you mean the singleton referencing other things, or other things referencing the singleton?
Start is generally used for external references, awake for self-reference
The issue that can pop up is when using it in DDOL, when awake and start will not be called when a new scene is loaded
assign singleton instance in awake while everything else should at least wait Start to use instance of it , yes
@random dirge when you have a singleton with serialized fields, they are typically used to hold references to other objects in the scene
As said twice, use start
Awake only for self-reference
!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.
Like getting a component reference to the same object as the singleton, or initializing values. Never for getting a reference to a different object or values in a different script
Even that is not foolproof though, but it is a start
Awake is used for (inside) self-initialization. Start is used for outside initialization . . .
Where is that from?
not accounting for a singleton
Because Start is called only once when the script is first enabled (which is when a GameObject first becomes active) . . .
Weird. Well, getting a reference to a SCRIPT could be fine in awake. Not to a value IN the script though
those commends also do not contradict what was told to you
They mean references between scripts (on the same GameObject). They just weren't specific . . .
You reference scripts from other (outside) GameObjects in Start . . .
What's the point of awake if you can reference scripts in the same gameobject on start
Then things may not be initialized when you try to reference them from the start of another script
not just for null too, imagine this scenario
//script1
void Awake()
{
number = INeedSomeValue();//9
}
//script2
void Awake()
{
Debug.Log(script1.number);//logs 0 or whatever initialized field was
}
void Start()
{
Debug.Log(script1.number);//logs 9
}```
It gives you two different times. The first start (of objects existing when the scene is loaded) is guarenteed to be after all awakes
ahh got it
Instantiating obviously doesn't work that way though
I have this part in my update function inside my player, and though I press the keybind it seems to do nothing (fullscreen is a public bool). Is this just me not knowing at all how to use Screen stuff?
if (Input.GetKeyDown(fullscreenKey)) {
fullscreen = !fullscreen;
Screen.fullScreen = fullscreen;
}
are you testing in a build? because the editor will not play game mode in actual fullscreen
yes, testing. Is there a way to see this in action while testing?
I mean not test build, testing the game as in during development of it
is there a game file I should launch via file explorer?
put a log there to print when it does its thing and what it changes to
otherwise build it
whenever I press the keybind it switches on or off (not while holding)
which is the desired behavior
it's working now, thanks for the help
my friend, paste the code here:
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
@slender nymph sry to bother again but i basically replaced Vector2.up with transform.up like you told me and it doesnt really seem to work
i mean like it wont even add the force to begin with so i cant really tell which direction its facing
have you made any other changes to the code? also you can select the object in the hierarchy and set the tool handle to Local instead of Global to see the direction its axes are facing
the upper left buttons in your scene view window are the tool handle buttons. your rotation one (the second one) needs to be set to Local
how can i set it to local 😅
i just told you how
there you go. so as long as the component with the code you showed is actually attached to that object it will add force in the correct direction
nice but it still wont apply the force for some reason
was it adding the force previously
yea
then what else did you change
i didnt change anything
i can double check that it applied the foce previously
gimme a sec
you had to have changed something if it was working before and it isn't now
my bad ive accidentally changed the type of force to vector instead of float
it probably works now ill give it a quick check
ayy works like a charm
thx again 🙂
its a bit weaker now that its angeled though
even turning up the force still mostly pushes the character up rather than to the right
that's likely due to how you move the player
is it possible for me to screenshare to you?
no. you can share your code and send a screen recording or screenshots here though
good enough, give me a second
I'm currently trying to improve a maze generator I made by giving it the ability to generate multiple floors on the same maze
my idea is is to mark the exit/goal node of the previous level as the starting node for the current level, by removing the floor
Am I able to use a 2D array to store all the nodes in the mazes, 1 storing the number of that node, relative to its level
this may sound like absolute waffle but i feel like it'll be easier in my head if i say it
stupidest question ever, yes i can
int rowIndex = //pick a row
int numberOfColumns = levels
for (int col = 0; col < numberOfColumns; col++)
{
currentFloorNodes.Add(nodes[rowIndex, col]);
}```
I could use a for loop
ah
yeah
cheers my friend
I've seen you talk here quite a lot, you are a life saver for a lot of people my brother 💙
Or use a jagged array and pass the intire row into the list
when I get a chance lol
true, directly access the whole row is good
can any one help me on this
Did you check, if you have the package for TextMeshPro?
Try creating one first (I mean, try adding in your scene a TextMeshPro text in the editor)
It should prompt you to import the package
Context?
where i can share u my code
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Here
ohk
Ok so
The error is trying to tell you that in line: 3 you have a
using System.Diagnostics.Contracts;
Which doesn’t exist
You need to remove that line
line 3 is using System.Diagnostics.Contracts;. does this exist? if not, remove it . . .
Not a code problem. #🥽┃virtual-reality
no one is responding there
Then wait
naah, it was not mine
I just show the error
lol, the error is actually in the line you cropped out
maybe dumb question but why do some people use namespace in their scripts
really you should always use namespaces. It allows for the allocation of scripts into logical secctions
so its easier to find?
I been trying to access and modify a mesh on a gameobject through a scriptable object. But I'm a bit confused, do I pass a mesh to a meshfilter to change the form of the object?
I've declared a mesh variable on my scriptable object and picked the capsule mesh. Then I declared a mesh on my object I want to change the mesh of. But on that I get a type mismatch. I can't select the gameobject in the inspector.
you mean to change the mesh? yes, the meshfilter contains the Mesh to be rendered. so you can meshFilter.mesh
on your scriptableobject you cant really reference a meshfilter because the meshfilter is a reference in the scene, switching scenes will break it
So I can not modify my gameobjects mesh with a scriptable object?
youll need to test it tbh
try referencing the meshfilter first and see if anything bad happens
im not sure if the SO will allow you to reference a scene variable
I can reference a meshfilter to my scriptable object but it results in a type mismatch in the inspector
So I cant really do anything with it
how do i change color of the text by script?
price.color = new Color(15, 30, 247, 255);```
this doesnt work for me
Color values are between 0 and 1. If you want 0-255 use Color32 instead
aaa okay
ty
works
i am making a inventory system is it reliable to use a system where it has a databse based on names
Based on names for what? Looking them up in the database?
There can technically be duplicate names
It's better to give a unique id to each item instead
Also, should you want to implement language localization using any string descriptor would break your database
is it possible to change your project to urp ?
So I have a base class for AI general stuff that sort of looks like this
public class Hostile : MonoBehaviour, IDamageable, ITriggerCheckable
{
[field: SerializeField]
public float maxHealth { get; set; }
[field: SerializeField]
public float currentHealth { get; set; }
[field: SerializeField]
public bool IsAggroed { get; set; }
public bool IsWithinAttackRange { get; set; }
[HideInInspector]
public Navigation navigation;
[HideInInspector]
public LineOfSight lineOfSight;
public GameObject target { get; set; }
#region State Machine Variables
public EnemyStateMachine stateMachine { get; set; }
public EnemyIdleState idleState { get; set; }
public EnemyChaseState chaseState { get; set; }
public EnemyAttackState attackState { get; set; }
#endregion
void Awake()
{
stateMachine = new EnemyStateMachine();
idleState = new EnemyIdleState(this, stateMachine);
chaseState = new EnemyChaseState(this, stateMachine);
attackState = new EnemyAttackState(this, stateMachine);
navigation = GetComponent<Navigation>();
lineOfSight = GetComponent<LineOfSight>();
stateMachine.Initialize(idleState);
}
I want different types of course, so 've made a class called Zombie that inherits from Hostile. I want Zombie to set the sightRange of the lineOfSight component to 15.
But it keeps telling me it has a null reference for the object.
I assume it's because the child is trying to call before the parent sets up properly. Anyone know how to generally fix this?
Where does your assumption come from?
When does the subclass of the Hostile class tries to use the lineOfSight component?
your awake needs to be a virtual method
If it's in awake then just as Carwash said ^
virtual, override, call base and then do your stuff
protected void virtual Awake() { }
and then in your Zombie class, override it
protected void override Awake()
{
base.Awake();
// other code
}```
Oh okay, thanks a ton guys!
In regards to this, my zombie class is just adjusting lineOfSight.distance within it's own awake
Yeah, then do as Carwash said
So just something as simple as this?
public class Zombie : Hostile
{
private float sightRange = 15;
protected override void Awake()
{
if (lineOfSight != null)
{
lineOfSight.distance = sightRange;
}
}
}```
Gonna remove the if check now
you missed the base.Awake()
You forgot the base call
Oh right yeah
My bad
protected override void Awake()
{
base.Awake();
lineOfSight.distance = sightRange;
}
Like this?
Try it out
No luck
"Zombie.cs(10,29): error CS0115: 'Zombie.Awake()': no suitable method found to override"
distance within lineOfSight is just a getter/setter if that matters
then you 'forgot' some thing else
protected void virtual Awake() { }
Show your Hostile class, the Awake method needs to be marked as virtual
protected virtual void Awake()
{
stateMachine = new EnemyStateMachine();
idleState = new EnemyIdleState(this, stateMachine);
chaseState = new EnemyChaseState(this, stateMachine);
attackState = new EnemyAttackState(this, stateMachine);
navigation = GetComponent<Navigation>();
lineOfSight = GetComponent<LineOfSight>();
stateMachine.Initialize(idleState);
}
Huh, just hit play again, it works now.
No worries then
Guess it didn't update the file properly
Thanks again guys
Hmm, actually, there's something I'm still missing somewhere I think
Doesn't seem as though that distance is changing on play.
The vision cone remains the same even though I am overring 🤔
{
private VoxelData voxelData;
private void Start()
{
voxelData = NewChunkManager.Instance.GetVoxelData();
if (voxelData == null)
{
Debug.LogError("voxelData is null");
}
else
{
Debug.Log("voxelData is not null");
}
}
public void GenerateVoxelMesh()
{
VoxelCell cell = voxelData.GetCell(x + chunkCoord.x * chunkWidth, y, z + chunkCoord.y * chunkDepth);``` my voxelData.GetCell is giving me a null reference. im getting the voxelData from my manager instance, can i not use .GetCell on it from this script or is there something else going wrong?
i got the debug.log that it is not null
When do you call GenerateVoxelMesh()
on the start of my chunkmanager script private void Start() { RandomOffset(); voxelData = GeneratePerlinNoiseVoxelData(); GenerateChunks(); initialized = true; }
its in the generate chunks method
Then show the GenerateChunk() method instead.
{
ClearChunks();
int chunksX = gridSize.x / chunkWidth;
int chunksZ = gridSize.z / chunkDepth;
chunks = new NewChunk[chunksX, chunksZ];
for (int x = 0; x < chunksX; x++)
{
for (int z = 0; z < chunksZ; z++)
{
Vector2Int coord = new Vector2Int(x, z);
GameObject newChunkObj = new GameObject("Chunk_" + x + "_" + z);
newChunkObj.transform.parent = this.transform;
NewChunk newChunk = newChunkObj.AddComponent<NewChunk>();
newChunk.Initialize(coord);
newChunk.GenerateVoxelMesh();
newChunk.UpdateMesh();
chunks[x, z] = newChunk;
}
}
}```
that fixed it, ty
But it wouldn't be a bad idea to just pass the voxel data in the GenerateVoxelMesh() method
Instead of getting it through a static instance in Start/Awake
Anyone know how to get rid of this error?
NullReferenceException: Object reference not set to an instance of an object
UnityEditor.Graphs.Edge.WakeUp () (at <f94752164e14499c83c250d9839d9e96>:0)
I thought restarting Unity would do it, but it just never leaves
Some graph window is bugging out a bit, could be Shader Graph, VFX Graph or Animator window for example
Can try to reset your layout and see if it helps
Hmm, gave it a try but unfortunately still there
No way to set an ignore for that particular error I imagine?
Did you clear the console though?
I did yeah
What is your unity version?
Okay guys i have a big problem, my unity wont launch
Yesterday it worked
I have no idea for what it doesn't work today
I must work rn but I can't omg
well we dont know why your unity isnt launching either
got a screenshot?
@gilded kiln
usual tech questions: have you tried restarting your pc, reinstalling unity, did you do any funky stuff with your project files?
Actually i dont want to reinstalling Unity, i already try to restarting obviously it doesn't worked but now I'm try to earased all files in the folder Temp
No I do nothing wrong with Unity
do you have a screenshot of what happens when you try to boot up unity
Nothing happens that the problem
unity hub or unity editor?
And I think I can't take a screenshot of nothing lmao
Unity Hub
uninstalling hub shouldnt remove editor
I know how to start Unity I do it a lot of time
plus you might be able to start editor without hub
Normally I need to start Hub before the editor
C:\Program Files\Unity\Hub\Editor\2022.3.19f1\Editor
this brings me here, theres a unity.exe you can use
change the version accordingly
dumb plan but yeah
secondary plan is to find out directly whats wrong with unity hub by launching unity hub from a command line
but theres a point where you just reinstall unity hub
on a differrent note is unity hub installed on a different drive?
I'm trying
No it's not working
Nothing work
OMG i think i will reinstall
LMAO
The first worked but the second not
my class has implicit string conversion, why cant i string.join it?
i dont seem be able write conversion for class array only for class
I have written a code for facing the player in the direction it moves, but it behaves very weirdly and causing the player to move in unwanted directions. Please help!
{
PlayerControls();
}
void PlayerControls()
{
float xInput = Input.GetAxis("Vertical") * moveSpeed * Time.deltaTime;
float yInput = Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime;
playerTransform.Translate(xInput, 0, -yInput);
//for rotation
Vector3 direction = new Vector3(xInput, 0, -yInput);
playerTransform.forward = Vector3.Slerp(playerTransform.forward, direction, Time.deltaTime);
}```
Hello, I was wondering, where should I declare interafaces. For example if I have an IDamageable interface I would use it in my Enemies script, my Players script and any items that could be damagable. Do I declare it in one of the objects scripts? Should I have one big script for just declaring different interfaces?
make a different script an interface which has all the damagable logic, and then attach that interface to all items
Just make a script, name it your interface, and define it in the script . . .
All of your types should be in their own script . . .
is the code logically correct or its not?
So each new interface I make should have a different script?
yes for every different interface
x axis is horizontal from what I know
Yes, an interface is a type. Just like a class, struct, ScriptableObject, interface, etc. . . .
yes but i set it because my camera is set up like that
if u can imagine that
Can this help you?
https://docs.unity3d.com/ScriptReference/Transform.LookAt.html
it just made the player start rotating around an axis
not face the direction it moves
Your direction Vector is just the players transform.position + input, a direction needs to be calculated as some target.position - transform.position
why cant i write operator for class array error says i must convert from exact type and its array fails to count as one
Unity has a page for that
https://docs.unity3d.com/2018.3/Documentation/Manual/DirectionDistanceFromOneObjectToAnother.html
{
ClearChunks();
chunks = new NewChunk[numberOfChunksX, numberOfChunksZ];
for (int x = 0; x < numberOfChunksX; x++)
{
for (int z = 0; z < numberOfChunksZ; z++)
{
Vector2Int coord = new Vector2Int(x, z);
GameObject newChunkObj = Instantiate(chunkPrefab);
newChunkObj.name = "Chunk_" + x + "_" + z;
newChunkObj.transform.parent = this.transform; //< This line gives the error
NewChunk newChunk = newChunkObj.GetComponent<NewChunk>();
if (newChunk == null)
{
newChunk = newChunkObj.AddComponent<NewChunk>();
}
Vector3 chunkPosition = new Vector3(coord.x * chunkWidth * scale, 0f, coord.y * chunkDepth * scale);
newChunkObj.transform.position = chunkPosition;
newChunk.Initialize(coord);
newChunk.GenerateVoxelMesh();
newChunk.UpdateMesh();
chunks[x, z] = newChunk;
}
}
}``` im getting these warnings but no errors
what shall be the target position here?
I cant really imagine what your game looks like given that your horizontal and vertical axis are switched but you could try subtracting your players position from the input Vector3 you have already made
whats different between this code and mine
like in this it didnt subtract the target and transform position
because this code works but mine doesnt
Oh yes, you could do it this way, but you cant use your xInput and yInput variables, they are multiplied by your speed and Time.deltaTime
You know if you're going to continue to refuse to provide enough context for anyone to have any goddamn clue what you're asking about you can probably just cut the middleman and not ask
ohh, got it
but what if I normalize it?
like direction.normalize
{
public static implicit operator string(test[] thing)
{
return "";
}
}```
cant use array
So you're trying to cast an array of test to a string? That's not going to work. You can't implicit something that isn't this type
test is not test[]
well idk whats difference can use explicit as well
i just want convert it to string without additional functions
because messy
What's the problem with public string SomeFunction()
Get over it
This is unfathomably more messy
than just having a function that returns a string
having 20 functions for conversions is not cool and when i found out about implicit its amazing
just it dont work for arrays for some reason
even chatgpt says it supposed to work
I do not think it would work, normalizing changes the length of a vector, not it's direction
oh, well if gpt say so it must be wrong
I mean, a hammer is an amazing tool until you discover that screws exist
ohh
Because test is not test[]
and i cant define class of test[] either
because it literally does not know anything whatsoever
correct
i cant literally do anything with arrays
{
float zInput = Input.GetAxis("Vertical") * moveSpeed * Time.deltaTime;
float xInput = Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime;
playerTransform.Translate(xInput, 0, zInput);
//for rotation
Vector3 direction = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
playerTransform.forward = Vector3.Slerp(playerTransform.forward, direction.normalized, Time.deltaTime * 10f);
}
I did this, now the player looks in the direction I move, but now my movement is messed up, like it wont move in the same direction when I added the rotation logic
brother there will be a day when u will start having trust issues with AI, soon
well it wrote entire server for webpage for me so
Well yes, you changed -yInput to zInput
I fixed my camera so thats why
No, it stole a server webpage from a stack overflow question you could easily have googled yourself
try to build a full fledged working game with it and u will know its suffering
Vector3 direction = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
I did input the actual values without multiplying speed but still the same problem
It wont move in the same direction as in it is going the complete opposite way correct?
Beacuse I think in your zInput you forgot the negative sign
not opposite, i think its mixing the rotation with movement
its like combining the rotation with movement
so If I press W for instance, it starts revolving or some shit
https://docs.unity3d.com/ScriptReference/Transform.Translate.html you should read the description of Transform.Translate here
Reference
okay
The transforms are applied in local space, this means that they are affected by your players rotation
Which means that as your player rotates it tries to go forwards, where the player rotated
you need to set the relativeTo parameter (which is optional) to world
It is written in the documentation I showed you above
wouldnt that make my approach much more complex?
than it shall be
i will read it
So, basically, here's the not stupid way to do this:
public class test
{
public static string ArrayToString(test[] thing){
return string.Join(",", thing);
}
}
Stop trying to use your fancy new hammer on every fixture in the house. Sometimes, you're gonna need a screwdriver
bruh i tried to use string.join in the first place and its not able convert it to string
that why i wanted implicit cast
If you dont want to mess around with local and world space, transform.position is always in world space, meaning you can also replace playerTransform.Translate(xInput, 0, zInput) with playerTransform.postion += new Vector3(xInput, 0, zInput)
I figured since you were so gung-ho about implicits you already had an implicit for test to string
If not, then you can use Linq to map ToString over it
What is the exact error
ohh
Also when developing a 3D game understading world and local space is very important
ambiguous call
okay got it
thanks!
i can type its class but then it just prints class name without actual data
That is not the "exact" error
ig i will have to read up some documentation
The call is ambiguous between the following methods or properties: 'string.Join(string, params object[])' and 'string.Join<T>(string, IEnumerable<T>)'
Ok, perfect. So it IS able to, you just made a mistake. Show exactly what you wrote
This fully compiles and does exactly what you expect it to
It's unsure if you want to pass in the list as a list or as params, so it's ambiguous
you don't need implicits at all
You just need to tell it "No this is supposed to be a completed list, not params"
See how easy it is to fix when you actually give us the fucking information as to what you are doing
noone mentioned object array conversion till now
because you haven't actually told anyone what your error was for three months
Turns out this whole time it was a stupidly simple solution and you just kept stepping on rakes because you assumed we "didn't need to know what you were trying to do" to help
well fuckin look at that, turns out once we did get it it was an easy problem
i havent touched arrays till now implicit cast for type is still useful
just arrays were issuing
sure, implicits are useful. However, you never needed them to solve this problem and going down that rabbit hole just kept moving you further and further from actually solving the problem
though i see object[] cast still doesnt solve issue
Okay, what doesn't it do that you expect it to do
Does your test class have a ToString?
no
The default ToString of every object is just their name
why doesnt it use implicit
so if you want it to do something different, you have to have told it to do that
because that's not what implicits are for
Every object has ToString. That is, in fact, one of the only things that can be said of the type object. That's just about the only shared function on it
So you've been spiraling into madness when the solution was ToString and casting to object. Something that basically anyone on this server could have answered in five minutes if you had actually said what you were trying to do from the beginning
hey guys, pretty embarrassing but for some reason visual studio doesn't seem to reference exceptions? I'm not quite sure whats going on. I put "NullReferenceException" in the catch statement and it doesn't even seem to recognise the syntax for it. Does anyone know what I'm doing wrong here?
What is the error?
missing a using System ?
this, I'm pretty confused
That is not an exception being thrown.
thats embarassing
for Exception? NO
At least, it doesn't have to be one.
You can write an error to the console with Debug.LogError.
😬 yikes my fault
yea idk the correct way to phrase it my fault
thanks guys that was confusing me for a while ðŸ˜
Figure out where the NaN is coming from when calculating the force.
is there a reason you're editing this on your phone...?
I don't have discord on my laptop
see the weird thing is I did a check to see if the wheel.thrust or wheel.thrustpower == float.NaN and it isn't
which has me super confused
Under axis.Normalize(), I added axis*=Math.Deg2Rad;
perhaps the wheel has already gone to space, so that transform.forward is full of NaNs
axis?
you convert the angle, not the axis..
I wasn't thinking about how it interacted with the code, just the results.
That's why I was confused.
all of these checks yet alas, the issue persists :/
Just log all of the values.
Importantly, I don't think float.NaN compares equal to anything
You'd have to use float.isNaN()
Are you multiplying by excessively high numbers?
ahh I see
it was the wheel.thrust value
I'm not quite sure what is making it NaN I think the engine simulation thingy needs a frame at the start
it accounts for the velocity of the previous frame etc etc
I see now
thank you very much
I have a problem that when I pause the game to change the volume by using the slider in unity, when I turn down the volume, and after I unpause to resume the game, the volume changes bak to full when I move the player to the right, and the volume turns down when I move the player to the left, by using the "a" button for moving left and the "d" button for moving right, that only happens when I pause the game to change the volume, how do I fix that so the volume doesn't change when I move the player?
this is the volume setting
https://gdl.space/ahujifaced.cs
and the pause script
your slider is still selected by the EventSystem because you aren't setting the canvas's GameObject inactive, you just disable the canvas component. so either set the currently selected gameobject to null in the EventSystem or completely disable the object(s)
Am I blind? Unity is giving me this error:
error CS0122: 'State.lineOfSight' is inaccessible due to its protection level
It's inheriting a protected so it should have access right?
public class State : MonoBehaviour
{
public LineOfSight lineOfSight;
private void Awake()
{
lineOfSight = GetComponent<LineOfSight>();
}
public virtual State Tick(StateManager stateManager)
{
return this;
}
}
public class IdleState : State
{
PursueState pursueState;
[Header("Detection Layer")]
public bool hasTarget;
private void Awake()
{
pursueState = GetComponent<PursueState>();
}
public override State Tick(StateManager stateManager)
{
if (lineOfSight.objects.Count > 0)
{
return pursueState;
}
else
{
return this;
}
}
}```
have you saved the State class
change something in the eventsystem in the first image, or but the null in the second image?
I'm making a 2d football game. When characters hit the ball it never goes up when its on the ground what can I do about that?
neither, my suggestions were both code related so you aren't changing any settings on the EventSystem component. you need to tell the EventSystem component that nothing is selected when you exit your pause menu. and simply assigning null to a field is completely irrelevant to what i've said
Yeah it's been saved
then where do you see protected in your code?
Okay, I restarted Unity twice and now it works all of a sudden
First restart still had the problem
like this?
what am i doing wrong here? im trying to click the text and have it take me to another scene (the game)
add a Debug.Log statement to find out if the function is being called at all
from what ive seen its not acting like a button at all, my curser doesnt change when i hover over it and the colours dont change, neither of which are even in the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bedScript : MonoBehaviour
{
public GameObject inticon, bed, bedText;
void OnTriggerStay(Collider other){
if(other.CompareTag("MainCamera")){
inticon.SetActive(true);
if(Input.GetKey(KeyCode.E)){
bedText.SetActive(true);
bed.SetActive(true);
inticon.SetActive(false);
}
}
}
void OnTriggerExit(Collider other){
if(other.CompareTag("MainCamera")){
bedText.SetActive(false);
inticon.SetActive(false);
}
}
}``` how can i get my dialogue to look like this?
do you have an Event System in your scene?
- Do you have an event system in the scene?
- Are you hovering over the text itself, since that's the target graphic? Hovering over a blank space like the emplty space inside of an
awould not count. - Does your text component have "Raycast Target" enabled
use a coroutine to change the maxVisibleCharacters property over time on the TMP_Text object
whats a coroutine and how do i do that
i am hovering over the text as for the other two you will have to give me some time as i have no idea what they are or where to find them
First one is simple, is there an object named Event System in the scene and does it have the EventSystem component on it?
Third one, it's a checkbox on all UI renderer components like your TMP Text
there is not, i put everything onto the button itself
Not on the button.
Somewhere in the scene.
You can search the hierarchy for t:eventsystem
screenshot your hiearchy
yep, no event system, add one
you can find a template in the GameObject > UI menu
GameObject -> UI -> Event System
It gets created automatically when you add your first canvas, it's important, don't delete it
seems to be working
Trying to work with a simple state machine, currently getting a consistent error message of NullReferenceException: Object reference not set to an instance of an object
IdleState.Tick (StateManager stateManager) (at Assets/Scripts/Enemy/IdleState.cs:15) which is this
if (lineOfSight.objects.Count > 0)
Anyone have any ideas? Not sure what I'm missing
using UnityEngine;
public class State : MonoBehaviour
{
protected LineOfSight lineOfSight;
private void Awake()
{
lineOfSight = GetComponent<LineOfSight>();
}
public virtual State Tick(StateManager stateManager)
{
return this;
}
}
using UnityEngine;
public class IdleState : State
{
PursueState pursueState;
[Header("Detection Layer")]
public bool hasTarget;
private void Awake()
{
pursueState = GetComponent<PursueState>();
}
public override State Tick(StateManager stateManager)
{
if (lineOfSight.objects.Count > 0)
{
hasTarget = true;
return pursueState;
}
else
{
return this;
}
}
}
i'm guessing line 15 of IdleState.cs is that if (lineOfSight.objects.Count > 0) since you don't assign to lineOfSight with that class?
in Idlestate you need to call base.Awake().
Did we not do this earlier?
Yeah we did, that's where I said a bit earlier I ran into an issue and lost some progress.
Was trying to remember all the things I had done
you could have just searched this discord
I lost a bit more than just that one bit, so it slipped my mind
amazing, it didn't slip mine and it's not my code
the new operator is used to invoke an object's constructor. which creates an instance of that object
it makes a NEW copy of something
I want a Car, I get a new Car. I have a new Car
Vector3 is an object (a struct specifically)
You are creating one (as the others said) with the values you want.
how can i use a script inside of another script
Depends on what you mean by "use" and "inside"
Are you talking about referencing?
yeah
get a reference to it
do i use a game object?
all of your components will be attached to gameobjects
nvm
!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.
hello guys
i have a problem
everytime i write a code in visual studio it appears in unity like nothing happened
it appears in unity like nothing happened
what do you mean by this
i make a new script
i write my code
i finish
i go to unity
i dont see my work
please fucking finish a thought before pressing enter
and again, this is not clear what you mean. provide some actual details about what you are talking about. do you mean that the code just doesn't work? or do you mean that you didn't bother saving the code so unity does not see the changes to the file and has not attempted to compile it
i mean when i finish a code on visual studio and click save then go back to unity i see the code but i cant drag stuff to the code
idk how to say it tbh
you can't "drag stuff to the code"
Do you have compiler errors?
no
so i really do not understand what's going on here
screenshot the entire editor window with the Console open.
Your console window is not open.
You are currently selecting a script asset. You can't do anything with this. You need to actually add the component defined by the script asset to an object if you want to assign things in the inspector.
That's my best guess of your problem right now, assuming you don't have a compile error.
those serialized fields would actually show up there if they didn't have compilation error(s)
true
how do check if i have errors?
Console
look at your console. and also make sure that your !IDE is 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
I've told you several times to show the Console window.
Click on the tab.
compile error should show as a Red error.. or sometimes a Popup window directly telling u
yes we saw that from the code you shared
lol
dont be sorry for learning something new 😉
thx man
If you don't know what something means, ask for a clarification.
no ones judging you for getting familiar and learning the editor
alr
ok thank you guys ill learn how to remove the error from google or yt
you can fix the error by getting your IDE configured then re-typing that line since you'll have auto complete preventing you from making silly spelling mistakes
alternatively, you could reveal what the error is
CS0246: The type or namespace collider could not be found (are you missing a using directive or an assembly reference?)
Accessing the TYPE Transform on line 12, and perhaps trying to get a reference to transform from player (which is already a transform) are two that I see
ah yeah that one too
yh thats the one
C# is case sensitive
Things being capitalized or not make them quite different
gonna be honest, i completely missed the second one
your IDE should be highlighting all of these errors for you
I completely missed the one you said haha
in ur face kinda squigglies.. make the world a better place
and all is right in the world lol
How can I do a 'While' loop in Unity?
People don't seem to like using 'while' with unity
what?
while (condition) { }
you use it exactly like you would anywhere else
I have fewer of them than foreach loops, sure
I use them when I need to do something until a condition is no longer true.
So when would you use a CoRoutine and not a while loop?
those are two unrelated concepts
I'm trying to slowly change the size of a box collider over a period of time. Would a while loop or CoRoutine be better?
You'd use a coroutine when you want a coroutine.
You'd use a while loop when you want a while loop
again, two unrelated concepts
generally you would use a while inside a coroutine. With a yield in the whille
a coroutine lets you run code that spans several frames
A while loop does not have any concept of "over time"
All loops always run to completion.
Couldn't a while loop do that too?
vitally, no code ever has the concept of running "over time"
it runs until the condition is false
including code inside a coroutine
it's not like there are a thousand little virtual machines all running a single script's code, running in parallel
while (true) {
// ...
}
if you hit this code, your game freezes
(assuming that nothing happens to make you exit that loop)
A while loop will run as fast as possible if you don't do it in a coroutine or some other asynchronous method
Coroutines and while loops are not different ends of the same spectrum. They are completely different, and should not be compared the way you are
to clarify: it takes zero in-game time for the code to run. Time does not pass at all in the game as your code is running.
it's not that the while loop runs really really quickly
it's that nothing else happens while your code is running
Unity makes a gigantic to-do list of every single thing it needs to run per frame, then runs through it in order
!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.
What am I doing wrong here? The code seems to go on forever until the collider is flat
Well, the conditions is all based off of size.y and offset.y which you are setting directly to -0.1
so I'm not sure what you're expecting to happen
I'm trying to reduce the height of the collider
if that condition is true, it sets them to -0.1
then waits 2 seconds and checks again
Subtract 1 from their current value
yo, fellas. i'm working on a top-down tank game, and i'm having a good amount of trouble coding the cannon to stop rotating past a certain point. how would you guys go about it?
How would I do that?
What do you actually want to do with those values?
You're doing the math but not doing anything with it
minus them by 1 each frame
This is subtracting 1 from them. What do you want to do with that new value
Make that the new value of the collider size and offset
So do that. Set the collider size and offset to the new value
It's not like this, is it?
You need to use an = somewhere in that line
You still aren't doing anything with the result of your math
You're doing subtraction and then not using that for anything
C# forbids you from writing a useless statement like that, which is why it's giving you an error.
This isn't going to modify the variable. Numbers are passed by value, it's going to give you the value that is 0.1 less than size.y
For example, 4; is an invalid statement
This is correct, right?
Hello when I decide to use DOTS - does it mean - that all parts - that needs to communicate with each other - must be also converted (baked) to ECS.
For example:
I have Camera and Character in my main scene - and One Entity that want to read data from that camera and character.
Does it mean - that I need to move and convert camera and character into Subscene (and therefore convert it to ECS) ? Or there is possibility to somehow read data from gameObject from main scene from subscene ISystem?
You should ask about this in #1064581837055348857 -- but I'd say the answer is "no". You can pass information back and forth just fine.
Yes, that would be actually using the result. It'd be used as the Y value of the vector you're setting the Size to
Oh sorry I missed that channel - but thanks!
I don't even know what I hate lol
Apparantly the = operator
It would seem like it
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class fridgeScript : MonoBehaviour
{
public GameObject inticon, fridge, fridgeOpened, fridgeClosed;
void OnTriggerStay(Collider other){
if(other.CompareTag("MainCamera")){
inticon.SetActive(true);
if(Input.GetKey(KeyCode.E)){
fridgeClosed.SetActive(false);
fridgeOpened.SetActive(true);
fridge.SetActive(true);
inticon.SetActive(false);
}
}
}
void OnTriggerExit(Collider other){
if(other.CompareTag("MainCamera")){
inticon.SetActive(false);
}
}
}``` how can i make the fridge close if i press e again
Instead of setting each object to specifically true or false, set it to whatever value it currently isn't
im a little confused
Well, let's take it one at a time. Do you know how to check if fridgeClosed is active
in the code or?
yes
no i dont think then
no
Now you know. Put those all together and you have the recipe to toggle an object instead of setting their SetActive to a specific value
i dont get what any of those sites mean
It's called "documentation" and you're gonna need to get used to reading it
because that's like 60% of what programming is
Look at the first bullet point in that link
which one
The most recent one
what is a bullet point
The dot before an item in a list
oh yeah i forgot lmao
yeah
what about it
That is how you negate a bool
Maybe I misread
i have no clue what "Unary ! (logical negation) operator" means this is my first game
Did you try reading it
That's why I linked it
because it explains things
what do i do now
im in code beginner
Using what you learned to negate the current value of the bool
That is a link to a message
Now you do the thing I said and set each thing to what it currently isn't.
do i just copy what it says
What what says?
bool passed = false;
Console.WriteLine(!passed); // output: True
Console.WriteLine(!true); // output: False```
This is what we call in the business "an example"
you're supposed to read it
and see how it works
and apply it to your own project using a thing we like to call "thinking"
im trying to learn this from scratch
Then read the links more fully and do so. Asking here is not learning from scratch
You currently know:
A) How to set an object's active state to a boolean
B) How to invert a boolean
C) How to get the object's current active state as a boolean
From there, it should be straightforward to:
Set the object's active state to the inverse of its current active state
Google more examples if needed
i dont know if i dont understand it
which step do you not understand
what does "console" mean
Console is completely irrelevant to you
Console.WriteLine is how you output text to the C# console when writing standalone programs
and has absolutely nothing to do with anything right now
I feel like there's a severe lack in general C# programming knowledge and that should be dealt with before even coming near Unity
I mean, it's okay to not know C#, but you need to at least know logic
The example is meant to show you how to use !
That is the important part here
i have zero experience in any of this i just wanna make a simple game
#💻┃code-beginner message
Which part of this process do you not understand how to do
Specifically
A, B, or C
Game dev is one of the more difficult types of software engineering. You cannot just jump in without doing any legwork. Do the courses I linked before coming back
And there's also a lack of that logic, so it would be best to at least learn C# first and "learn the logic" alongside it
Honestly, depending on the course, you not only learn programming but it also changes your mindset on how to approach different problems
I recommend taking gamedev.tv's unity2d C# course on udemy
i dont understand how to use this https://learn.microsoft.com/en-us/dotnet/api/system.datetime.op_greaterthanorequal?view=net-8.0#system-datetime-op-greaterthanorequal(system-datetime-system-datetime)
i want to check with the if function if the System.DateTime.Now.Hour which returns current hour is later than hour 21
is it like a special boolean or something?