#💻┃code-beginner
1 messages · Page 15 of 1
Yea he is using visual studio code so that makes me think maybe he didn't download the cs language
so here i need to somehow check if there is going to be remaining amount after you would add to the inventory, and if so you just subctact the amount and refresh the cell
and is its more then you Remove()
i think
The red circle, you're removing and readding is what I'm not understanding. You should be changing the value on the item in the slot as to where it's at and only removing if the value remaining is 0.
yeah im removing from the slot you clicked on and then adding to the opposite cells
because i pass in cells
to the add method
so if you quick stack on a hotbar slot
you add to the inventory cells
I got a better idea why not keep the value of the cells add it to the one in the inventory then remove the first one
which are these
Yea so from my understanding if you remove it than add it to the inv it will add 0
(i didn't read and analyse the the script tho)
Is that what's going on? You got the value on the cells and not the items?
Yup
its on the Item
the cell holds the Item object
i just hide it in the world when a player picks it up
and show it when he throws it out
Ok i get it
when splitting items in the inventory i instantiate a new one
But what about the amount of that item
set the amount to half
Ye that's what i meant
thats not important tho
but this is how it works
you see when i picked up the item, it got set not active in the hierarchy
and when i split the item a new one gets instantiated
anyway im going to sleep
i spent like the whole day and its still not working
Well, from what I can see is that you're readding it to the inventory after stacking. That is something you should look into and see if you can manage just deducting from the original item's stack amount, and if that amount is reduced to 0, just delete that instance.
yeah thats what i do here for example
thats for stacking items
it destroys the instance when the item you are adding can fit into an existing stack
Alright, but here it looks like you're readding it to the inventory when the stack isn't depleted fully and that's the problem. If you're using some temporary instance to do this operation, then you need to carry over the previous item slot index I guess.
Imma read the whole thing
alright i'll try in the morning
see ya guys
later
and thanks
Now that you're done (assuming you are. Do you see red squiggles?) compare your code
#💻┃code-beginner message
With the example code here
https://docs.unity3d.com/ScriptReference/GameObject.Find.html
Then, let us know what you WANTED to do with that function, because i'm not even sure. The Find method is for finding gameobjects
why is there a bit of delay before my instantiated prefab starts spinning?
[SerializeField]
Rigidbody2D rb2d;
[SerializeField]
Rigidbody2D spriteRb2d;
float LifeTimer = 0;
public float Range;
public float flySpeed;
private void Awake()
{
spriteRb2d.angularVelocity = -1500;
Debug.Log("I should be spinning");
}
private void Update()
{
LifeTimer += Time.deltaTime;
if (LifeTimer < Range)
{
rb2d.velocity = transform.up * flySpeed;
}
}
Debug values in the condition you are setting
what values? the angular velocity or something else?
Ah, you set it in awake. Do you get a delay for your debug message there as well?
nope, no delay
Have you tried with lower angular velocity? Maybe you are breaking speed limits.
The default limit is 7 rps I think? Which would be like 2520
Can you show the code that spawns this object?
here
If you are still struggling with this, test things in isolation. Use a clean scene and test that physics initializes properly there and everything works as expected, then start narrowing down what can cause it in your original one.
I ultimately gave up on this idea. I went with just rotating the transform every frame instead.
I must suck at Google. Been searching
struct I would only want to use for temp bits of data like if a collider is colliding right?
But I dint understand why I wouldn't use a bool in that case
no
Is there an immediate benefit of using a struct vs a class?
Oh sorry. Thanks fir the reply. I'll wait
structs are value type. classes are reference type
that is the main difference to work with
as the name implies, struct is short for “data structure”
Oh so if I won't need to reference outside of the script then I can safely use a struct to do things like control camera behavior on collision
yeah. for example, vectors and collisions are very great examples of structs
Structs are immutable, and passed by value. If you have a variable with a struct type, it holds the data right there, rather than a pointer to the data elsewhere. This means structs are very efficient to create and discard, no allocations or freeing of memory required. It also means that if you have a lot of data in it, it takes up a lot of memory in the heap. There is a point, different on different machines, where the speed gained from skipping the allocations is less than the speed lost dealing with passing things to and from the heap.
Basically, for small amounts of data, structs are faster. For large amounts of data, classes are faster. If you need to have multiple variables affecting the same data, classes must be used.
Mathf is a great example of a struct that makes no sense being a struct
Yeah that one's just baffling why it's not a static class
Another artifact of old unity
just in case he sees things that are structs or not, and is confused
I'm so new to all this, I appreciate you guys explaining it to me
generally speaking: if you expect to need changes during the lifetime of the object, you should use a class. UNLESS the object is so extremely simple ans small, that you can afford to make a whole new one cheaply every time you want to “modify” it
although I'm a bit confused still on the Mathf bit. Mathf I've only seen used in equations so far and don't fully understand what the meaning that it's a struct is
because you can’t modify a struct. you’re basically making a whole new one
it makes no sense being a struct
perfect. sounds like that's the way to go if I want a Zelda style behind the back camera
that is a great example of a struct that has no business being a struct
oh i think i get it. so Mathf you wouldn't put into struct something something mathF
On example I have of a struct is CardinalIntensity, which is a small struct which holds 4 ints. One for up/down/left/right
and I do a fuckload of math with it, and NEED operations on it to be blazing fast
needs to be a struct
COULD be a class, and I could make everything work. But it is a classic example of a time NOT to use a class
can somebody help me? im trying to enable a game object by clicking the key tab, no errors in the output but doesnt work, ```cs
using UnityEngine;
using UnityEngine.InputSystem;
public class LeaderboardEn : MonoBehaviour
{
public GameObject objectToToggle;
private bool isTabPressed = false;
private void Update()
{
if (Keyboard.current.tabKey.wasPressedThisFrame)
{
isTabPressed = true;
if (objectToToggle != null)
{
objectToToggle.SetActive(!objectToToggle.activeSelf);
}
}
if (Keyboard.current.tabKey.wasReleasedThisFrame)
{
isTabPressed = false;
}
if (!isTabPressed && objectToToggle != null)
{
objectToToggle.SetActive(false);
}
}
}```
@buoyant knot @polar acorn thanks again. I'm going to jump back in while this info is fresh
?
I think you have to use this https://docs.unity3d.com/ScriptReference/KeyCode.html
That is for old input. They are using new
Put debugs in to make sure things are getting called properly.
ah k
never mind, i fixed it
Ok nice. I was trying to put in the debugs where rhey should go, but coding on a phone sucks. Glad you caught me early lol
heh
When I move, my player vibrates and idk why ;-;
public class PlayerController : MonoBehaviour
{
private float speed = 10.0f;
private float turnSpeed = 10;
public float xRange = 4;
private bool walking = false;
public float horizontalInput;
void Update()
{
horizontalInput = Input.GetAxisRaw("Horizontal");
if (Input.GetKeyDown(KeyCode.Space)) {
walking = !walking;
}
if (walking)
{
transform.Translate(Vector3.forward * Time.deltaTime * speed);
transform.Translate(Vector3.right * Time.deltaTime * turnSpeed * horizontalInput);
}
if (transform.position.x > xRange)
{
transform.position = new Vector3(xRange, transform.position.y, transform.position.z);
} else if (transform.position.x < -xRange)
{
transform.position = new Vector3(-xRange, transform.position.y, transform.position.z);
}
}
}
And then I have a script for the camera to follow it
public class FollowPlayer : MonoBehaviour
{
public GameObject player;
private Vector3 offset = new Vector3(0, 5, -6);
void Update()
{
transform.position = player.transform.position + offset;
}
}
i modified your script a bit, should work
using UnityEngine;
public class PlayerController : MonoBehaviour
{
private float speed = 10.0f;
private float turnSpeed = 10;
public float xRange = 4;
private bool walking = false;
private Rigidbody rb;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
horizontalInput = Input.GetAxisRaw("Horizontal");
if (Input.GetKeyDown(KeyCode.Space))
{
walking = !walking;
}
}
void FixedUpdate()
{
if (walking)
{
Vector3 movement = Vector3.forward * speed * Time.fixedDeltaTime;
rb.MovePosition(transform.position + movement);
Quaternion turnRotation = Quaternion.Euler(0, horizontalInput * turnSpeed, 0);
rb.MoveRotation(rb.rotation * turnRotation);
}
rb.position = new Vector3(Mathf.Clamp(rb.position.x, -xRange, xRange), rb.position.y, rb.position.z);
}
}
well it fixed the vibration when i move forward but now i just rotate in place nad dont move when i press a and d
send vid
👍 '
using UnityEngine;
public class PlayerController : MonoBehaviour
{
private float speed = 10.0f;
private float turnSpeed = 100.0f;
public float xRange = 4;
private bool walking = false;
private Rigidbody rb;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
horizontalInput = Input.GetAxisRaw("Horizontal");
if (Input.GetKeyDown(KeyCode.Space))
{
walking = !walking;
}
}
void FixedUpdate()
{
if (walking)
{
Vector3 movement = Vector3.forward * speed * Time.fixedDeltaTime;
rb.MovePosition(transform.position + movement);
}
float rotation = horizontalInput * turnSpeed * Time.fixedDeltaTime;
Quaternion turnRotation = Quaternion.Euler(0, rotation, 0);
rb.MoveRotation(rb.rotation * turnRotation);
rb.position = new Vector3(Mathf.Clamp(rb.position.x, -xRange, xRange), rb.position.y, rb.position.z);
}
}
try now
does the same thing just rotates much slower
i want it to just move left and right like physically in the world when I press a and d I had it working fine before but then it just like
ok
1 sec
using UnityEngine;
public class PlayerController : MonoBehaviour
{
private float speed = 10.0f;
public float xRange = 4;
private bool movingLeft = false;
private bool movingRight = false;
private Rigidbody rb;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.A))
{
movingLeft = true;
movingRight = false;
}
else if (Input.GetKeyDown(KeyCode.D))
{
movingLeft = false;
movingRight = true;
}
}
void FixedUpdate()
{
if (movingLeft)
{
rb.velocity = new Vector3(-speed, rb.velocity.y, 0);
}
else if (movingRight)
{
rb.velocity = new Vector3(speed, rb.velocity.y, 0);
}
else
{
rb.velocity = Vector3.zero;
}
rb.position = new Vector3(Mathf.Clamp(rb.position.x, -xRange, xRange), rb.position.y, rb.position.z);
}
}
try
@celest fable
it worked fine but once you pressed a or d it wouldnt stop moving that direction if you only tapped it once
alright
and you had to press the opposite direction to make it move
i got it working with this one except i just deleted everything after the if statement for the walking bool and added this
ty for ur help 👍
can someone help me with canvas as when i select a child image i cant see the canvas
wdym see the canvas ?
like i wasnt to set up buttons when i select the button i cant see the screen area so i dont know how will i anchor the buttons according to the screen
maybe Zoom out ? from this photo alone is hard to tell whats going on
like when the canvas is selected i can see the outer layer but it disappers when i select the image
it works now. Thanks for the help!
hey the tutorial guy told me to make a camera script so if i rotate the camera doesn't rotate with me and it's all basically the same and it's working fine except the fact that i don't want the camerae to completely center around the player and i want it to be a higher and more to the right like a super mario game how do i write that in the code
im trying to make the gold bars destroy after they are 6 units behind the player, but it only spawns like 2-5 before it gives up and stops
i have this script on my gold bar prefab
public class DestroyOffScreen : MonoBehaviour
{
public GameObject player;
private int i;
void Update()
{
if (transform.position.z < player.transform.position.z - 6)
{
Destroy(gameObject);
}
}
}
and this is my spawn manager
public class SpawnManager : MonoBehaviour
{
private int spawnRange = 4;
public GameObject[] prefabs;
private float startDelay = 2.0f, spawnInterval = 0.5f;
// Start is called before the first frame update
void Start()
{
InvokeRepeating("SpawnBar", startDelay, spawnInterval);
}
// Update is called once per frame
void Update()
{
}
void SpawnBar()
{
Vector3 spawnpos = new Vector3(Random.Range(-spawnRange, spawnRange), 0, transform.position.z + 20);
Instantiate(prefabs[0], spawnpos, prefabs[0].transform.rotation);
}
}
why does thta look like a mobile game ad
im trying ot copy flop one of them to learn how to use untiy
oh cool
forget that junk. use cinemachine
show inspector for spawnmanager
is gold bar a prefab from the scene or project folder
its in my scene
is that why?
i was using the one from te scene cuz If i used the one from my project fodler the scale wasnt right and idk how to change it
yeah you're trying to instantiate something that was destroyed
ohhh
apply the settings from scene view
you should have an option to apply all changes to prefab
ohh i see
im so lost i dont konw what im doing wrong ive done waht you said but they arent despawning at all
let me record a vid of it
expand the console
not sure what exactly that Player prefab is doing in there
in gold bar
oh that was some dumb shit i forgot to remove it
i was trying to make it not spawn if you werent moving but I gave up and forgot to remove it
alright so no console errors now right?
nope
whats the current code for the bar
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyOffScreen : MonoBehaviour
{
public GameObject player;
void Update()
{
if (transform.position.z < player.transform.position.z - 6)
{
Destroy(gameObject);
}
}
}
thats the only script it has on it
oh, which one is the pickup script then
there is no pick up script yet i am not there yet
oh ok..so what is the issue again ?
they are not despawning when they are off of the screen
ohh so thats why you have player in there?
put the player in scene reference on the Spawn Manager the pass that to the gold bars when you spawn them
the one from the scene
you can't put player prefab in there, it wont work
and you can't put scene objects in prefabs
public class GoldBar : MonoBehaviour
{
private Transform player;
public void Init(Transform p)
{
player = p;
}
void Update()
{
if (transform.position.z < player.position.z - 6)
{
Destroy(gameObject);
}
}
}```
NRTJNU89TE09W3K4T09WLTTHP,TGPOJN,EDTJMPTGM,JDTGOLJ
im ghonnalsoe itomg
gomg
imso
bad at htis
wat?
no thank you
ok
whats wrong?
hmm that line number doesnt make sense
Save the script and run it again, because that line cannot throw that error
are you sure this saved changes?
NRE are runtime errors
actualy means what this is problem not with my code?
probably haven't assigned a field
^
Okay, so the line changed. What's line 49?
anyway you're using animator but doesn't seem is assigned in inspector
...
animator is null
where did you assign it
Okay so where do you assign it
damn...
That is a declaration, not assignment. Common confusion between them
Still don't see how that would change anything unless you had awake/start somewhere doing GetCompnent
wait...
just make an inspector field for it and assign it like the rest of the references you have there..
no need for any of that jazz
yeah, im still testing script, ill do this
it keep sending me errors...
Where do you set animator
Hey why am I getting this error? seriously makes no sense
Where did you assign the value to manaCost? Note that by putting int in front, you are declaring a NEW and UNRELATED manaCost to anything somewhere else. Now, int DOES have a default value (0) but the compiler is concerned that you may not have intended it to be 0
Fixed it
I thought it would be assigned since I'm assigning it a valuse inside the if loop
that's not an error, it's a warning that the variable is not used anywhere . . .
How am I able to make a 1up system in Unity that if my Player collects 100 coins he will earn a 1up. Is there a video tutorial or anything?
meant switch
Yeah, just realized. gotcha
yeah, you should be able to find a bunch of level or experience system tutorials . . .
you can make an if loop that checks the amount of coins, after getting to 100 add 1 to your lives
Does it have a default case? I can't see it under the warning
no need for loop here
If you don't, there is potential it won't be set. That's what the compiler is warning there. There IS a situation where it would never be assigned to
That's the thing, I can't find one. If you do know can you send me a video where it goes over that?
all you're doing is checking an intiger if its over a certain value , increase another int
i literally just google: experience system unity and a bunch pop-up . . .
it's gonna be some basic == really
why it not working?
when i set bool "istrgger" to false it works, but it not destroying object
when true, script does not work
probably because you're not using OnTriggerEnter
I assume the method is OnCollisionEnter2D then?
please stop sharing screenshots of code
share full thing
you use oncollisionenter to detect a triggered collider
!code
📃 Large Code Blocks
Large code blocks should be posted as 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 get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
guys i think i am going insane what am i doing wrong
Here is my code
Debug.Log(index);
Debug.Log(objectives[index].objectiveName);
objectives.RemoveAt(index);
and here is my log
you have 0 items
nuh uh
look at the second log
it prints the name of the objective
which is the item at that index
okay
hmm share script
#💻┃code-beginner message
also show full console window without cropping
are u sure its not this line
Destroy(objectivesContainer.GetChild(index).gameObject);
show console window with the error expanded
you remove somthing from list in foreach loop?
the line number is 77: objUI.UpdateObjectiveUI(objectives[i].objectiveName, objectives[i].objectiveInt, objectives[i].targetInt); . . .
also, if you're storing the index to use a foreach, just do a for loop instead . . .
he use a go for parent i guess
yeah i didnt realize i needed the index until after i made the loop so i just got lazy 💀
make sure objectives has items in its list . . .
btw completeobjective maybe called in foreach loop and it removes element from the collection which iterated in foreach loop
also why 3 params for the same item , just pass the item directly
u right i definitely wrote that at like 3 am
😆 it happens
no, never. don't do that . . .
though you will break the foreach loop once you find the target, but still you should avoid modify the collection in foreach loop
This might be a very wrong take, but to me, foreach feels barely useful, there isn't much it can do over a for loop, or I wrong?
I suppose it's more readable
it's simpler to write, more readable, and less error prone
It's just syntax sugar for a for loop though
fair
I tend to completely avoid it, since I might realize I need to index Im on later down the line, which would mean rewriting the loop
Rewriting the loop is simple
Start with the simple thing
Don't do the complex thing until you need it
Rewriting stuff is normal
Ever hear of YAGNI?
https://www.techtarget.com/whatis/definition/You-arent-gonna-need-it#:~:text=YAGNI principle (%22You%20Aren',desired%20increased%20frequency%20of%20releases.
you arent gonna need it?
i dont understand how to fix this
The error message has a file name and a line number. Start there
Something is null on that line that you are trying to use
the reference becomes null when he start play mode
if (other.gameObject.CompareTag("spike"))
{
healthBar.TakeDamage(1);
}
Probably their code is setting it to null then
I understand this in the context of performance, but I doubt foreach performs better than a for
but I see what you are saying
it send me to this
!code
📃 Large Code Blocks
Large code blocks should be posted as 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 get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
Your healthBar reference is null then
but, i set health bar, but when i press play it just sets to null, is it prefab or code error?
https://hatebin.com/lyqzuuecgq
line 36 (start())
It's your code, as mentioned
healthBar = GetComponent<HealthBar>();
Why are you doing this
This making it null
You're getting component but setting the healthbar elsewhere
If you intend to set it in the inspector this is pointless and actually harmful
Since it's setting it to null
Just delete that line
try to always use inspector for references when possible
Hey, I'm trying to make an area on the ground where the player slides, how can I detect the player being in that area?
I tried using colliders but I don't want it to be collidable
just make it a trigger
Gonna look into that, thanks
Okay some questions relating Linecast.
I'm making a board game and I used Physics.linecast to find the objects next to my selected Unit. But the problem now is that if there are two objects surrounding my SelectedUnit, the linecasts hit only one of them and not both of them.
I thought I was making 4 line casts with my code but it seems I was wrong.
I wanna be able to detect and hit all objects surrounding my SelectedUnit in 4 directions
is there a reason ur not using physics.SphereCast? you would get surrounding units in single run
oh I never tried that actually
Can someone please help me. I am trying to have it that when the player dies his 1up counter (top right) gets decremented. However when the player collects 2 coins the 1up counter gets incremented. However when the player does get 2 coins the coin counter gets to 6. Instead of Lives + 1.
your playerLives in ItemCollector script needs to be updated as well when you take damage otherwise you add a life to default 5 value and update player lives with that resulting in that 6
I know, the thing is, is that I have no clue on how to do that
I would however move that logic to player itself and OnTriggerEnter see what kind of trigger it entered
Debug.Log("Local Anchor: " + eAnchor.x + ", " + eAnchor.y);
var anchor = LocalToPixel(eAnchor);
Debug.Log("Final Anchor: " + anchor.x + ", " + anchor.y);``` why is this returning the wrong thing?
I'm making per-pixel destruction and trying to move the joint from the parent object that was just cut into several bits into the part with the joint
{
point = new Vector2(Stuff.RoundFloat(point.x, 3), Stuff.RoundFloat(point.y, 3));
int x = Mathf.CeilToInt(Stuff.RoundFloat((((point.x - pixelSize / 2) / (pixelSize * size.x)) + 0.5f) * size.x, 3));
int y = Mathf.CeilToInt(Stuff.RoundFloat((((point.y - pixelSize / 2) / (pixelSize * size.y)) + 0.5f) * size.y, 3));
return new Vector2Int(x, y);
}``` this is what LocalToPixel is
it works just fine anywhere else
but here it isn't working at all
//Example: 1.48398183817, roundPoint = 3
//Result: 1.484
public static float RoundFloat(float value, int roundPoint)
{
float point = 10 ^ roundPoint;
return Mathf.Round(value * point) / point;
}``` this is `Stuff.RoundFloat` too
I tried to use LocalToPixel somewhere else and it works just fine
{
Debug.Log(LocalToPixel(new Vector2(Random.Range(-2.5f, 2.5f), Random.Range(-2.5f, 2.5f))));
}```
its fine anywhere else but not here
Log stuff to see where the value becomes weird
I doubt rounding is the issue. Likely your computation (subtraction/division) of some arbitrary value.
Break the problem down. Log stuff in the function
if I use the exact same values of these vectors somewhere else
in local to pixel
it works just fine
but here it doesn't for some reason
It worked with A but not with B - edge case.
Good luck then.
the function is kind of a single line.
.
It's implied
I would see what float point = 10 ^ roundPoint does cause wtf
its not about this function
If you're not certain of your math/numbers..
the issue is that size.x isn't set.
size.y isn't too
since I set that AFTER this code is run.
I am very smart I know
thanks
what
The one to move the cubes
move to mouse, round to ints and do lerp for smoothness from one pos to another
Is there a video or script to do that?
script allredy done but i have a no idea bug fixing
probably, its not that hard to make just break down each thing to learn then combine
That what I saw from learning C# from Unity I don't have much room to memorize that why I forget the things I see
i needed snap fix amount of left or right move my objects by mouse or touch through
@cursive tangle no reaction gifs, please
learn the logic to achieve something, the code comes after
code is the tools yes?
Yeah?
pov u want to make X but X was made by noone except some guy with bandicam watermark across yt 30sec clip 10yrs ago
too true 😂
I needed proper programer help
You need to ask proper question
I needed a system ( fix amount snap my 3d object by mouse through) left or right
what is wrong with it?
What mean
you said fix ?
you have to build it, or google .
You won't find script here..
bro u didnt even say ur problem or im tripping
Is there a video so I can learn unity c#?
friendo , gpt is as useful as a wet sock
If possible, you can show the video in Spanish.
of course there is don't be silly..
the internet is full of them
does google español not exist?
haven't we been here before or am i having dejavu..
Thought it was solved?
Where open method was never called
Triggers do not work after the build on android, but it works in the editor...
You can try debug to see maybe you have a NRE somewhere
try a desktop build also, see if that works
Why this is not working? I want to spawn prefab while pressing e and also while colliding
you need to be some type of flash to press that at same time as trigger enter
you can't check input during OnTriggerEnter. do that in Update . . .
OnTriggerEnter is called during a single frame . . .
oh
use a bool in update to detect when ur inside trigger
alr
i dont understand how to fix this though
Thank you! @rich adder @cosmic dagger problem is fixed!
Do you ever call the method?
Whether it's used as an inspector callback or through code, it needs to be used somewhere for it to have occurred.
are you talking about public void Open(Vector3 UserPosition)
im just confused on which method
and thats the script on the door
which has the sounds attacthed to it
Yes as suggested prior #💻┃unity-talk message
All his code seems to be from ChatGPT, he doesn't know where Close and Open is called on the doors, I asked him in #💻┃unity-talk. I told him to do an actual programming course instead of just copying stuff from ChatGPT.
No i did not get it all from chatgpt
i followed a guide
and then when this error came up again and again
i handed it to chatgpt
i thought a class getting called is you writing it
when the door opens in game
but doesnt it already get called when it opens in game because the method opens the door
and the sound plays with it
Well, something is calling Close and Open, and you say you followed a guide that wrote it, then you would know when you actually did write it.
I think you should follow the guide exactly as is
I think getting some coding fundamentals would be better to get before following the guide, like the junior programming pathway linked in the top right.
Then you would actually get the idea behind why the guide does what it does. But what ever floats your boat.
yea probably should aye, i do not see the junior pathway link
cheers
can someone help i cant get my player to move
i have
Have you read the Do because it doesn't seem you did
i did
lets make sure
how can i save my progress ingame? im making a 2d drag racing game and idk how to make a saving system,
your missing a }
^
but theres a gazillen lines
make sure if you have a { that their is a }
well mate
In your movement script?! (inferring line count)
?
let me guess, you copypasted a script and dont know how to fix it
i hope you're not actually using notepad to code..
^
not even notepad++
I suggest using an actual !ide, it will help a lot with coding.
If your IDE is not autocompleting code
or underlining errors, please configure it:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code*
• JetBrains Rider
• Other/None
*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.
username checks out
Saving between game sessions or between scenes?
well, i need between scenes and when i close/open game
so, both?
use a file
json is a good format to keep things organized
Make sure to use an IDE that's properly configured. It's required to get help on the Unity Discord server - relative to code. You can check out how to do so in the #854851968446365696 channel
ide?
you just create a json/text file in a special folder that unity has called Application.persistentDataPath
technically you can save it anywhere you want on pc, this is just a common folder for all platforms / devices
It's what you ought to be using to write your scripts with sanity.
if possible, can you give me a code example on how to do it?
there is no explanation on this one like I typically do but here I've made the whole process shown in about 5minutes
https://youtu.be/Q0_xreJMldM?si=6LmoIaRYq-Qi8OPP
This video will quickly be going over saving and loading data to a file.
More Info from what is used in the video:
https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html
also, how do i use values from script to script? i have been trying to figure out but all tutorials were useless, idk what to do
uhh if you're still att that point understanding that vid might be hard for you lol
i mean i made a functioning car w manual transmission
but could be
I might quit Unity
this only tells you references but thats how you can connect 2 scripts
you just need them to be public variables / methods and use . operator
do some basic c# courses
There's the dirty solution: player prefs 
https://docs.unity3d.com/ScriptReference/PlayerPrefs.html
a tutorial for further instructions.
argh we had a whole discussion about that monstrosity , unity should have their own integrated solution already that is not playerprefs.. lol
im already learning c# in school
i have also made a rocket ship game
dot operator would probably be somewhere in lesson one lol
its prob one of the most important operators
dot operator?
they make us make games from tutorials
dot operator? the one that connects the code together, sorta?
idk
it lets you do a specific thing somewhere with something
I created a script but for some reason whenever I save it in Visual Studio I just get spammed with warnings in the console:
[Worker0] Import Error Code:(4)
Message: Build asset version error: assets/scripts/counters/platekitchenobject.cs in SourceAssetDB has modification time of '2023-09-30T10:02:15.8462733Z' while content on disk has modification time of '2023-09-30T10:03:15.9066344Z'
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
What does this mean and how do I fix it?
yeah i know wdym now
i knew what that was just didnt know the terminology aswell lol
school doesn't teach terminology
Never referred to it as the dot operator either in university
I never went to school , I couldn't tell ya
From what I understand somewhere two clocks don't match and unity isn't happy about it
Yeah they just taught us that's how you access things but that's it
microsoft calles this Idk
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/member-access-operators
I think they call it "member access operator" officially
The dirty solution.. 😳
close
Alright for some reason it works now 👍
so uh
Yeah the overall teaching was good, but the prof had their own naming conventions so we stuck to it for 2 years, and then when I got my first job that used the official conventions I was like "wtf???"
thanks
okay i stil;l dont see anything wrong
is not configured
You now need to configure VS Code so it displays errors for you
breh
Html copy paste mishap
this won't be the first spelling issue you will have coding if you don't configure it now.. You're only hurting yourself
Intellisense did not kick in. Your ide hasn't been properly configured.
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code*
• JetBrains Rider
• Other/None
*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.
how to configure
!vscode
It might be also due to the fact that Restricted Mode is activated. See the blue bar at the top to disable it
You will need to do that anyway to configure it
well at least now vscode is reduced to 1 extension and updating a package 😅
microsoft came in clutch on that one
Yeah before it was hell, you almost had to open your computer and bend 2 CPU pins to make it work lol
ah just realized they have compile error and external tools window might not see vscode until it compiles
Is PlayerPrefs a temporary save? I used it to transfer some variables between scenes (the game level + menu) and they working but when i start a new play session i still can load them back however they also gets overwriten by the new session values.
For example if i have a score variable and the player scores 2 point then on the next try 1, the total score on the stat would show 3. If i exit the app and start again i can load back the total score 3, but if i score, say 2 point it the total score will be 2 instead of 5. (android phone)
PlayerPrefs is meant for settings, like audo volume, graphic quality etc, so it's permanent. For transfering data between scenes use a static property, scriptable objects or DontDestroyOnLoad
which one is easier to use?
None of those work for your problem
Playerprefs is fine, you have some issue in your own code
oh I read the question wrong
but the addition is working one the first play session correctly it just get overwriten on the second play session
Show the !code
📃 Large Code Blocks
Large code blocks should be posted as 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 get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
Yup, because you have made a mistake in the code
You don't load the score into the variable when the game starts. It only updates the text.
highscore works fine btw, only total coin/obstacles and number of tries get "overwriten" at new session
ohh so i should load them in the logic start method?
i did try to load them in the start method of the menu script tho, i will try to move them to logic then
Hello how do I get a value in a dictionary all I have is the key
yourDict["yourKey"] = the value of that key. Kind of depends on what kind of key you have.
it still overwrites my data.
You didn't do it properly then
you were right, solved it. Thanks 🙂
Hi. Does anyone know a good tutorial or something for dynamic footsteps? Either they're all using the standardassets firstpersoncoltroller script and adding to it or they're really outdated.
Unity giving me a missing reference exception even though I don't destroy the object in question
This is the code that causes the error. Basically subtracts the player health by 1 then disables the player object when it reaches 0.
Idk why it tells me the gameobject is destroyed even though I just disable it
I am making a game. I have created a ground material in the game. I want to randomly multiply this ground and make it a level, but the code I wrote did not work. I My goal is to make the character you see in the picture jump when it hits the ground, play like this.I will send you the code too, 1 minute
!code
📃 Large Code Blocks
Large code blocks should be posted as 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 get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
Please use one of the paste sites
I've got a couple prefabs that make up different patterns of individual objects I'm spawning at once. Is there an easy way to get the size of the whole prefab without having to code it for each prefab?
Trying to get them to randomly spawn into a particular sized zone and need to adjust the position based on the size of the pattern so some of them don't go out of bounds
Well you could add up the bounds of all individual objects in the prefab with a script during editor time
Or when you spawn the objet depends on your need
I was thinking if there wasn't a built in way, that I might just add a collider to the prefabs and use the bounds properties? Does that make sense? Seems easier than trying to add up all the children
Seems like something that can be calculated pretty simply from the prefab? Just iterate over the children?
Use this on all the children to get the group bounds https://docs.unity3d.com/ScriptReference/Bounds.Encapsulate.html
I'm probably being dumb here, but if every prefab is different arrangements of objects, how could I do that consistantly? If I have 1 that's 4 rows of 2, and another that's 3 row of 4, and another that's a single row of 5?
Ahh, alright, this one might work
Just write a script that encapsulates the bounds of all children it will work for any number of children
With a for loop
how to turn collider result from overlapsphere into meshcollider component
turn it?
DO you mean it's already as MeshCollider?
and you just want to treat it as such?
yes
I'm making a game. I created ground material in the game
With this, I created a code called ground generator.
The purpose of the code was to make the ground prefab, multiply them randomly in a certain place and level them up, but when I ran the code, it did not multiply the ground. What is the reason for this error? My aim is to make the character you see in the picture jump when it hits the ground, to play this way.
can ı help me
if (theCollider is MeshCollider mc) {
mc.Whatever();
}```
YOu still aren't posting your code properly. !code
📃 Large Code Blocks
Large code blocks should be posted as 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 get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
Hi all. I want to check for inappropriate images within unity. Is there any sdk available for this?
Is it like this?
just pick a website you like in !code and paste your large code block on it.....
📃 Large Code Blocks
Large code blocks should be posted as 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 get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
what about later
It doesn't work, what I posted is quite self-explanatory.
There is no error message in the code, I mean there is no error, the code does not replicate when it runs, can you solve this?
you've also already been told why it doesn't work
it's already solved
you simply have to read what people are writing to you
So where is the solution? I don't understand.
I posted the code neatly in all 3 ways.
and finally, where do you call
start? because that isn't the same asStartwhich is what Unity will call automatically
The first was redirecting you to the proper channel for the problem illustrated. The second was to inform you how to properly send code if you need further/future help. The third was the suggested solution.
Now I understand what happened, thank you
fix your spelling
So exactly which part of the code should I fix? I'm sorry, I'm a bit of a burden to you.
start is not a thing
It won't be in any documentation or tutorials
It
isn't the same as
Start, which is what Unity will call automatically
So is the start there unnecessary?
No, you just haven't capitalised it properly, and somehow haven't noticed the difference in the 4 or so times it's been pointed out
unity has a number of messages it will send to MonoBehaviours when certain conditions are met
for example, the Update message is sent every frame to every enabled-and-active MonoBehaviour
Yes, the first letter of the start was supposed to be capitalized, but I wrote it lowercase, thank you very much.
and the Start message is sent before Update on the first frame an object is enabled-and-active
problem solved
messages work by finding a method with a matching name and calling that
method names are case-sensitive
https://docs.unity3d.com/ScriptReference/MonoBehaviour.html has a list of every message a MonoBehaviour can receive
thanks goodday
Why does my player GameObject start bugging/flashing and shrinking when he jumps on the platform that has a setparent script when the player jumps on? Is there something wrong with the players transform?
I want to create hilly terrain in 2D- is there an easy way to go abot this?
ur asking questions that we cannot answer based on this screenshot
One sec
Your favorite art program + splines package
https://gdl.space/oselocawaq.cs this is the sticky platform script
Splines package?
splinesssss
https://gdl.space/xedefufuga.cs platform movement
Damn could of just did it in 1 link
Anyway
is that mostly editor or actually proramming focused
so when u parent it disappears ?
hmmm thanks
Not fully disappears, It flashes and it's scale starts have a seizure
Navarone I noticed a problem
While it's on the platform it starts parenting and unparenting
even when it didnt exit
yeah the debug.log keeps saying entered exit on repeat
show the trigger areas and whatnot
try make video if possible
u have two colliders i cant tell which one is the trigger on it
the top collider has the trigger on the platform
do you know if there is an easy way to add a collider to a spline?
googling it shows a paid asset on the store
Probably something like edge colliders and looping through the points
also mesh colliders
where are u deactivating the platform?
are you using object pooling for your platforms?
Not that I'm aware of
then you need to search your code for a SetActive(false)
are these two scripts only ones that are important ?
Well I flipped the istrigger on the boxcolliders on the platform
also show rigidbody setting for platform
the flashing disappeared
I removed the rigidbody for the platform rn
but then the player doesnt get parented*
and just slides off
one sec im onto something
yes it gets parented now correctly however
the player shrinks
once it becomes a parent of the platform
more likely it could be the scaling being non-uniform might be messing with size
I think this way be the right place? My characters footsteps only work on flat surfaces or going down an incline but when moving up an incline, they do not work
for (int i = 0; i < cablePoints.Count; i++)
{
if(i < cablePoints.Count - 1)
{
cablePoints[i - 1].GetComponent<SpringJoint>().connectedBody = cablePoints[i + 1].GetComponent<Rigidbody>();
}
}``` i get that error beacose the ``i + 1`` but i don't know how to make that error not occur
Yeah size is being messed with once the platform parents.
Can someone please give me a 2D character coontroller
yes , its maybe the scale of platform messing with player
Thanks, but do you know one which is in one script?
I just need a really simple one for a proof of concept
did you bother reading the description?
it also has a video
Can anyone help or point me in the right direction. Not sure what to search in regards to this
Wow someone literally hands you the solution on a silver platter and it ain't enough
yeah my mistake, it never is for those type of people xD
What about the footsteps doesn't work, is it the animations? Or something else?
I'll take a video. 1 min
OBS isnt working. Basically, the audio doesnt work when walking up any incline, but walking down it, it does. its very weird
going up. no sound. going down. there is sound. (footsteps)
Hope that makes sense
Show the code that plays the sound
!code
📃 Large Code Blocks
Large code blocks should be posted as 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 get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
If it works going down but not going up then it's probably starting the ray inside the collider. foot.position is likely underneath the terrain. Try casting from further up
I'm assuming you mean I should increase my "Raycast" length?
no, raise the position from which it is fired and increase length
No, if it failed going down then that would be the length. You need to raise the origin
Isn't that the empty "foot" object I have? If so, I have raised that and also increased the length
Your foot transform needs to be moved up
Yep how far did you raise it?
You might want to add a Debug.DrawRay to visualize the raycast
was just about to mention that
Could I get a quick hand here please. Trying to draw the ray.
why you draw"line" only if raycast hit something
DrawLine takes two points.
You want DrawRay.
It takes a point and a direction
and draws a line from point to point + direction
also, the fourth argument is not a length.
It is how long the line will stay drawn.
Debug.DrawRay(foot.position, -foot.up * raycastSize, Color.red, float.MaxValue);
//inside raycast if statement if you want
Debug.DrawLine(foot.position, hit.point, Color.yellow, float.MaxValue);
if not provided, the line will last for one frame
I did realize and face palmed myself. :p
you may use else to draw ray of different color
if hit draw red ray
else draw green ray
easier to debug
I thought my Raycast size was my distance? That I can change in inspector? (I'm kind of taking reference to my interact raycast)
That, is a very good idea
It is the distance for the raycast, yes
yeah isn't that the same var u use for ur raycast?
But you passed it as the fourth argument to DrawLine
That is not correct. The fourth argument is the duration of the DrawLine/DrawRay command
You should instead mutliply it by the direction the ray was casted in
-foot.up has a length of 1.
Multiplying it by raycastSize will give you a vector that's the correct length
so that Debug.DrawRay can draw a line from the start to the end of the raycast
Raycasts and DrawRay are different
There is no "length" parameter of DrawRay, the direction and length are the same one
Hi, I have two Shader Graph shaders that I want to use on a single sprite. However, SpriteRenderer only allows for a single material in the Inspector. Does this mean a sprite can only have 1 material assigned? Is there the option to use a materials array?
cant you just combine the shaders into 1 ?
I'm just reading all you have written and looking at unity docs
Vector3 start = new Vector3(1, 0, 0);
Vector3 end = new Vector3(3, 0, 0);
Vector3 delta = end - start; // [2, 0, 0]
Debug.DrawLine(start, end);
Debug.DrawLine(start, start + delta);
Debug.DrawRay(start, delta);
these are all equivalent
bruhhh never click this on VS Mac...it will leave you staring at your own code wondering why it looked spooky...
I was like "is this even my code" TIL about Intermedia Language mode
Gameobject.add in a while loop not working the same as a debug statement
Yea just thought i broke VS somehow lol
unless you do IL2CPP, of course, in which case you compile it ahead of time
8: 'PlayerController.rigidbody' hides inherited member 'Component.rigidbody'. Use the new keyword if hiding was intended. how do i get ride of this warning. Im asigning it in start with void Start() { rigidbody = GetComponent<Rigidbody>(); }
Well, they are separate because most times they are used separately, but in a few cases I need both, so I was trying to avoid combining them to make a third one...
now this is some legacy content
yeah iirc rigidbody used to be a property on monobehavior
In the distant, distant past, you had a bunch of extra properties on MonoBehaviour
These don't actually exist anymore, but you still get warned that you'd be hiding them
if you declare a member with the same name as one from your parent, you're "hiding" it
is there a fix to remove that warning
i just call my rigidbody rb xD
You can add new to signal that you meant to hide the field. Although, I think that'll then cause a warning when you compile, because that member doesn't actually exist in the built game
or add the new keyword I suppose
public new Rigidbody rigidbody;
but yeah thats ugly
I always call mine rb
yeah very common across the board i think
ray is sorted. testing now
Thank you all for helping with that
Cheers is just used rb
So my ray starts at my empty game objects transform. it follows my player as it should. If I raise it. then it doesnt work at all
you could just disable the warning
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives
look under pragmas
good to know thanks
show current code
and by "raise it" you mean in the inspector / scene view or sum
I've raised the transform in scene view. I've made the ray longer too. I'm just lost why walking up an incline, there's no footstep sounds but walking down the same incline, there is
those try catches 😲
are the methods for playing those different?
What do you mean?
walking up no sound, walking down sound
what makes those different, I don't know much about it besides what u sent
how do i connect wheelcollider to car? i got 4 wheels and 1 cube car
doing new unity3d project on 2021 version.
tried doing this, but the wheels go away
https://docs.unity3d.com/Manual/WheelColliderTutorial.html
you attached them to a main rigidbody
the cube car? is it also rigidbody?
alr show a little more of the current setup
ill show soon, got bored waiting and closed unity
i've made a 3d project where you are able to move in every direction ( except downwards, gravity is dealing with that ) but for some reason, ground collisions work fine but when it comes to the side collisions of the platforms i'm using, it goes really weird. I can get inside it until the invisible plate i use that i place on top of the platform detects a collision with the sphere i use for the player. Can someone please help me with that ?
share script
ok give me a minute
What would be a good way to Lerp between 0 and 1 using an enum and a dynamic time? like timer = 1 or 2+ etc. This is for the slider to go between 0-1 over X time
IEnumerator LerpGlow()
{
mat.material.SetFloat("_Lerp", 0);
float newTimer = 0;
while(newTimer < timer)
{
newTimer += Time.deltaTime;
mat.material.SetFloat("_Lerp", newTimer);
yield return null;
}
are u using a character controller?
Translate wont give you accurate collisions and will phase you thru stuff
you're essentially teleporting the player
would it be
mat.material.SetFloat("_Lerp", Mathf.Clamp(0, 1, newTimer));
to clamp the range?
what is that
a component
i don't think i'm using that
screenshot player inspector
but anyway dont use Translate lol
what's the alternative
You already have a rigidbody
use that
.velocity or .AddForce()
you can't freeze position tho
unless u only move up and down
what do you mean
the constraits you currently have on rigidbody
"Freeze Position"
do you know what that does
well i think i tried to use it to solve an issue i had with camera movement but it didn't solve it so i did something else and it was a success this time so for now Freeze position is useless for me
but i want to know what is it's use
it just freeze the rigidbody on those axes (ie if something smacks into it it doesnt fo flying on x or z)
or in your case also it doesnt rotate up or down when hitting something
anyone know why my tilemap2d collider has this weird colliders?
https://gyazo.com/6ecf928756f5ab4e8f0a62732ca4ef45
Probably the wrong channel, try #💻┃unity-talk
Hi, I hope i am posting this in right channel, if not let me know and ill move it.
ive been trying to get my projectile to "kill" objects in my scene but i cannot wrap my head around why it doesnt work. Is there anyone that could help me to see what it is im doing wrong ?
what ive checked:
collision matrix - everything is ticked so everything can collide with everything.
box2d collider is set to "is trigger" on both projectile and enemy
body type: dynamic
collision type - discrete
Tags
layers
note: the enemy (2dsquarered) is a child of empty "Enemie"
2dsquarered is what holds collider, sprite and rigidbody2d
what i notice of behaviour: player and enemie doesnt collide and are able to walk through eachother.
bullet: flies through enemie.
ive added screenshots containing the various inspectors of each element and projectilebehaviour and enemyhealth script.
thanks in advance !
yea so you need to change OnCollisionEnter2D into OnTriggerEnter2D if any of them is a trigger
ooooh..... hang on ima do that o.o
it seems to be grayed out when i do this but i get no errors ?
theres a mistake its OnTriggerEnter2D tho you should let vs autocomplete it
it doesnt autocomplete, ive changed the D though
ahhh
start writting ontrigger in an empty line outside methods and it should suggest all related
when typing "ontriggereneter2d on a empty line, it doesnt bring in {} and all that stuff automatically, ive seen it done it before, would u know why ?
This fixed it !!!!!!!!!!!!!!!!!!!!!!!!!!! thanks so much btw
@timber tide u think you can try and help me out?
you already read all of the code yesterday
i think u understand it as least a little bit
with the quick stacking
ive got no clue maybe something wrong with configuration
I can't find the render pipline in the unity edit section, how can I add it?
I have a parameter in my animator called speed which I want to be equal to my players movements, how would I write this in code?
the "unity edit section"?
I do not know what you're referring to.
you would do animator.SetFloat("speed", 2f);
or whatever value you want there
If you're using a rigidbody and it's named rb, you could do animator.SetFloat("speed", rb.velocity);
err
animator.SetFloat("speed", rb.velocity.magnitude)
there we go
rb.velocity is a Vector3. rb.velocity.magnitude is the length of that vector, which is your speed
You should do this in Update, since that runs before the animation system
I guess that's kind of the default anyway, lol
doing it in LateUpdate would make your values a frame late
Is there any reason that this code would stop my camera from moving left and right and locking it into the middle?
exactly why im confused. if i remove my footstep script. my camera works?
This is the other script
Perhaps an exception is being thrown and stopping something else from running
why are these last 2 days very problematic xD
Make sure you are not getting any errors in the console
notably, make sure that you haven't just hidden the errors
would anyone know how to make an object grabbing system like Half Life 2? The player holds an object that can be up to a certain size, his weapon disappears and when he presses left click he releases the object and right click he throws it and the weapon reappears
I would create a system to control which "mode" the player is in
currently, you only have the "combat" mode, where you have a weapon out
in that mode, you would show a weapon and let the player fire
when you exit the "combat" mode, you would hide the weapon
once that works, you would add a "grab" mode
I'd attach the object to the player with a FixedJoint
or maybe a SpringJoint, if heavy objects should move more slowly
when you enter "grab" mode, you would attach the joint
and in "grab" mode, you'd use the input that normally makes you shoot to instead disconnect the joint and shove the object
you could also check if the object is too far from the joint and forcibly exit "grab" mode
So I would start with "combat" and "idle" states
that'll be an easy one to do: just put the weapon away and do nothing special
I was using Unity Renderer. In Unity, there should be render pipline in the edit section, but there is none, how can I do it?
it should be like this
but it should be like the 2nd picture
Is it due to version difference?
Not really sure what you mean, and also not a coding question, but you probably want to go to Quatlity and set the renderer there?
I already added
hello, im trying to integrate gpt into unity via this tutorial. https://www.immersivelimit.com/tutorials/how-to-use-chatgpt-in-unity
i have an error that i cant fix, ive looked everywhere to see where to get the namespace but to no luck.
/// <summary>
/// Optionally provide an IHttpClientFactory to create the client to send requests.
/// </summary>
public IHttpClientFactory HttpClientFactory { get; set; }
/// <summary>
/// Creates a new entry point to the OpenAPI API, handling auth and allowing access to the various API endpoints
/// </summary>
/// <param name="apiKeys">The API authentication information to use for API calls, or <see langword="null"/> to attempt to use the <see cref="APIAuthentication.Default"/>, potentially loading from environment vars or from a config file.</param>
public OpenAIAPI(APIAuthentication apiKeys = null)
{
this.Auth = apiKeys.ThisOrDefault();
Completions = new CompletionEndpoint(this);
Models = new ModelsEndpoint(this);
Files = new FilesEndpoint(this);
Embeddings = new EmbeddingEndpoint(this);
Chat = new ChatEndpoint(this);
Moderation = new ModerationEndpoint(this);
ImageGenerations = new ImageGenerationEndpoint(this);
}
(the line with the error and the surrounding code)
Look up IHttpClientFactory and see what library it's in. You may have download a .dll from NuGet or another place and drag it into your project. From the error message, it looks like you're missing whatever package that type is defined in.
i might be wrong but from what i can see its in ASP.NET? thats what i gathered from the first link atleast
Microsoft.Extensions.Http.dll is what you need to find and download, looks like
alright, thank you! do i need to install that via the in unity package manager or do i import the dll from an external service?
It's not a Unity Package, it's just a .NET library. So maybe from NuGet https://www.nuget.org/packages/Microsoft.Extensions.Http/
The HttpClient factory is a pattern for configuring and retrieving named HttpClients in a composable way. The HttpClient factory provides extensibility to plug in DelegatingHandlers that address cross-cutting concerns such as service location, load balancing, and reliability. The default HttpClient factory provides built-in diagnostics and loggi...
sorry, i havent used anything but the package manager before now. could you explain please?
!cs
Hello, i'm new to unity and c# and eager to learn both, can you guys help me understand how does the distance inside the BoxCast work?
RaycastHit2D raycastHit = Physics2D.BoxCast(boxCollider.bounds.center, boxCollider.bounds.size, 0, Vector2.down, 0.1f, groundLayer);
for example in this code, i have a distance of 0.1f
does that mean that distance applies only to vector2.down?
no worries! go to the link, click download package, it will give you a .nuget file. change the extension to .zip and extract it. go in and find a .dll that corresponds to the scripting runtime you're using in Unity (probably look for the .NET Standard .dll but that that's up to your project). Drag that .dll into your Unity project (somewhere like Assets/Plugins/)
which mean the y axis -1
the distance is how far the box will travel in your given direction. if you mean to not move it at all then use an OverlapBox instead
@upper spire including external packages can be complex so don't fret if it trips you up. this may or may not work to fix for your error, but I hope it does!
so it that case it only affects Vector2.down right?
Vector2.down is the direction. i don't know what you mean by "affects" it since it doesn't change the direction. it's just how far in that direction the box travels during the cast
@upper spire I'm not sure why they have made it so complicated. It is easy enough to write a GPT interface just using UnityWebRequest

Oh so that's how it works, now i get it, thank you so much!
btw why did my code show unformatted? i used cs after the three backquotes

