#💻┃code-beginner
1 messages · Page 249 of 1
and there's no reason you can't add more maps that define more qualities of the material
I want to kill myself after coding this (not a question)
so like a texture pass onto a plain color sketch?
that is terrible architecture 😄
@fringe plover 🤝
Holy sh-
call back hell
just code it better LOL
HOW
write methods in local scope to reduce nesting
where did all my animations go, they still play in game but i dont see the state machines
also you can check if the opposite, then log error, and return
if (val == null){
do X;
if (next…)
..
}else do Y;
Is the same as;
if (val != null) {
doY and return;}
do X;
if (…)
okay ill try
hello does anyone know???
then you won’t have 69 layers of nested ifs
public async Task<string> UsePromo(string code) {
var isLogged = await IsLogged();
if (isLogged == false) return "you need to login";
var isValid = await IsPromValid(code);
if (isValid == false) return "code is invalid";
var isValid = await IsPromUsed(code);
if (isValid == false) return "code has been used";
return "code is valid";
}```
something like this would be my first idea
wait wha-
Hello its not a code question?
so where do i ask
#🏃┃animation probably
https://gdl.space/tezupoxejo.cs hello, I have this piece of code that takes a set of instructions (along with timers) and outputs an 8-byte array that encodes that data for further transfer (debug.logging atm)
it seems to work, but Im looking to optimize it a bit, would love some advice with that!
Also have some patience
yeah, just flip your if statements so you can return as fast as possible
still does anyone know?
sorry mate
I'm a Never Nester and you should too.
Access to code examples, discord, song names and more at https://www.patreon.com/codeaesthetic
Correction: At 2:20 the inversion should be "less than or equal", not "less than"
i mean the number that you said...
he literally breaks up something that looks exactly like your code
they just gave an arbitrary number to get their point across (stating that you had a lot of ifs) . . .
yep. 69 is just a standard, arbitrary number
when you only ever need a max depth of 1 for this code
okay...
okay tysm!
I'd say that the readability / maintainability of the code you posted is of secondary concern.
the main issue I see is that you are doing what I assume is a web request in a synchronous manner, this will then "freeze" you game while the code is running / checking the code.
using async/await model or a coroutine should be the first point up for a refactor imo.
well, at least it works... ill change than, thx for saying
maintainability and readability is always a primary concern
because unmaintainable/illegible code is the fastest way to get something that works, breaks later, and now you have a bunch of code that depends on code that you cannot fix
i wanted to use return instead of Action things, but i used Action cuz of weirdness of API that i use...
Maybe there was more ways to do it but tbh.. i dont know how...
write a named function
what?
it can even be local scope, if you need
for (int i = 0; i < 5; i++) {
Increment();
}
return x;
void Increment() { x++; }
}```
here, Increment can only be used within the scope of Count(, but it is at least named
oh...
now you have an api as following
public class TheObject{
TryThing1(params, Action onSuccess);
TryThing2(params, Action onSuccess);
TryThing3(params, Action onSuccess);
}
```then you can write
```cs
private TheObject theObject;
public Try(){
theObject.TryThing1(params,OnSuccess1);
}
public OnSuccess1(params){
theObject.TryThing2(params,OnSuccess2);
}
public OnSuccess2(params){
theObject.TryThing3(params,OnSuccess3);
}
btw some api use singleton, you dont need the field in this case
ill try ig.. i still need to recode it... so, thanks for advice, i need to learn how to use these...
locally scoped functions just let you to define a named function, without actually adding a member to the class
tina is referring to just writing actual member functions
the never nester video should give you ideas of how to straighten out nested code
i want to have an enemy follow the player. why is having agent.setDestination(player.position) in update gives the navmeshAgent a seizure and doesnt move?
im talking about the new navmesh system which honestly i have no idea why they changed it. it was perfect
make sure its placed on NavMesh
it is. having the function run one time is the only way it works but it doesnt follow the player. it follows the path of the player when the functino was first run.
do you mean it does move top player start pos, but doesnt follow player?
yess
make sure its on Update + player may be unreachable
im not sure ho it works, tried NM only once
it is. and the player is reachable
one sec ill send a video of how it is when it is in update
what exactly is player.position??? isnt it supposed to be player.transform.position? or you have it recorded in script?
maybe this value doesnt change
the player is a Transform instead of a gameObject. so i just took the position
here this is a video
in general, I don’t think you want to move a transform when something else is moving the transform
like you don’t want to move a transform when the transform is being controlled by a rigidbody
idk if navmesh is the same, but maybe it is
huh? no its the same thing the its just so the code is simpler. instead of getting gameObject.transform.position you just get transform.position
they're not moving the Transform
Is Application.quitting guaranteed to fire before Unity starts destroying objects?
I have entities that need to do some cleanup when playing the game in the editor, since I have Domain Reload disabled
I want them to be able to do this before random stuff is being destroyed
thank you nitku, I think I understand how it works now
it was confusing but I know how to make flow properly now
also I ate KFC earlier
I am happy
oh, the plot is thickening in interesting ways
i was assuming that destroying a game object destroyed its components and children in some kind of order
looks like it's more random
ah, that's not even what's happening here, though
I have an Entity that references a Brain. I need to tell that brain to disengage so that it unsubscribes from InputAction events. The brain is not parented to the entity
I tried having the entity respond to OnApplicationQuit by destroying itself, and then disengaging the brain in OnDestroy
But destruction doesn't happen until the end of the frame normally, so this doesn't do anything immediately
then Unity starts destroying everything in the scene, and it winds up destroying the brain first
(and the entity skips trying to disengage the brain, because it thinks it has no brain at all)
ugh
I guess I'll have the brain disengage itself if it gets destroyed
this sounds so scary without context 
I havent tried brain thingy yet, but hope you find a solution 
bro what should i do with my code, so i want to make my game to pick up all object in my game
using System.Collections;
using UnityEngine;
public class CarryObject : MonoBehaviour
{
public GameObject pickAbleObj;
ArrayList pickableObj = new ArrayList();
public Transform handPlayer;
public float range = 2f;
public GameObject pickUpButton;
public GameObject dropButton;
private void Update()
{
CheckForPickableObject();
}
public void CheckForPickableObject()
{
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.forward, out hit, range))
{
// Memastikan bahwa objek yang terkena adalah objek yang bisa diambil
if (hit.collider.gameObject == pickAbleObj)
{
pickUpButton.SetActive(true);
}
else
{
pickUpButton.SetActive(false);
}
}
else
{
pickUpButton.SetActive(false);
}
}
public void PickUpObject()
{
if (pickAbleObj != null)
{
pickAbleObj.transform.position = handPlayer.position;
pickAbleObj.transform.SetParent(handPlayer);
pickUpButton.SetActive(false);
dropButton.SetActive(true);
}
}
public void DropObject()
{
// Memastikan ada objek yang dipegang sebelum mencoba melepaskannya
if (handPlayer.childCount > 0)
{
pickAbleObj.transform.SetParent(null);
dropButton.SetActive(false);
}
}
}
Classic, doesn't actually read beyond the first sentence. If you're not going to, why even bother asking questions.
im loading in a sprite with this code
and the image is alerady set to transparent
but when the game loads it in it's set as a white square at first
Do you know what the 4th argument does?
transparency?
Transparent in what sense? Like has transparent regions?
By default a UI Image is a white square. If you set the color's alpha to be 0, then ya it'll be invisible. You seem to be setting alpha to 1 at some point before the Pokemon comes out.
why bother with GetComponent<IMage> if you're just grabbing the Transform? You can just do transform directly
oh yea i just changed it and it makes no difference LMAO
this unfreezes my rotation cs rb.constraints = RigidbodyConstraints.FreezePositionY;
how can i just freeze the y position while leaving the other stuff alone?
rb.constaints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionY;
alright now how can i unfreeze the y position?
or if you want to literally "leave everything else alone:
rb.constraints = rb.constraints | RigidbodyConstraints.FreezePositionY;
rb.constraints = rb.constraints & ~RigidbodyConstraints.FreezePositionY;```
alright thank you so much
not sure why death animation for boss doesnt play, i use th same enemy health script for both enemy and boss, the animation for death does play for enemy but doesnt for boss
do they have the same animator controller?
Hi! I am in a bit of a major bit of confusion right now, so I am asking for help in this forum.
I am doing a study using unity, so my game is basically a big questionaire. I plan to collect information into a class and simply send it as a .json string to my server. Problem is the communication with the class. This class has to be non-static, sure, but the object of the user should be available to multiple scripts and receive information from multiple additively loaded scenes. I am at a loss on how to organise such a thing, whether i should use events or anything else to facilitate communication between multiple additively loadedd scenes. If anybody of you did something similar, please let me know of your solution!
P.S: I tried simplifying the issue, but it would be very unwelcome to move to a single scene, as I am loading different parts of study logic as different scenes (i.e half of people get one test and half of people get another.)
Here is my current(not working) solution
You need to pass an instance of UserData into ToJson
not the class itself
Also your data should not be static variables
they need to be nonstatic
Yeah, i get that, but i cannot make an object of the userData class that is accessible from all the different scripts that need to get to UserData
Why not?
You either make a singleton that holds an instance, or use a static field to hold the instance
either way you need an actual instance
you'll need to be able to create an instance of UserData when you deserialize
so having all of the data in static fields doesn't work
and actual nonstatic variables inside it
Ig a singleton should work. I am trying to shoehorn singleton logic with a static class
e.g.
public static UserData CurrentGameData = new();
void SetSomeData() {
CurrentgameData.sceneType = 4;
}```
stop using static classes
that's not what you want
and it won't work with serialization
you'll replace every instance of UserData.foo with SomeoneWithTheData.data.foo
And what if some data that I need for the userData class lies in other scenes? Do I do a [DoNotDestroyOnLoad] even though all my scenes are loaded additively?
Everyone will have access to the static field that holds the UserData instance
things will work almost identically to how they do right now
So basically instead of having a static class I'll have a static object of said class?
Can i ask a stupid question?
What is the difference between a static object of said class and a static field that holds an instance of that class?
static reference to an instance of the class
there is no such thing as a "static object"
it's not a "static object"
the reference variable is static
The static modifier on a class doesn't really do anything
the objects instance is completely normal
It just makes the compiler throw an error if your class has any non-static members
I guess it also stops you from constructing an instance of the class
But it doesn't enable anything new
Well, there's GameObjects marked static in the inspector 
static effectively means it is a part of the class definition. it does not belong to any “thing” because there is no thing to own it
😭
don’t confuse the man
Yes ignore me I'm just being a pedant these concepts have nothing to do with each other they just share a name
so basically unity "static" is just a marker interface?
static means it belongs to the class, not any instances
god damnit now you confused him
You can sort of think of it as "belonging" the script file on disk, if that helps
or maybe I've been confused instead 😭
C# static means it belongs to the class definition
awesome
You currently have a class with static members in it. This means that each of those members is part of the class, not a specific instance of the class.
The member is on the class, not the object.
there's only one file, there's only one thing with static fields and functions
How do I fix this error? I have it install but it says I don't
You are going to make the members non-static. This means that the members exist on instances of the class, not on the class itself.
if I make a class called circle, and define static float Pi, then Pi is now a member of the class. It belongs to the class and not any one circle
You are then going to make a static field that holds an instance of UserData.
Basically I need a singleton. Whether it means making a static class or a static reference to an instance of a class (correct me if i said something wrong) doesn't matter
belongs to class not instances
Now you can statically access the instance and read and write its fields.
that is literally what I said
You can also serialize this instance to JSON. Then, you can turn that JSON back into an instance, and store the instance in the static field.
thought you were asking a question mb
if you make a singleton, which is a class with a static reference to one instance (that forces there to only be one instance), then the definition of your class contains a reference to the one instance
the current question
yeah, this is exactly what I wanted with the static class
a static class is one that cannot have instances, btw
static class means everythjng in it is static
When i have a public static class i can just assign variables directly from other scripts of mine
Sorry
sorry i did not see this , no tey have two sepearet ones
static variables are super dangerous because it is tied to the definition of the class. Anything can fuck with it, it is very hard to debug because it is hard to trace
yes you should use them, but only with great care
if you need to get a reference to an instance from various scripts, then you are probably looking for either a Singleton pattern, Service Locator pattern, an initialization method that gives your script the ref it needs when instanced, or a serialized reference
Singleton => class has exactly one instance => direct reference to it
a static field that you write data to when saving sounds perfectly fine to me
Service Locator => like a telephone operator, instance A asks the service locator for something, and the service locator gets it a reference to instance B
i just need to make sure he doesn’t abuse static variables, because that is an easy way to get into very deep shit
I usually do this by giving the relevant components a "Save" method. The Save method is given an instance of your SaveData class, and the component writes data to the object.
You can either explicitly call the Save methods on the relevant components, or you can have the components subsribe to an "on save" event that you invoke when you want to save the game
From my understanding, since i just need to put all of my data into a single instance, and each script corresponds to certain fields/variables that will be assigned as the script does its job. The instance is then converted to .json and sent over. From my understanding I can just get away with a singleton pattern? Pls correct me if i am wrong
public class GameController : MonoBehaviour {
public static event System.Action<SaveData> OnSave;
public void TriggerSave() {
SaveData data = new();
OnSave?.Invoke(data);
// write the data to disk
}
}
The latter would look something like this.
static classes are usually like toolboxes of functions to use. like System.Math and UnityEngine.Mathf
notably, those static classes also generally don't have any state in them
they aren't remembering stuff from function call to function call
That's what can make static members dangerous, IMO
If calling SomeStaticClass.Whatever() changes what the method does the next time you call it, then anything in your game can indirectly interact with anything else in your game
the state lives for as long as your game does, too
(that's part of why static members are so useful, of course)
you can shove data in a static field before a scene transition and read it later
you can completely blow up every single object in your game and reload the title screen and that data will still exist
alright
Well, I'll check out what the singleton pattern looks like and how to figure out this logic. I'll write on my success/failure
just get a Singleton implementation
UnityEditor.BuildPlayerWindow+BuildMethodException: 4 errors
at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x002da] in <06837d428b6d46f581d93f9597703696>:0
at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00080] in <06837d428b6d46f581d93f9597703696>:0
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
pls help guys
Look for the actual errors, not the error that tells you how many errors you have
Using this singleton looks like
public class MyClass : Singleton<MyClass> {
protected override void Awake() {
DontDestroy = false; // Or true, if you need don't destroy on load.
base.Awake();
}
}```
Omg thank you so much
guys need help here
Honestly I wouldn't trust myself with base.Awake() because while i am ok at OOP, I am not good at unity documentation at all. I found a pattern like this that should work. What do you think?
It seems you have a console error? Send a screenshot, what you sent is not very usefull
you don't need thread safety for Unity singletons
Also this will only work for non-monobehaviours
seems like a general purpose C# singleton, not a unity singleton
Wait, you are using java?Can you even so that with Unity?
idk whats happening
i used cs
Why would this only work for a non-monobehavior? If you have an article that is similar, that would be great too:)
you can't create MonoBehaviours with new
Is unities gravity meant to feel floaty?
no
guys its my android game pls help i have to realease it rn
tbh i coded in c# for a couple years, and only recently actually properly learned OOP in college, so it is like relearning the language all over again
It definately feels like it has no acceleration when falling
either a code problem or a perspective/scale problem
show your code
Im jsut using rigidbodies atm, sure thing
this isn't helpful, generally you look at code errors from top to bottom since those are the first errors that fail the build
got it, thanks. So a MonoBehaviour is similar to a static class in what it does?
not even close to a static class, no
ok
public class movement : MonoBehaviour
{
public float speed = 300f;
public float jumpForce = 1000f;
private bool _jump;
Vector2 move;
Rigidbody2D rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
if(_jump){rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);_jump = false;}
rb.velocity = new Vector2(move.x * speed, rb.velocity.y);
}
// Update is called once per frame
void Update()
{
_jump |= Input.GetKeyDown(KeyCode.Space);
move = new Vector2(Input.GetAxisRaw("Horizontal"), 0);
}
}
MonoBehaviours are C# classes that represent Unity components attached to GameObjects
Every frame you're doing this:
move = new Vector2(Input.GetAxisRaw("Horizontal"), 0);
setting y velocity to 0
no wonder you fall slowly
Ahh. that makes sense, should I set it to rb.velocity.y?
Like... don't know much about this... But seems that it is telling you that you don't have a reference to java.java?
guys anyother soln?
yes or you can just do rb.velocityX = Input.GetAxisRaw("Horizontal"); if you're on Unity 2023+
Ohhh okay, sounds much more simply. thank you
@wintry quarry It looks like that when using .ToJson i can get away with a simple Serializable class. I haven't made a MonoBehaviour class even in my less complex builds and it worked
Yes isn't that what we have been talking about this whole time?
Oh sorry you were also the singleton person
exactly
This feels significationly better. thank you! Next up Im going to work out dampening on horizontal since my player just stops in mid air ahaha.
I mean, the singleton thing you were showing was pointless/overkill
all you needed was a static variable initialized with new
I still wouldn't personally do it that way but that's the simplest approach
How would you personally do it?
sealed class singleton is garbage
you want to be able to do the programming and logic once for singleton, make it as a generic, and then use it for different classes
A singleton MonoBehaviour which manages the saved data object
the class I linked has cases for the application quitting, cases for monobehaviour vs not, cases for dontdestroyonload vs not
and if you later want to make it thread safe, then you now need to update like 20 classes or whatever, instead of modifying the singleton class that everything derives from
Yeah, ig i'll have to make the app actually production safe
if you are too afraid to use a singleton because you are bad at documentation, then you need to get better at documentation.
Honestly I do not think I should care about thread safety? But it doesn't hurt
you can't be a programmer who sucks at documentation. you will drive yourself insane
Then i'll go get better at documentation
thread safety is irrelevant when you only access the singleton from Update/etc.
Unless you go out of your way in Unity, thread safety is not a concern.
unity's update loop is single-threaded
i'll not, thanks!
you have to explicitly try to wind up on another thread
that's why my singleton doesn't have thread safety in it. But if you later change your mind and need to add it in, it is easier to do if you just need to fix one class and not 69
and that applies to any modification
if there is something about the Singleton you don't like, you just change it, and it follows to every class derrived from it.
that's why I'm not a fan of manually implementing singleton behaviour into a class, unless you have a case where you need to derrive from a non-singleton-derrived class.
A bit of an unrelated question, but did you already have another hopeless programmer come and ask you stuff to need a GitHub folder with data structures?
yes
error
you are not the first. you won't be the last
that is good to hear
Early returns. Instead of
if(value != null){
}
``` do
```cs
if(value == null){
showerrror...
return
}
my laptop is in a bad conditon and ig its my last opeing my laptop and still i cant publush my game
😭😭😢😢😿😿🥹🥹
and yeah guys can anyone tell yes or now that wuld connecting my laptop throgh hdmi cable to my tv set top box work??
we had someone doing that exactly this morning lol
hello how would change the value of a bool parameter in animation stuff? in a script
unclear how this is a code question or even a unit question
all things arent questions sire.... these are emotions
xd, i forgot to replay to the right message. I was telling a extremely nested code what could be done, but I think that was a long time ago now
still thiss error?
you need two arguments for SetBool
hello again : D
nice
ngl i feel im learning rlly fast
I am very mcuh not remembering the maths to do drag..
I was thinking of using lerp
but it stops instantly, which could either be my code, or the way im using lerp aha
RaycastHit2D hit = VisualPhysics2D.Raycast(transform.position,-Vector2.up,groundedDistance, groundedLayer);
if(hit){
rb.velocityX = Input.GetAxisRaw("Horizontal") * speed;
}
else{
rb.velocityX = Mathf.Lerp(rb.velocity.x, 0, horDrag);
}
lerp looks wrong
What is horDrag?
Hopefully not a constant?
Not entirely sure what you mean by a constant, its just how much drag I want to use as a public variable
I mean an unchanging value
But yeah, sounds like it is the wrong thing
The third parameter is supposed to change from 0 to 1 for what you are attempting
Oh, no, do not multiply it by deltaTime
I would look into MoveTowards or SmoothDamp
SmoothDamp sounds like it might be more correct
this also looks suitable?
it explains it a bit.
The correct/easies would be doing elapsedTime / duration
as shown here https://unity.huh.how/lerp/coroutines
but yeah you probab can just use the ones that dont overshoot like movetowards
I havent really tackled coroutines here
the recommended one in the link you sent does give a nice effect, but I will try the other two out shortly.
there are two ways to use Lerp
One is to have a fixed start and end, and to vary t from 0 to 1
The other is to have a variable start and fixed end, and to pass a (roughly) constant value of t each time
The former gives you a linear movement from the start to the end.
The latter will give you something more like on that "wrong-lerp" page, where you start fast and end slow
I see
Both are valid, but the latter is easy to do wrongly
the intuitive "just do Time.deltaTime times a constant" idea is framerate-dependent
SmoothDamp is great if you want to move towards a target with some damping
i am using debug.drawline to visualize my velocity force when i start the game without moving the red line which represent the velocity is in this direction. Isnt it supposed to be 0 if we consider it a vector? (edited)
You want DrawRay.
DrawLine draws a line between two points
DrawRay draws a line starting at a point and extending in a direction
ok so ive got 2 questions soooooooo how would i make the player model point in the x direction of the mouse and how would i make my anims play when the player moves?
Vector2 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
var dir = (mouseWorldPos - (Vector2)transform.position).normalized;
transform.right = dir;```
tysm
just an example, this would also include the y though.
i just dont want the player looking all weird
idk what that means
ok so
the reason i want the player character only on the x is bc i dont want the model slanted or smth like that
at an angle
so you only want a flip based on mouse pos? not aim towards mouse?
idrk
wdym ur the one making it lol what do you want to do
it would be nice to make it rotate from the hip actually
might try that
is there not a thingy called lookat?
couldnt i do
new Vector3(Cursor.Lookat());?
what I sent will look at the cursor
should i put it in a new script?
it shoud be in update yes
it can but you have to 0 out the z manually
or just copy how I wrote it with the casting, up to you
I mispelled the first time 😛
check the edit
okeodke
its ScreenToWorldPoint
Game Maker, Source SDK, Unreal,Godot, Three.Js .. thats about it
lol what has happened
oh you're doing 3D?
ive used a bit of gamemaker, godot dont rlly wanna do unreal and roblox studio
yes sry shoul've specified
im quite fond of roblox studio
Okay yeah then totally different ballgame lol
lol
what kinda game are you making
Ohhhhh so its FPV
First Person View ?
if you want to rotate the player with the mouse You have to GetAxisRaw horizontal then plug that into the player Y rotation
is this not already rotating player ?
only the camera
once you rotate player on Y if camera is already as child it will rotate properly
is i put my character into camera it will rotate?
no your camera has to be child of player
then you can just rotate player on Y it will rotate cam on Y too
should i put cameraholder into player then?
yes
could anyone help me with creating a ring of light around my player? its a 2D, top down project, i want the world to be completely black outside of the ring of light, i feel like ive looked all over for something similar but i cant find a thing. im reading that using Universal RP is the way forward but i've never used this type of lighting system before so im pretty lost
okedoke
unity2DURP has built in 2D light, you can use that
@rich adder is that a seperate package or is it included in Universal RP?
it should be part of URP
ah right, ill have a look. thank you
yes you have to reference the correct transforms though
put script on player and change the fields to be Transform and do one for player and one for camera
Transform player
player.rotation = Quaternion.Euler(0, yRotation, 0);
got it working
i just put it into camera and did what u said
ty ty u r the goat
actually one more thing
how would i make the player model not phase through the camera
near clip maybe, show what you mean
yea you'd have to lower then camera Near from 0.3 to something lower, under Clipping Plane
what would u say to?
you have to keep lowering until it works for you , I dont have an exact number lol
okedoke ill try it
lowering it?
u sure
its better when i make it higher
nvm
nothing rlly seems to work
no matter what i o
do
ahh
wait
it doesnt seem to work
idk what any of this means?
so whats not working?
it keeps clipping
If the camera is stuck into your body, you're going to get clipping
ohh you dont want that?
wait they are mis-synced
did you leave the rotation on the camera Y too ?
yeah that is hella wrong
isnt it like !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.
yes use the proper format
alright no problem
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
public float sensX;
public float sensY;
public Transform orientation;
public Transform player;
public Transform camera;
float xRotation;
float yRotation;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
// Update is called once per frame
void Update()
{
float mouseX = Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensX;
float mouseY = Input.GetAxisRaw("Mouse Y") * Time.deltaTime * sensY;
yRotation += mouseX;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
orientation.rotation = Quaternion.Euler(0, yRotation, 0);
player.rotation = Quaternion.Euler(0, yRotation, 0);
}
}
something like cs camera.localRotation = Quaternion.Euler(xRotation, 0, 0); player.rotation = Quaternion.Euler(0, yRotation, 0);
alright
or you might need += for camera with eulerAngles
why do you have so many
🤷♂️
get rid of the first two lines as those dont make sense
the last two are more explicit on whos what
without transform i ant move left anr right
rotation should not affect movement..
are you sure you only removed the first two
did you assign the new two fields ?
If your rotation affects movement, your model is not centered
ah yes, make sure pivots are correct with that too
Has this person actually shown the inspector of the script and the hierarchy window to show which object is which and what's assigned where?
good question , we should've probably did that first lol
@shadow rain show us the script and which object its on, with fields showing
!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.
Script: https://gdl.space/arevidahef.cs
Video: https://www.youtube.com/watch?v=k_pFMnqkgtw
Description: The issue, as seen in the video, is that when I start a world where I manually place enemies, they move along with the player and change position accordingly. However, when I try to spawn enemies in a different world using a spawner, intending for the enemies to fly towards the player's position, it happens that, as shown in the video, the enemies fly past and do not follow the player.
I want the enemies not to be behind the player but in front of the player, and as soon as one spawns, it should move towards the player and behave as shown at the beginning of the video.
I hope someone can help me 😦
Hello, I have some code that for some reason just won't work. The movement part of it is fine, it's just the part where it says stuff about colliding. When the bullet collides with an obstacle it doesn't destroy. I have box colliders on both of the objects (bullet and obstacle) with the bullet having "Is Trigger" turned on. Can anyone help?
The obstacle has the correct tag.
How are you assigning the player reference when you spawn the enemies?
OnTriggerEnter2D is spelled wrong, and therefore definitely not running
There is no way i did that lol. I triple checked everything 0.0
In the future use Debug.Log to make sure your code is running properly
What's that?
The first thing you should have learned when starting Unity
it prints a string to the console window
you should be using it to debug your code
Alright thank you
@ bob ``` private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Enemy"))
{
Destroy(other.gameObject);
Destroy(gameObject);
}
}```
try this
@void siren
What calls OnTriggerEnter2d?
there's no need to change anything really except fixing the misspelling of OnTriggerEnter2D
I got it working now but thanks
CompareTag would be slightly better though
ok
pretty sure it just checks if the trigger box collision thing has entered another box collision thing? i have no clue
@wintry quarry what do you mean?
I mean, you have a player reference that your script uses to follow the player. How are you assinging it when you spawn enemies in during the game?
if you're NOT assigning it, then naturally they won't know how to follow the player
Nah, that calls OnTriggerEnter2D. Not OnTriggerEnter2d.
OnTriggerEnter2d is a custom method you made.
OnTriggerEnter2D gets called by unity
oh mb im slow
asdjasdasj ds leave me allooinen
alr why do you have 3 fields + transform.rotation one in the script
so the script is on PlayerCam?
🤓 Uh, ☝️ bullying will NOT be tollerated!🤓
@wintry quarry i have puplic gameobject player and i have a prefab that i used?
send this again doesn't answer the original question
You need to assign the reference on the spawned enemies or they won't know which object to follow.
in code
thats not true sorry
Just a roundabout way to explain why the spelling matters. Functions only run when something specifically calls them. Unity obscures this fact sometimes by calling functions of specific names at specific times, and therefore it is vital to get the spelling right, since naming a function OnTriggerEnter2d and then calling it on your own is fully valid C# code, which is why it's not actually an error
then why does it work in the other world?
why are you spamming this screenshot
what do u want me to ssend?
Because you placed those objects manually in the scene and assigned the reference manually, in the scene, at edit time
that's not possible when you spawn a prefab
I asked which object is this script on and why now do you still have 3 fields + the transform.rotation
Yeah, I'm a bit uh y'know and I didn't see the spelling mistake after 15m of re-reading the same code.
it is on playercam
ok and how do I do that with a code?
private game object
findobejctwithtagplayer? or what
In the code that spawns the enemy
yes i know
not to worry Capitalization is something you need to get used to in c# is case-sensitive
pseudocode:
var newEnemy = Instantiate(enemyPrefab);
newEnemy.player = thePlayer;```
but what i must add
just... you know... actually assigning it
this assumes you are using the script type directly for your prefab, not GameObject
ok that answers only half the question, also it can just be on the root of the player since you now have the fields
ouu okey i try it i just see var the firstday
If you use GameObject (you shouldn't), you have to use GetComponent to get the script component then assign
var isn't the important bit here
If there was some plugin that did that thing thats like if you press tab it would finish the code, then it would be helful asf
it's just shorthand for GameObject or EnemyScript
unless there is and I havent found it
a configured IDE will do this automatically
what is the other half?
Im using visual studio and it does it for me on python but not this?
hi, I'm trying to create a TMP_InputField programmatically:
TMP_InputField inputField = inputFieldGameObject.AddComponent<TMP_InputField>();
// ... code that adds the text component and placeholder ...
inputField.caretColor = Color.white;
inputField.selectionColor = new Color(0.0f, 0.5f, 1.0f, 0.75f); // blue selection
inputField.caretWidth = 1;
inputField.interactable = true;
inputField.enabled = true;
I need to create it via script because this is a content mod for a game that I like a lot, so I don't have access to the unity engine interface.
the input field itself is showing correctly but the caret cursor is not appearing... the blue selection is also not appearing when I select the text or when I press CTRL + A.
I can send the full code if needed. can someone help me?
did you configure your VS?
For use with Unity?
uh, idk how.... im gonna look for a vid rq
There's a lot more to the default TMP Input Field template object than just adding the component
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
lol
ty
I can send the full code
I think I added everything
Have you created one in a scene and looked at it and all the child objects it has etc?
about the fields ?
Hi! I am just dropping in to thank you guys for your help a couple hours ago(I am the person that wanted to shove a static class into a method). The singleton pattern worked really well and I ended up with 3 singletons to manage my data better. Y'all are great!
this?
yes, look at the child objects it has and all the components they have etc
the text area, the text object itself, etc
ok, I'll check it
this is confusing
and notice how it has the viewport and text component assigned etc
"In unity, open up windows, packages" what
Yes, follow those instructions
where are you reading
so I need to make everything the same as in the editor by myself? no one has ever created a input field programmatically in unity? 😭
vs coe
PraetorBlue I apologize for saying your tip wouldn't work.
It works now thanks to you, thank you brother
@wintry quarry 
for me to use
are you on VS or VSCode?
code
Unity has prefabs so you don't need to do this
i thought they were the same till u sent the links mb
prefabs? like, code snippets?
just press the cloud button or Window -> Package Manager
I need to do it using code
I understand that. Doing it in code is going to be annoying
they are not, click VSCode one and make sure you do all the steps including installing.NET Sdk if it doesnt automatically, notice you need restart after that
might need to regen project files in External Tools after too
Unity has prefabs to avoid that annoyance, but you're not using them so it will be annoying
Honestly if you could use UI Toolkit it would probably be simpler
you could include the UXML and load it all from there
not sure if that's supported in whatever you're doing.
alright, Im clueless at what too send could u explain it a bit more?
Im terrible in unity
i already have that installed
@woeful smelt do you use chatgpt? or you make this alone
ok, continue following the instructions. that's just part 1
what do you mean?
Oh also VSCode's integration is really just not as good as VS
VS sucks
K, I'm just telling you
Visuall Studio is perfect for Unity
The Unity integration is much better
VS makes me want to cry when i use it
Does anyone have a Korean font asset for me please? Because I can't convert with Text mesh pro
is there a link for evertything
yes
wtf i dont unterstand why they make it so complicated
ok, i looked in the edit thing 30 times
Common theme you looking at something a lot and missing stuff 😉
Why, it is as simple as double clicking a file in unity then just editing the text.
Install unity and then in the module you can add Visual Studio which will be installed automatically and I have no idea why they make such a fuss out of it with strange links and websites
i code on other stuff too
not only unity
As do many people here
I used chatgpt, why? the code is outdated?
chatgpt may give terrible code that dont work
// ... code that adds the text component and placeholder ...
i see this lol ...
Don't try to use chatgpt for something like that, learn it yourself, there's no point in having an AI close everything then you won't learn anything
no, I added that comment
Which part are you talking about? The guide for configuring is very straight forward
so I don't have to send the full code here in the chat
to be fair VS for mac is pretty much gone so VSCode is the only option for us :\
but OP prob has windows so idk lol
I wrote that 😭
@woeful smelt Just don't use Chatgpt for that 🙂 You won't learn anything
you're making it look look like I just copied the chatgpt unfinished code and sent it here
wouldn't be the first, many people do that lol
I don't do it
Yes ... Fivem developer daily shit lol
Modding is not something we help with here, see #📖┃code-of-conduct
the game has an official modding api
Doesn't matter
then you should be asking for help in that game's modding community rather than here
then they should have their own discord for modding no?
but this is a unity related question
about creating a TMPInputField
Prohibited content and behavior
[...]
Discussing the modding or decompiling of third-party projects.
and the correct answer would be to create the input field using the editor. but you cannot do that. so go get help in the game's modding community
Even if they have an API and allowed modding, it's still not allowed to be discussed here.
I understand why they wrote that rule... so people won't mod games without consent
that isn't the only reason.
Hello. I have this code to make light disapear and then appear while holding button f to make light flickering
yield return new WaitForSeconds(0.45f);
ww.SetActive(!ww.activeSelf);
``` it works in editor, but not in build
code beginners is for beginners who develop games with the unity enginge and not modding for fivem or anything like that
in build it is very laggy
it's not fivem
dont send 3 lines of code expecting us to know whats going on
we need more context
this has nothing to do with holding any buttons. Share the full script
{
[SerializeField] GameObject ww;
[SerializeField] GameObject ee;
[SerializeField] AudioSource dzwiekswiatel;
[SerializeField] GameObject rr;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.F))
{
StartCoroutine(B());
StartCoroutine(C());
StartCoroutine(D());
}
if (Input.GetKeyDown(KeyCode.F))
{
dzwiekswiatel.Play();
}
if (Input.GetKeyUp(KeyCode.F))
{
dzwiekswiatel.Stop();
}
}
IEnumerator B()
{
ww.SetActive(!ww.activeSelf);
yield return new WaitForSeconds(0.45f);
ww.SetActive(!ww.activeSelf);
}
IEnumerator C()
{
ee.SetActive(!ee.activeSelf);
yield return new WaitForSeconds(0.45f);
ee.SetActive(!ee.activeSelf);
}
IEnumerator D()
{
rr.SetActive(!rr.activeSelf);
yield return new WaitForSeconds(0.45f);
rr.SetActive(!rr.activeSelf);
}
}
``` There are 3 lights
you're not doing anything to prevent multiple coroutines from running simultaneously
also making three different functions for three different lights is just wasteful
you could just put them in an array and use one function
Could you explain bit more? Sorry I'm new to unity hah
Update runs every frame
so every frame while the F button is pressed, you will be starting new coroutines
these will overlap with the other coroutines you already started
Add a debug to your coroutines at the start to see how many coroutines you are starting
and cause chaos
PraetorBlue had already helped me with everything I needed... but all of Just1n's messages made me feel bad... he keeps assuming things, like I just copied something from the chatgpt and came here, and also that I am programming mods for fivem? anyway, everything Just1n said to me felt like an attack and really didn't help in any way. Anyway, thank you for the help PraetorBlue. I'm leaving
So how I can make light flickering effect that make light disappear very fast? Make variable that block running another for 0.45f?
what is the effect you want to achieve?
very fast light flickering
When?
while the button is held?
or somethign else
and do you want randomness?
or something else?
I mean it not must be randomness just like it was it appears and then after 0.45 of secund it disapears and again again
and do you want all the lights to follow the same pattern, or no?
yes
and how does the F key relate to the behavior?
you're already doing it for the audio source - start a coroutine that flickers the lights on the frame the key is pressed down, and then stop it again when the key is released
it make them appear. They are on default not active then it make it active and then again disappear
ok but when you release the button then what?
And when you hold it should they continuously flicker on and off?
It's unclear
There is a dark corridor. After using button f light starts to flicking so you can see there
Since you're not being incredibly clear, my best guess is you want something like this:
[SerializeField] GameObject[] lights;
Coroutine flickerRoutine;
void Update() {
if (Input.GetKeyDown(KeyCode.F)) {
flickerRoutine = StartCoroutine(Flicker());
}
if (Input.GetKeyUp(KeyCode.F)) {
StopCoroutine(flickerRoutine);
}
}
IEnumerator Flicker() {
while(true) {
foreach (GameObject light in lights) {
light.SetActive(!light.activeSelf);
}
yield return new WaitForSeconds(0.45f);
}
}```
"f starts to flicking" is unclear. I press F once and it flickers forever? It only flickers while holding F? I press once and it flickers for some time and then stops?
until you release it. After releasing it it stops
the code they sent does that, try it
okey
why does it do that
you're setting your camera position to 0
or near 0
on the z axis
Part of the problem may be that you have offset set to zero on your script
yea it worked i changed the offset z axis to -1 and it now works fine
thanks for the help
Sometimes light stay turned on
using System.Collections.Generic;
using UnityEngine;
public class Mechanika2 : MonoBehaviour
{
int blokada = 1;
[SerializeField] GameObject ww;
[SerializeField] GameObject ee;
[SerializeField] AudioSource dzwiekswiatel;
[SerializeField] GameObject rr;
[SerializeField] GameObject[] lights;
Coroutine flickerRoutine;
// Start is called before the first frame update
void Start()
{
}
IEnumerator Flicker()
{
while (true)
{
foreach (GameObject light in lights)
{
light.SetActive(!light.activeSelf);
}
yield return new WaitForSeconds(0.05f);
}
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.F))
{
flickerRoutine = StartCoroutine(Flicker());
}
if (Input.GetKeyUp(KeyCode.F))
{
StopCoroutine(flickerRoutine);
}
if (Input.GetKeyDown(KeyCode.F))
{
dzwiekswiatel.Play();
}
if (Input.GetKeyUp(KeyCode.F))
{
dzwiekswiatel.Stop();
}
}```
which object is this script on
on empty gameobject
Is the object ever being deactivated or destroyed? Are you changing scenes?
no
that's the only way I could imagine this stopping. Or maybe you put another copy of the script on something elsewhere
it stays only sometimes
Search your hierarchy for t:Mechanika2
See if there's any other instances of this script in the scene
I would rather say, that you do not deactivate the light when stopping the coroutine
They may be currently active, so you'd need to deactivate them manually after stopping the coroutine
if (Input.GetKeyUp(KeyCode.F))
{
StopCoroutine(flickerRoutine);
foreach (GameObject light in lights)
{
light.SetActive(false);
}
}```
i.e. you're stopping the coroutine when it's waiting to deactivate the light
You also have double if statements checking the same thing, so merge them together (light flicking & sound play)
Ahh good point
how would i change this to make it spawn at a random y position rather than at the origin of the object
ah that was not so clear - yeah caesar has the answer
make a new V3 and randomize the Y value
Vector3 pos = transform.position;
pos.y = Random.Range(min, max);
Instantiate(Enemy, pos, Quaternion.identity);```
something like this
is there a way to change vairabled all at once instead of going each script one by one
in what context?
ty
for example i changed my variable heart to health and i wanna change it in the powerup script health script etc
thanks for help 🙂
wait so where would that go
Your IDE should have a Rename feature for the variable
oooo how do u use that
I mean, would've explained it no problem..
Usually right click the variable name and select Rename
ther may also be a hotkey
or Refactor -> Rename
would it change the variable in other scripts aswell
Yes that's the whole point
wa da hell
now the enemies are spawning but i cant se them
wait
1s
lol ty
yeah idk
All my code does is change where they spawn
anything else would be a problem elsewhere
theyre spawning outside of the box i put 0.0
How I can use variable from another script into other?
did you try googling it?
You're already doing that in your script
alr works
For example when you do dzwiekswiatel.Play(); you are accessing the Play() function from another script (The audio source)
ty for the 7th time today
You can do the same thing with your own variables and functions
even if that script is on different object?
yes
as long as you get a reference to it
dzwiekswiatel.Play() is from that script
praetor, do you live in this channel
I am getting odd behavior with number inputs. Out of all the numbers, pressing 1 is the only key that gets triggered. Sometimes even "1" doesn't get triggered, and I have to hit stop and hit play again for "1" to work once again. Can I get some help on this please?
The behavior is the same whether I use the numpad or the normal numbers on the keyboard.
Are you getting any errors in your console, even in other scripts?
I only have the one script running on this scene, but there are no errors showing.
Show the full !code for this script
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
I don't really know much about the new input system, but if '1' is the only one that works. could that be related to the fact that that's the only one you enable?
Ah.
Forgot to enable the rest...doh.
That doesn't explain why it only "sometimes" worked though, but I'm going to enable the rest right now and see what happens.
whys this grayed out
This is correct.
right in the center of my screen
yeah
The position of the canvas in the world doesn't really matter when it's in "Screen Space - Overlay" mode
what about it
i want it top left
The canvas is drawn directly onto your screen after the camera renders.
The canvas's position is completely irrelevant
0.0
press F with the canvas selected to focus the scene view camera on it and set it up as you desire
you can look at the game view to see how it's going to look in-game
Okay, the rest of the keys work. And I think the keys stopped randomly working because I was clicking into the console. Thank you for your help digiholic and simex.
ty
now theres this white line
and is this in the game view or the scene view?
game
do you have Gizmos turned on in the top right corner?
turn it off if you don't want to see gizmos
gizmos are used to visualize things like colliders
ah
stuff that would normally be non-visible
so if that were to be public no one would need gizmos
with it turjed on
dumb question nvm
i don't understand how the game itself could be "public"
how do i make my LineRenderer tile my texture?
Give it a material with tiling
You can start by uploading your !code to a bin
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
I assume that the ledge grab transition is true, while the 'any state' transition to the blend tree is true at the same time
can anyone familiar with Gorilla Tag help me?
If you're grabbing the ledge, you probably should have a bool that you're doing so, so it doesn't call it every fixed update.
without know what trigger/bools etc, the transition are bound to, helping with this is going to be hard
my texture isn't tiling, after a certain point it just begins to stretch
(linerenderer)
change your textures import settings *wrap mode to repeat instead of clamp
where do i find this menu
and the conditions from AnyState to jumpBlenTree?
in your textures import settings. select the texture asset in your project and then find the "Wrap Mode" settings in the inspector
@lusty flax
ok
So. currently my character "sometimes" (very very rarely) gets stuck of youre going at exactly the right speed when hitting the edge like this. it "should" be slipping off as it normally does but isnt. is there an equivalent to capsule collider for 2d?
just gonna replace the raycast with it
thank you! it worked!
there is your problem, as long as grounded is false, you can go from any possible state to the jumpblendtree. but that's also a condition from ledge grab, casuing a loop. AnyState to jumpBlenTree should maybe also have the condition canGrabLedge = false, or something to that effect.
you want CapsuleCollider2D component?
or Physics2D.CapsuleCast?
https://docs.unity3d.com/Manual/class-CapsuleCollider2D.html
https://docs.unity3d.com/ScriptReference/Physics2D.CapsuleCast.html
my hearts was like this but i changed the vairable fullhearts to filledheats now it dosent show when its filled
capsulecast, thank you!
Show some code :3
ok
!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.
!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 that?
it was working before
when it was fullhearts
but once i change the vairable it dosent
Show the inspector of this object
is the reference to the sprite still assigned? it probably got lost when you renamed the variable
yea Unity saves what values you have set in the inspector using the name of each variable. When a variable name is changed the original value is lost unless you add the [FormerlySerializedAs("fullhearts")] attribute
you need to reassign the reference after renaming the field
oops, i was scrolled back
Could I use Collider2D.cast for a similar outcome? It seems go?
I don't really know what you're trying to do or how you're trying to do it. Can you provide more context?
Actually dont worry, it doesnt seem to have a layermask argument
Ill just use circlecast ^^
thanks though!
how do I stretch a sprite in a LineRenderer? it works, but it's a bit squished which makes it look odd
are you tiling it via material or the line renderer's texture mode?
material
do you want it to tile based on the distance of the line, or stretch regardless of the line distance?
regardless of distance
(as in, it tiles the same but the image is 2x longer or smth)
I would like some opinons, Im starting work on a grappling hook mechanic and Im wandering if I should a. use a distance joint and set the target to click location, or b use a hinge joint and set a rigidbody at click location as the joint
just to be clear, do you want A or B
Option A
using Texture Scale?
yes haha set it to Tile and it tiles
yeah but i tried that before
the tiling thing works, but when I try to change the scale it just doesn't want to
First image has TextureScale.x = 1, and the second is TextureScale.x = 2
i just want it to stretch
Can you change the tiling in the material?
I can't change it
I don't know exactly why its disabled, but probably because it's a sprite shader. The line renderer is not a sprite renderer so you can just use a regular Unlit shader for your material
changing it to an unlit texture kinda broke it
It needs to be transparent since your texture has transparency
Also if the Texture Scale wasn't working before maybe it will now. The sprite shader might not have been playing nice with how the line renderer works. Texture Scale works for me with the Unlit shader
wait my texture is no longer being translucent like before
show me the material inspector
That shader has alpha clipping
Which means if the alpha of a pixel is above the "Alpha cutoff" value it will be fully opaque, otherwise it will be fully transparent
I can't see the full shader name but I'm guessing that's "Unlit/Transparent Cutout" when you want "Unlit/Transparent"
when I changed it to "unlit/transparent", it still doesn't become transparent (i think this is because i set the transparency through the "color" component of the LineRenderer)
Is linerenderer the best option to draw a line with texture between two points (a grappling hook for example)?
Or is there another method
linerenderer works
!cs
Join the C# Discord server, a programming server aimed at coders discussing everything related to C# (CSharp) and .NET. https://discord.com/invite/csharp
!blender
A supportive community for Blender artists of all levels. Share your work, ask for help, and learn from others! https://discord.com/invite/blender
@warped roost There's no need to test out the bot. It works.
i know. I just wanted too join the servers..
Why does OnEnable execute before Awake?
https://i.gyazo.com/a98184c7eda415793b00f514e57e25a1.png
Unity docs say that Awake should happen before OnEnable.
https://docs.unity3d.com/Manual/ExecutionOrder.html
Is there an order in which I should be executing my scripts?
Would this be a good way:
void StartGame()
{
InitializeObjects(); // creates instances of game systems like inventory system, player controller and their events.
UIManager.Init(); // loads all UI elements and set them to Active which should execute all OnEnable functions which will subscribe to events
LoadData(); // Load game data from save file if needed or just default starting data(like getting first character in the game)
}
Did you add any logs to see if this was truly the case? Maybe one object just isnt created yet unless these are both in scene
I found out the issue, apparently Awake and OnEnable are called in this order within their scripts.
So 1 script might call Awake + OnEnable while another only Awake.
It is generally a good idea to define some order like this if the order matters. Helps you pass around data too, for example if something needs data that only happens after LoadData() but LoadData relies on something else happening first.
I was just trying to use this:
private void OnEnable()
{
Game.Instance.areaManager.onAreaUnlock.AddListener(OnAreaUnlocked);
Game.Instance.areaManager.onAreaActivate.AddListener(OnAreaActivated);
}
private void OnDisable()
{
Game.Instance.areaManager.onAreaUnlock.RemoveListener(OnAreaUnlocked);
Game.Instance.areaManager.onAreaActivate.RemoveListener(OnAreaActivated);
}
It was recommended to me many times, but it seems like a bad idea, I might as well use Init function instead of relying on OnEnable
Or I have to load all ui + data in correct order to make sure they can subscribe to all events.
how can i add a ton of objects to a list quickly without having to tediously go through them all individually (i have over 50 sprites to add)
Select all, drag and drop
when i select, it exits the sprite atlas inspector screen
Lock it. There's a lock button at the top right. Also, this is not a coding question.
oh, yeah right
where should i have posted this (to post stuff like this there instead, next time?)
kk
(i was confused cause there's no im-stupid-and-don't-know-how-to-use-the-UI-help channel) 😅
how do i make my camera look speed the same when using a mouse and controller
because right now the mouse is way faster
Add a speed modifier parameter that is different based on wether it's mouse or a controller.
Add mouse sensitivity settings.
Note that this doesn't even make sense because you can move your mouse at any speed, they're not analogous control schemes
Also show your code
how does (vector2)transform.position differ from vector2.zero here?
Because I bet there's a bug in it
*first line of both methods
Your code is framerate dependent for controllers
those are the only 2 scripts that involve the camera
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
i recommend gdl.space personally
CircleCast doesn't make any sense with Vector2.zero there
You would just do OverlapCircle at that point
whats overlapcircle?
!docs