#💻┃code-beginner

1 messages · Page 522 of 1

lapis totem
#

I wanna get the HighScore from the game and save it into mysql database in which I have my users saved, then have a custom table print it out from the database in a different site on the same web in which the unity game will not be running

#

got it

rich adder
lapis totem
lapis totem
rich adder
#

so Get Highscore from MySql then into Unity then into JS to show on the page? why not directly from mysql onto the page?

rich adder
lapis totem
lapis totem
#

just the one in the Hello function

rich adder
rocky canyon
#

if ur running it from the Editor how is it supposed to work?

lapis totem
rich adder
#

did you actually build to webgl ?

rocky canyon
#

thats what i wanna know

lapis totem
rich adder
rocky canyon
#

and it doesn't work?

lapis totem
rich adder
#

ShowAlert(message);

lapis totem
lapis totem
rocky canyon
#

is it possibly an issue w/ the Javascript?

rich adder
#

did you actually put the javascript file?

lapis totem
#

    // Define the JavaScript function that Unity will call
    ShowAlert: function (message) {
        window.console.log(UTF8ToString(message));
        }
};

mergeInto(LibraryManager.library, functions);``` this is in JSLIB.jslib that is in assets
rich adder
#

hmm that looks diff from the page are you sure thats meant to be on the bottom?

#
mergeInto(LibraryManager.library, {

  Hello: function () {
    window.alert("Hello, world!");
  },
});```
lapis totem
#

well, I can change it, but it should have the smae effect I think, give me a few minutes so it can build

rich adder
#

ohh okay i see you passed the variable as functions, i guess it would the same then

languid spire
#

this
UTF8ToString(message)
should probably be
Pointer_stringify(message)

lapis totem
lapis totem
rich adder
languid spire
#

well i'm just looking at my production jslib. also you're missing an autoAddDeps

languid spire
#
var functions = {

    // Define the JavaScript function that Unity will call
    ShowAlert: function (message) {
        window.console.log(UTF8ToString(message));
        }
};
autoAddDeps(functions, 'ShowAlert');
mergeInto(LibraryManager.library, functions);
rich adder
#

weird. no mention in the docs

languid spire
#

it exposes the ShowAlert function to the library manager

lapis totem
eternal falconBOT
#

🪲 To make bug reporting as quickly as possible, we made a bug reporting application for you. When running Unity choose Help->Report a Bug in the menu, or you can access it directly through the executable in the directory where Unity is installed. It will also launch automatically if you experience a crash.

📝 If your bug report is to do with Documentation, either an error, typo, or omission, you can report it by scrolling to the bottom of the page where you found the issue and click ‘Report a problem on this page’!

💡If your report is to do with a new feature idea, you can check the Unity Product Roadmaps page to see if your idea has already been planned.

For more complete instructions on how to report bugs, access: https://unity3d.com/unity/qa/bug-reporting

lapis totem
#

why?

#

is it a bug?

rich adder
#

nah

rocky canyon
#

no, they just being lazy

lapis totem
#

welp

silver mauve
#

sorry what

#

lazy how

rocky canyon
#

lol, nothing wrong w/ it 😄

silver mauve
#

didn't expect it to post my command, i don't know exactly how discord works

#

if bots can eat commands and not post them

rocky canyon
#

what are u trying to do?

silver mauve
#

it gave me a response already

#

which i guess you didn't see

rocky canyon
#

ahh okay 👍

lapis totem
#

its acting dead like a mouse

rocky canyon
#

does the javascript have to be in the index?

rich adder
#

do you have any errors in browser console?

rocky canyon
#

never seen javascript being called via a unity script

rich adder
#

jslib afaik is already in the unity build
you can add additional JS scripts to interact with if you add them to the index.html

lapis totem
#

all I get are these warnings, but I get these even when I dont have the jslib and things in the game WebGL: INVALID_ENUM: getInternalformatParameter: invalid internalformat

rocky canyon
#

might have to give this a shot later

languid spire
lapis totem
rich adder
# lapis totem how?

wdym how, thats if you want additional JS interaction.
yours should work fine, you put a .jslib file in the plugins folder correct?

lapis totem
#

but it does not work...

languid spire
#

what does your c# side look like?

rich adder
#

public class InteropJSTest : MonoBehaviour
{
    [DllImport("__Internal")]
    private static extern void Hello();
    void Start()
    {
        Hello();
    }
}
lapis totem
#

huh...

rich adder
#
mergeInto(LibraryManager.library, {

  Hello: function () {
    window.alert("Hello, world!");
  },
}
)```
rich adder
lapis totem
#

apache server on xampp

rich adder
#

which compression method did you use btw

lapis totem
#

no compression since it is http

rich adder
#

ok good good

#

I tested it with VSCode LiveServer plugin but doubt thats much different than xampp

lapis totem
#

Im using unity 2021.3.37f1 if thats useful to know

rich adder
#

I'm on 2022 but I think its the same process

lapis totem
#

I just have no Idea why its not working

rich adder
# lapis totem I just have no Idea why its not working

something wonky going on here..
what i always do is try
A Blank Scene, 1 Script with only that function in Start or something. And just export that scene, see if thats working. This makes it so you dont have to worry about anything else

languid spire
#

@lapis totem This works

var Library = {
    Message : function(msg) {
        console.log(UTF8ToString(msg));
    }
}
autoAddDeps(Library, 'Message');
mergeInto(LibraryManager.library, Library);

using UnityEngine;
using System.Runtime.InteropServices;

public class JSTest : MonoBehaviour
{
    [DllImport("__Internal")]
    private static extern void Message(string message);


    void Start()
    {
        Message("Hello World");
    }
}
lapis totem
#

I built it with just the test scene selected but its still showing the samplescene

rich adder
#

are you sure you made a new build 😅

lapis totem
#

yes

#

I DELETED the old one and Built a new one in the same folder

rich adder
#

make it in a brand new folder then lol

lapis totem
# rich adder make it in a brand new folder then lol

OK..... I HATE UNITY now... 5 hours of tinkering just because it defaulted the build into an older version of the web HALF WAY THROUGH! I build at least two builds in the latest web directory, but unity decided to afterwards just build it into the old web directory, which had just a single number name difference compared to the new one. I AM DONE, thank you very very much for your help. I appretiate it a lot, time to sleep since its almost half past midnight now. Have a nice day.

lapis totem
rich adder
lapis totem
#

well, I have my project in a directory where I have multiple versions of it, essentially titled project_1, project_2 etc. In those I have a Games folder in which I was making the builds, I made at least two builds in project_4, but after that it seems that it was putting the builds in the Games folder of project_3 instead, and since it is just a single number difference I did not notice

lone sable
#

Everytime I start my application in editor right now, I get about a 4,000 MS EditorLoop lag spike. This appears to only happen in editor and not on build. Is there any way to debug this to find out exactly whats causing it?

rich adder
#

turn on deep profile

#

4k ms is insane

lone sable
#

DeepProfile is enabled.

rich adder
#

oh yeah seems like editor loop doesnt have hierarchy, I must've misremembered

lone sable
#

Hmm. Was able to track it down, partially. Seems like its due to some OnValidates that I'm using in Scriptable Objects.

rich adder
#

ok that makes more sense

#

how heavy are those operations ?

north kiln
#

OnValidate strikes again

rich adder
#

I even avoid putting heavy stuff in Start and Awake because it has the same effects for builds

lone sable
#

Heavy enough apparently. Guess I'll need to work on an alternative.

#

That or just manually add things.

rich adder
#

isn't Reset better ? or do you need specifically after field chages /event

lone sable
#

Honestly, I just need it on Creation of the asset.

#

Preferably though, when its being duplicated as well.

rich adder
#

iirc there are other hooks/events for those that might work better ? its been a while since I touch unity editor coding

lone sable
#

AssetModificationProcessor is one of them. I was just hoping to keep it simple.

#

Looks like OnEnable doesn't work either in this case. 😦 Guess I'll take the long root or just do it manually.

#

The Awake call seems to work/do what I want it to do, so, theres my solution I suppose.

opaque pecan
#

I have a few virtual cinemachine cameras in my scene. How can I hide the white orientation lines in the Scene view?

#

Oh! nevermind, i figured it out

main karma
#
  Vector3 newRight = Vector3.Cross(newCameraDirection, Vector3.down);
  Vector3 newUp = Vector3.Cross(newCameraDirection, newRight);
  cam.transform.rotation = Quaternion.LookRotation(newCameraDirection, newUp);

this ended up solving my issue, I should stop skipping math classes

olive galleon
#

Should I add events in interfaces? For example I'm trying to add a Die event, so should I make a IKillable script that objects can inherit?

rich adder
#

they are implemented

#

big difference

#

and sure as long as the event is a Property should be fine

olive galleon
olive galleon
rich adder
#

eg
Cat -> Animal
cat is an animal but cannot be anything else unless Animal inherits something else

#

if you do implementation
like Cat , IEat, ISleep, IPoo, etc.
You can have many classes with the same implementations, without them having any other relation besides having those common implementations

opal zealot
#

My bad.

olive galleon
opal zealot
#

Is it possible for me to use public class PlayaCharacterNormalLocomotionInput : MonoBehaviour, IPlayaHumanCharacterLocomotionMapActions without the need of PlayaControls?

cosmic dagger
opal zealot
opal zealot
restive ore
#

Anyone would volunteer to teach me how to make a fade screen after the button is pressed?

#

I'm new to Unity and just learned a few stuff today

rich adder
fading barn
#

How can i change unity's volume settings through monobehaviour code?

cosmic dagger
toxic frigate
#

hello, does anyone know why this isnt working?

Vector3 transformAmount = -moveDirection * movementSpeed * Time.deltaTime;
            obj.transform.Translate(transformAmount);

            var trackIcon = obj.transform.GetComponent<campaign_friendlyTrackIcon>();
            if (trackIcon != null)
            {
                trackIcon.destination -= transformAmount;
                RectTransform movementLineRect = trackIcon.movementLine.GetComponent<RectTransform>();
                RectTransform timeAndSpeedRect = trackIcon.timeAndSpeed.GetComponent<RectTransform>();

                timeAndSpeedRect.anchoredPosition = new Vector2(movementLineRect.anchoredPosition.x + 60, movementLineRect.anchoredPosition.y);
            }

transform.translate is moving it a different amount than manually addiing it to a vector3 does, how come?

#

ive been struggling at this for a bit

ivory bobcat
fading barn
#

Any good resources you guys know of to learn physics and mathematics specifically for game developement and computer graphics?

tall ingot
#

For computer graphics, there is little difference in that math vs. standard math. Just learn about vector spaces and how they are represented

cosmic dagger
tall ingot
#

For computing (and graphics) discrete mathematics, vector and matrix spaces, set and collection theory and core algebraic principles are key. For physics simulation you need an understanding of calculus and geometric funtions.

cosmic dagger
#

though you don't need to know physics. just use the physics engine: colliders, physics methods, etc., from unity . . .

tall ingot
#

It IS useful knowledge in general though...

eternal needle
#

most can be solved using first year math. especially since most operations needed are already built in by unity

eternal needle
# fading barn Any good resources you guys know of to learn physics and mathematics specificall...

there isnt gonna be an all encompassing answer here. computer graphics is already widely different from "basic math required for game dev". Also the level of math we're talking here matters a lot.
Basic math imo would just be stuff like vector math (adding/subtracting, dot product, normalizing). This stuff you can really just look at the first results on google, khan academy was always pretty good. While itd be good for you to know how to calculate these things, unity already implements it.
If you're looking for advanced physics or math, this would imply you're making something pretty niche. Either look for devlogs of people doing the same, or hit the books/papers on the real math to understand it properly.

fading barn
foggy tundra
#

can I copy things from one scene to another?

#

and after creating new scene how do I access to old scene?

topaz rain
#

Hi there.
I changed from VS 2017 to VS 2022
I have this minor problem, whenever i create a new script, intelissense stops working and i need to close VS and open it again to make it work again.

As I say, its a minor thing, but is there a known fix for it?

cosmic dagger
foggy tundra
#

how do I make button to load other scene?

#

why this doesn't work?

cosmic dagger
#

for that, you can easily google how to load a scene. there are tons of answers . . .

burnt vapor
foggy tundra
#

I made button

burnt vapor
#

I would assume that the method you try to access contains parameters

#

Share the button, share your !code

eternal falconBOT
burnt vapor
#

Until then, we don't know

foggy tundra
#

chatgpt said I can make it without code

burnt vapor
#

Your mistake is relying on ChatGPT for this

foggy tundra
#

using unity ui

burnt vapor
#

So what do you expect? You need a method to call on click

#

What are you calling?

foggy tundra
#

I'm trying to call another scene I guess?

burnt vapor
#

What does "call another scene" even mean?

foggy tundra
#

I'm making menu button that loads scene with game

burnt vapor
#

So how do you load this scene?

foggy tundra
#

I'm struggling to understand why it has to be so complex

burnt vapor
#

You need code for that

opaque schooner
#

@foggy tundra
This is how mine looks, I added a gameObject with my script attached

foggy tundra
#

I use godot and it does involve one line of code

burnt vapor
#

It's not complex. Your issue is that you are relying on ChatGPT instead of just learning how to do it

#

Also, loading a scene can be much more complex depending on your needs. It's a process requiring code, like anything else in a game

eternal needle
foggy tundra
#

I couldn't find simple tutorial, sorry

burnt vapor
#

I suggest you google how to load another scene, and take a look at hundred examples that do exactly this

#

You're not the first person that wants this

#

Once you have something and it still doesn't work, feel free to come back

#

And please get rid of ChatGPT ASAP until you have a grasp of how to do at least basic Unity

topaz rain
# foggy tundra I couldn't find simple tutorial, sorry

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class SceneLoader : MonoBehaviour
{
public void LoadScene()
{
SceneManager.LoadScene("Level2");
}
}

If you found this video helpful I would really appreciate a small tip so I can improve my video quality...

▶ Play video
#

just typed load scene button in youtube plz xdd

burnt vapor
#

This question generally just feels very lazy, I doubt they tried

opaque schooner
#

Its probably possible to do it through a Graph without code

foggy tundra
#

I did as in video and mine has no functions as in video

topaz rain
#

is the function public?

foggy tundra
#

I don't know

topaz rain
#

show the code plz

#

just make a screen shot

foggy tundra
#

copied from video

eternal needle
#

Seems you dragged in the script asset and not the instance

#

Also !ide

eternal falconBOT
teal viper
#

Watch the video again and pay attention to what they do in the inspector.

foggy tundra
#

no, I dropped wrong object

#

it has menu now

#

let's see if it works

#

ok I can't load that scene because it's mpt added to build settings, but when I go to build settings and lick Add Open Scenes, nothing happens

topaz rain
#

drag the scene from the project files to scenes in build

topaz rain
#

instead using the add open scenes

foggy tundra
#

ok it works

topaz rain
#

i've ended up loving this thread xd i'm on the edge of my chair rn

foggy tundra
#

thank you

topaz rain
foggy tundra
#

sorry to be annoying I just been working with godot for few years and unity is very confusing for me

burnt vapor
#

Please prioritize configuring your editor as Bawsi mentioned

quaint thicket
#

I'm trying to set a GameObjects MeshRenderer material to use a material I made, but it can't find/load it. Any suggestions?

headModel.GetComponent<MeshRenderer>().material = Resources.Load<Material>("Assets/Transparent.mat");
opaque schooner
#

Are one of the folders names Resource?

quaint thicket
#

No. I tried putting it in the folder called Resources, but I guess I need to use just Resource.

#

brb

opaque schooner
#

Resources should be correct i think

quaint thicket
#

Nope. Still not working.

north kiln
opaque schooner
#

try changing to "Assets/Transparent"

quaint thicket
#

Thank you guys.

runic sentinel
#

if I understood correctly, the code outside the "start" and "update" functions does not execute without being called (like in the csharp console without unity) but in this case why can I initialize my variables outside.

#

I'm very new to unity

steep rose
#

so you have the start function nested so it will not do anything

shrewd swift
#

not sure if your print("hello"); will be compiled

steep rose
#

put it outside the print function and put the print function inside of it

shrewd swift
#

looks like an error

shrewd swift
#

he just indented it

#

Start is member of printing

burnt vapor
eternal falconBOT
burnt vapor
#

Once this is done your editor will inform you that print() is not allowed on class scope

shrewd swift
burnt vapor
#

Then I suggest they either switch to Visual Studio or Rider

steep rose
shrewd swift
#

yeah it looks pretty much the same

burnt vapor
#

I'll assume they definitely have not correctly configured their editor, especially considering the inconsistent casing in the class name will make Unity ignore this class altogether

opaque schooner
#
public class printing : MonoBehaviour
{
   int number = 12;
   // Cant place functions here

   void Start()
   {
      Debug.Log(number);
      Debug.Log("hello2");
   }
}
#

Try formatting your code with indentations like this, makes it easier to read

shrewd swift
#

Printing

runic sentinel
shrewd swift
#

code runs only in functions

#

so typing anything thats not declarations outside of functions makes no sense and wont compile

opaque schooner
#

I dont know any other answer than its designed that way.

#

Just assign stuff there

burnt vapor
#

Your code must be contained in methods, or in initializers

#

I suggest you learn basic C# first before delving into Unity

runic sentinel
#

So, there is a Main function inside of Start or Update function ?

burnt vapor
#

You're trying to learn C# alongside learning Unity

hasty dragon
#

hello

burnt vapor
#

Unity is vastly different in how C# works and you're going to have a hard time if you try to do them both at once

hasty dragon
#

whats the difference between this.transform and just saying transform

runic sentinel
burnt vapor
#

So I suggest you close Unity and make a basic console application at the very least

burnt vapor
#

this just ensures that you point to the class when you get something

hasty dragon
#

oh ok

burnt vapor
#

The only reason for this is when you are bad at naming things and you want to make sure you don't grab a local variable, or something

hasty dragon
burnt vapor
#

If you make a new variable tranform, then that replaces the old one

#

Your compiler will inform you of this

#

You can get the old transform through base.transform, or just don't name variables that already exist

#

If you truly intend on replacing it, then you should use the new keyword with it.

#

However, the proper way is to have virtual variables, and to override them assuming the signature is the same

hasty dragon
#

i understand

tulip holly
#

is it possible to give each npc worker in a game there own inventory so they can go out collect resources and then return with them.

ivory bobcat
#

Yes

tulip holly
#

do you just add a inventory scriptable object to a prefab for the npc ?

polar acorn
#

That depends entirely on how you define "worker", "inventory" and "resource"

tulip holly
#

well i want to have workers i can send off to collects ore, woods, hides etc that you can use for crafting. what im looking to do is give them a specific amount of storage space to go fill up and return with what they got.

#

for example i want the player to be able to hire a miner to send off to collect iron ore or some other kind or resource you would get from mining

polar acorn
#

And what have you done in code to define any of this so far

tulip holly
#

Nothing just trying to figure out how to do this. All i find online is simple player inventory systems with a ui interface but nothing to do with what im trying to do. At the moment all i have is some scriptable objects for some resources and items to craft, a recipe SO and one for a worker with item slots so you can give it gear to boost its capabilities

#

Im trying to setup inventories now so i can work on a crafting system to pull stuff from base inventory to craft with

polar acorn
#

If you have a component that defines a worker, and a script that defines a resource, all you really need is a list of resources on that worker component

tulip holly
#

So just have that with a max capacity variable then so they only pick up what they can put in there im guessing

polar acorn
#

Whatever you need it to do. You aren't going to find a tutorial that does exactly the thing you need it to do, so you're going to have to design your own system that suits your specific needs

tulip holly
#

Yea i figured i would, was just unsure how to go about it

#

Will figure it out sooner or later

gentle fog
#

Guys
How do I refer to a script attached to a game object?

faint agate
#

Hello, im trying to get the distance of my player and a gameobject with a boxcollider. When I use Vector3.Distance(), it tracks the center of the object and not the whole. any tips?

slender nymph
#

Vector3.Distance doesn't "track" anything, it just calculates the distance between the two vectors you supply to it. but it sounds like you're just giving the transform.position of each object when you want a point on the collider face?

polar acorn
polar acorn
# faint agate appreciate it

If you need the edge-to-edge distance, one thing you could do is raycast from the player to the collider, then raycast back from the contact point, back towards the player. Then that distance would get you the closest approach distance from edge to edge

#

(Assuming neither of these are simple shapes like boxes or spheres where you could use bounds.width or radius)

tired bluff
#

Hi everybody. I faced such a problem that the sprite of the weapon does not want to rotate with all the added scripts and is in the same position, despite the fact that in another similar project, where everything is done the same way, the weapon rotates without any problems. What could be the reason?
Errors in the console are also not highlighted in this regard.

wintry quarry
wintry quarry
#

but it seems to me depending on the execution order, only one of those two scripts is going to work at a time

#

assuming they're both on the same object

#

they are both trying to modify the rotation of the same object

tired bluff
cosmic quail
tired bluff
#

Or I don't see something where there is an error. But I've already rechecked the scripts 10 times.\

cosmic quail
cosmic quail
tired bluff
frank pelican
#

Hey, we are in a group of 8 devs, all first time unity.
We are discusting whether or not the monobehavior scripts that we create should end with Script
So PlayerMovement or PlayerMovementScript
What is most commen / code convention

polar acorn
#

I don't think it's necessary. It's more likely that you'd want to have prefix/suffixes for other things, like Interfaces leading with I

#

Probably a bulk of your C# files in a Unity project will be MonoBehaviours, especially if you're using composition extensively.

wintry quarry
#

That's like calling things xxxClass

polar acorn
#

If anything, appending Behaviour or Component makes more sense, but it's still unnecessary

wintry quarry
steep rose
keen dew
#

PlayerScript pVariable; // comment: variable of type PlayerScript

polar acorn
steep rose
#

thats horrifying

#

I usually just do _Playerscript,player, movement, etc (I believe) as the variable name, its probably not the best way to do it but I have zero clue 😁

viscid anvil
#

Hello everyone, I have created a little main menu in that I can hover over START, SETTINGS and QUIT and it will go from transparent black to yellow when I hover over it. When I click settings and then my BACK button, then hover over START and QUIT again it no longer has the animation, does anyone know why?

polar acorn
#

Is there an event system in the scene?

viscid anvil
#

Yes there is

polar acorn
#

Is it still there after the buttons stop being responsive?

barren scaffold
#

Why do I get this
Shader error in 'Shader Graphs/Master': Couldn't open include file 'Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/Lighting.hlsl'. at Assets/CustomLighting.hlsl(10)
When the written line is this, pointing to the folder which contains lighting. I dont even see a lighting file in "ShaderLibrary"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl"

viscid anvil
polar acorn
viscid anvil
#

I keep receiving a warning message of "There are 2 audio listeners in the scene. Please ensure there is always exactly one audio listener in the scene." if this is a problem

viscid anvil
wintry quarry
#

Your buttons are probably blocked by some invisible ui element or something

viscid anvil
#

okay i will try now

wintry quarry
#

or possibly you made them uninteractable while the other menu was open

#

and forgot to reverse that

queen adder
#
    private void OnMouseDown() {
        mouseDifference = (Vector2)Camera.main.ScreenToWorldPoint(Input.mousePosition) - (Vector2)transform.position; 
    }

    private void OnMouseDrag() {
        transform.position = (Vector2)Camera.main.ScreenToWorldPoint(Input.mousePosition) - mouseDifference; 
    }

    private void OnTriggerEnter2D(Collider2D other) {
        if (other.gameObject.layer == 3) {
            CheckoutScript.checkoutValue += value;
            Debug.Log("Checkout detected");
        }
        
    }

I want to create a really simple Game, where the player pick up coins and drag them to the checkout filed. The Coin is a Collider2d set to trigger. The checkout is rigidboy and collider2d. Is there a fault in my code, with the mousedrag? When trying the trigger doesen't trigger. But the coin is moveable. This is the Code Script

burnt vapor
#

But honestly I dont think this should be done. Just call them controllers, managers, stuff like that

queen adder
rich adder
#

I cant see the components, why are they cropped

queen adder
rocky canyon
#

idk.

  1. every screenshot should be full window
  2. save your scene as something other than 'SampleScene'
frank pelican
#

Thanks everyone for responding !!
I will remove script from everything since i think there is 1 clear winner XD

rich adder
rocky canyon
queen adder
queen adder
rocky canyon
#

good 👍 just making sure

#

debugged ur OnMouseDown method?

rich adder
#

does static work with triggers?

rocky canyon
#

to see if its getting called?

rocky canyon
#

i wuld think it could cause probs

rich adder
#

seems it needs at least 1 dynamic or kinematic

queen adder
#

Yeah change it to dynamic and now is working

#

Thanks guys

ionic wing
#

hi all! I am having a little bit of trouble getting scene transitioning to work, my scene scripts don't seem to work at all. Any help would be appreciated, thnx

#

here is my current layout rn, the trigger for the scene just doesnt work

frosty hound
#

This shows nothing useful

frosty hound
#

Show how you've actually set up your triggers and code

ionic wing
#

i am really new to unity, so if you need to me provide something specific, lmk

ionic wing
#

heres the code for the scene transitioning. cs

frosty hound
#

I mean, you've set it up to work (how you think it should work), so naturally one might show that instead of just a gameplay screen.

frosty hound
#

Unless of course, you think putting the object named Challenger into your scene is all you need to do.

rich adder
ionic wing
#

i dont have game bar or nvidia highlights on this computer

rocky canyon
ionic wing
#

:(

rocky canyon
#

well then you cant

ionic wing
#

rip

frosty hound
#

You don't need to record your screen, take a screenshot of how you set up your character's rigidbodies/colliders, etc.

rocky canyon
#

^ code/ heirarchy/ inspector of relevant objects is normally enough

ionic wing
#

it says content blocked from this server

#

😭

#

nvm here we go

rich adder
#

player already missing trigger / collider

ionic wing
#

you sure? i have the layers

rich adder
#

I can trust my eyes

ionic wing
#

solid objects, interactables, and battlezone

rocky canyon
#

we're positive

#

theres no children objct of player.. and u dont have any 2D colliders

ionic wing
#

i added a 2d collider to the scene transition, not the player

rich adder
#

why would you check if other.isTrigger if other doesnt even have a collider

rocky canyon
#

you can't detect collisions without one

ionic wing
#

so wait do i just add a box collider 2d to the player

rocky canyon
#

does this try to detect ur player?

ionic wing
#

my npcs have them

rocky canyon
#

if so.. then yes

rich adder
#

if you plan into triggering something you need them lol

ionic wing
rocky canyon
#

ya, but it doesnt hav a collide.r.

ionic wing
#

idk how to make it detect it

rocky canyon
#

it'll never trigger that function

rich adder
ionic wing
#

i think

ionic wing
#

on there

rich adder
#

also at least 1 rigidbody is needed

polar acorn
rich adder
ionic wing
#

on trigger enter 2d collider 2d other

rocky canyon
#

ur object doesnt have one

rich adder
ionic wing
#

again im really new to unity so i have rly no idea what im doing

polar acorn
ionic wing
#

and help would be appreciated

rich adder
#

you never have anything incoming in the first place

ionic wing
#

😓

polar acorn
#

OnTriggerEnter happens when this object collides with another object, and if at least one of their colliders is a trigger

#

Collisions, by definition, require two colliders

ionic wing
#

so how would i fix this? asking the question

#

for my scene transition code

#

would i add something else

rich adder
#

start by giving your player a collider?

polar acorn
#

If you want to detect a collision with the player, the player needs a collider

ionic wing
#

a box collider or

#

do i have to go into the playercontroller script

rich adder
#

whatever shape you want to on the player

polar acorn
#

Whatever shape you like

rich adder
#

collider is a specific component to give your object a "shape"

ionic wing
rich adder
#

also at least 1 rigidbody is needed between the 2 Colliders

ionic wing
#

like this?

rich adder
#

sure, if you want it to be solid and not a trigger

ionic wing
#

well i want it to trigger

#

im just asking like

rich adder
#

so click isTrigger?

ionic wing
#

should i keep it like this

#

or

#

oh oka

polar acorn
#

Then you should check the box that says Is Trigger

ionic wing
#

i was thinking if the fkn

#

scene transition was a trigger already

#

the player wouldnt need the trigger

rich adder
#

yes but you need 2 colliders to interact

#

and 1 rigidbody

polar acorn
#

It would likely still work

ionic wing
#

yep it still doesnt work

polar acorn
#

That's why we asked if you wanted the player to be solid

rich adder
polar acorn
#

because it could be solid, or it could be a trigger

ionic wing
rich adder
ionic wing
#

i need a rigibody 2d now?

polar acorn
ionic wing
#

alright

rich adder
ionic wing
#

dynamuic, kinetic, or static

ionic wing
rich adder
#

sure

ionic wing
#

alr i just did that

rich adder
#

either one

ionic wing
polar acorn
#

Which one do you want?

ionic wing
#

idk what they do

ionic wing
#

i know dynamic for some reason slides off the screen

rich adder
#

probably kinematic

ionic wing
#

blegh it still doesnt work hmmm

rocky canyon
#

rigidbody must be present on atleast one object to detect collisions / triggers

ionic wing
#

ill try kinematci

rocky canyon
ionic wing
rocky canyon
#
public class DetectPlayer : MonoBehaviour
{
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Player"))
        {
            Debug.Log($"Player detected: {other.gameObject.name}");
        }
    }
}
ionic wing
#

should i set collision detected to continuous

rich adder
#

since you're not doing fast moving bodies

rocky canyon
#

the player seems to be set up correctly..

#

i would check ur Trigger object

ionic wing
#

alr imma try again

#

yep still nothing

polar acorn
#

How are you moving the player object

ionic wing
#

this is my second scene btw, dunno if i should do anything here

ionic wing
rocky canyon
#

this show us the movement code

polar acorn
#

How are you doing the movement

rocky canyon
#

Translation is gonna be problems when detecting physics collisions

rich adder
#

probably a transform since they never added rb

ionic wing
rich adder
#

moving transforms = same as teleporting

ionic wing
#

heres my code for player controller

rocky canyon
#

yea, thats not gonna work for accurate collisions

rich adder
#

You cannot use transform.position = Vector3.MoveTowards for accurate coll

#

you can switch it to rb.position tho or rb.MovePosition

ionic wing
#

i dont wanna remove that bc it might mess something up

#

ill try it though

rocky canyon
#

well, you sorta have to..

polar acorn
rich adder
#

then no accurate triggers for you

ionic wing
#

so change transform.pos to rb.pos?

rich adder
#

use MovePosition linked above its better

#

You must reference the rigidbody2d

ionic wing
#

so i change this

modest timber
#

where can i hire game devs?

rich adder
polar acorn
eternal falconBOT
#

:loudspeaker: Collaborating and Job Posting

We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
Collaboration & Jobs

rocky canyon
#

ya, it shouldnt be hard.. isntead of using transform.position change it to rigidbody2Dreference.MovePosition

steep rose
eternal falconBOT
#

:loudspeaker: Collaborating and Job Posting

We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
Collaboration & Jobs

rich adder
#

but the main movement is the one with the MoveTowards

ionic wing
#

so this one

rich adder
#

indeed

ionic wing
#

alr

rich adder
#

also it should be moved to FixedUpdate

ionic wing
#

ill change that to MovePosition

#

or move.position

rich adder
#

wait thats a coroutine, replace yield return null with yield return new WaitForFixedUpdate()

gentle fog
#

Guys
I've looked everywhere and I can't find it. What I found didn't work
How do I place the circle in front of the square?

rocky canyon
#

are they sprites?

gentle fog
#

Yes.
UI.

rocky canyon
#

well, UI is images..

rich adder
#

order of hierarchy

rocky canyon
#

use the Hiearchy order

#

Top gets drawn first

rich adder
#

draws last = always ontop

ionic wing
#

so uhm

#

what do i put here

gentle fog
#

Where?

ionic wing
#

move position or like move.position

rich adder
rocky canyon
winter echo
#

hello

gentle fog
#

Oh...

rocky canyon
#

its the Order of ur Hiearchy that controls UI elements

gentle fog
#

Ok

winter echo
#

i ned help its dosent go pass 2 lives why?

gentle fog
#

Nice
Tks

rich adder
#

eternal falconBOT
ionic wing
#

hmmm im gonna try something else

gentle fog
#

wait

#

How do I set hierarchy with prefabs?

rich adder
rocky canyon
# gentle fog Nice Tks

UI uses Hiearchy Order
Sprites (2D Objects) use Z position / Sorting Layers/order
3D just clips

ionic wing
#

figuring out if like i can get away with something else

winter echo
rich adder
#

do you want it fixed properly or not

ionic wing
#

yeah i do but im testing something

#

annnnd it doesnt work

#

figured

#

thats a theory out of the way

rich adder
#

literally a waste of time lol

ionic wing
#

i wanted to see if i had it in me

#

sfjvzl;xcjvlkczjxlk;v;xczlvcx

#

nyways

rich adder
#

it takes years of trial and error to know what actually works and what doesnt

ionic wing
#

im doing this shit for college

#

im prob gonna get rly frustrated

rocky canyon
#

if u destroy it they're gone..

rich adder
rocky canyon
#

if u create a new one.. its back to default values

ionic wing
#

i used to be a nintendo switch modder and it was difficult

rich adder
#

also you're jumping straight into diffcult things without proper basic fundations

ionic wing
#

everyone made it look so easy

#

i had to spend hours looking at raw assembly

#

thats all i was told to do

rocky canyon
#

Fighter Pilots make flying jets look easy too

ionic wing
#

C# is a little easier but not rly

rich adder
#

code is important but knowing the components and how they work is more important

ionic wing
#

i used a youtube tutorial that didnt explain swapping scenes but helped w everythinge lse

rocky canyon
#

yet

rich adder
#

yes Im aware, thats why you should build up instead of diving straight into deep end

rocky canyon
#

pro-tip.. you'll never find a youtube tutorial that does everything exactly the way you need

#

gotta learn to adapt.. use bits and pieces of many tutorials

#

and add em together

rich adder
winter echo
ionic wing
#

well iunno

rocky canyon
#

!learn most importantly.. for the fundamentals

eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

ionic wing
#

i hope college will explain this to me better

#

once im taking actual classes

rich adder
#

college on unity?

ionic wing
#

ive applied to several schools w comp sci and coding majors so i hope to learn shit

rocky canyon
#

so its always in the scene

ionic wing
#

again i want to learn what shit actually DOES

rocky canyon
#

and everything is based off of the gamemanagers live values

rich adder
ionic wing
#

no im not in for comp sci lmaooo

rich adder
#

the theory is good but they have no practical experience.

ionic wing
#

its part of my desired major but game design is my main focus

#

and game design has stuff like ui, music, coding, level design, etc

rich adder
#

school just teach you big heady concepts and barely any true real life coding experience

ionic wing
#

and with the set of classes im getting i hope it helps

winter echo
rocky canyon
#

how u ever plan on using that to count lives when u destroy it constantly?

winter echo
#

can i ask if is there any references i can see to get the idea

rich adder
#

the main difference is schools are structured to ease you into complex topics, doing it on your own, you have the same exact resources but control your own pace

#

which makes it diffcult to do things in proper order

rocky canyon
#

heres a page that shows u many of hte ways u can reference scripts or other objects

#

Singletons would be great for a gamemanager that tracks lives

#

(only ever have 1 instance of it) all ur gameobjects could ask it for the lives count

#

they'll all match

dusty rivet
#

bro does anyone know why my OnTriggerEnter2D just like isnt existing ive got a monobehaviour class and tryna make it have collision logic with a trigger and when i try use any collision stuff it only comes up with the Unity.visualscripting function

rich adder
#

welcome to VSCode

dusty rivet
#

ohhhhh

#

alr

#

thanks bro

rocky canyon
rich adder
#

I need to make a PR request for this, using an extension for this is ridiculous tbh

rocky canyon
#

lol..

#

i've been writing my own snippets lately >8)

dusty rivet
rocky canyon
#

you could still type it out long-hand 😉

rich adder
#

yeah its weird that microsoft made this and forgot about snippets

#

not like unity gives a shit about VSCode since they dropped full support at some point..

#

yet most of the employee videos on YT from unity are using vscode, aint that grand lol

dusty rivet
#

also how to i check if an object has a specific component smt like gameObject.hasComponent<component> or do i just do like if(gameObject.getComponent<component>){ // code }

rich adder
#

sure or TryGetComponent(always preferable because it has an included null check)

dusty rivet
#

alr

rocky canyon
#

TryGet OP

rich adder
# dusty rivet alr

btw any Component has access to other components on gameObject and transform

#

so collider.TryGetComponent also works etc.

dusty rivet
#

is there a way using like the leen tween library or smt where i can like make it so a range of numbers is converted to a range of colour so like when this variable is 10 the colour is green and as this variable gets closer to 1 the colour goes more and more red

#

i remember doing smt like that with LeenTween.value() i think a few years ago

#

idk tho

rocky canyon
#

ya, could do that with a lerp

#
    public void ChangeColor(int currentValue)
    {
        Color startColor = Color.green;
        Color endColor = Color.red;
        
        float t = Mathf.InverseLerp(minValue, maxValue, currentValue);
        Color newColor = Color.Lerp(endColor, startColor, t);
    }```
dusty rivet
#

ive done that but now when currentValue gets to minValue the colours alpha just goes to 0

#

also wanted to make it interpolate from green to red with 10 to 1 and when currentValue = 10 the colour is green which is good but when currentValue is anywhere from 2 to 9 the colour is just a flat yellow and doesnt change and then when its 0 the colour disappears

#

sorted out the colours inbetween

#

but it still goes invisible when currentValue is 0

leaden cliff
#

Hi, I want to implement a ball trail like in the reference video, varies its shape and helps to better simulate the “elevation” of the ball. I currently use AnimationCurves and multiple keyframes in script to simulate the ball's altitude by scaling the ball. ballscript fragment: https://hatebin.com/aznqgequim (1st video is the reference I want to achieve, 2nd one my game)

timber tide
#

Ah, actually yeah I get what you're doing with the keyframes, but I feel like that's something you already have information from seeing the ball shrink in your version, which seems like something you can plug into the TrailRender curve here

cosmic dagger
idle mason
#

void Flip() { facingDirection *= -1; transform.localScale.x = new Vector3 (transform.localScale.x * -1, transform.localScale.y, transform.localScale.z); }

Assets\scripts\PlayerMovement.cs(34,9): error CS1612: Cannot modify the return value of 'Transform.localScale' because it is not a variable

how do i fix this?

steep rose
#

you should just be able to assign it a new float directly instead of using a new vector

rocky canyon
#

or transform.localScale = new Vector3(transform.localScale.x * -1, transform.localScale.y, transform.localScale.z); }

idle mason
steep rose
#

that will work

rocky canyon
#

same thing commonly happens w/ rigidbody velocity.. rigidbody.velocity.x = 5; <-- error

#

rigidbody.velocity = new Vector3(5, rigidbody.velocity.y, rigidbody.velocity.z); you tend to create a new vector if/when ur wanting to modify just 1 of the properties

steep rose
#

yeah as transform.localscale.x or rb.linearvelocity.x are floats I believe

rocky canyon
#

yup, many of the common things new game devs run into are like this now that i think about it

#

Colors / materials was a big one for me

#

why do i need to make a copy of the material to change the texture!

rocky canyon
steep rose
#

couldn't you directly assign the X/Y/Z of a transform like so?

float Xscale = transform.localScale.x;
Xscale = anyfloat;

Or do you have to assign them again with the actual vector like you did above

nocturne kayak
#

I'm trying to understand colliders and bounds a bit better, but this one's breaking me - is there a way to get the topmost, frontmost and sidemost points of a collider?

rocky canyon
# steep rose couldn't you directly assign the X/Y/Z of a transform like so? ```cs float Xscal...

when you declare a struct its essentially a value type.. meaning when you assign a struct to a variable you're copying the entire value, not just a reference to it..
for example in a Vector3 when you try to modify a specific component like the .x you're not changing the existing instance, but rather creating a new instance with the modified component..
Vector3 originalScale = transform.localScale; // Copy of the original scale
originalScale.x = newXValue; // Creates a new Vector3 with the modified x
transform.localScale = originalScale; // Assigns the new Vector3 to the Transform
while Transform is a class, its localScale is a struct
blabla immutability of structs

steep rose
#

so you have to make a copy of it then use that copies X/Y/Z values and then assign the original with the copy again, I totally forgot about the copying instances of structs and classes

rocky canyon
#

yea, you have to create a copy, modify that copy and assign it back..

cobalt hinge
#

Hello, I'm having a problem where the player isn't able to jump in my webgl build, but it works perfectly fine in the unity editor. I am using the new unity input system and I'm pretty sure input is working properly but the velocity isn't being added. The video shows how after clicking or using the spacebar, the prompt goes away and the game starts, and the bird falls and then collision is detected and the game ends. I can't jump in the webGL version though. Here is the playermovement code: https://hatebin.com/amqphitpzw

rocky canyon
#

where does OnJump() get called?

cobalt hinge
#

In the playermovemtn script

#

its using the new input system

#

That just makes the prompt dissapear.

ashen niche
#

this code causes a slight stutter when the player starts pressing on the screen, and another stutter when the player releases
ive noticed a similar stutter in the chrome dino game
not sure if its a browser or device issue bc i tested it on multiple devices and it still stutters ( this only stutters on mobile not pc)

    {
        HandleInput(); 
    }

    void LateUpdate()
    {
        HandleCamera(); 
    }

    void FixedUpdate()
    {
        ApplyPhysics();
        RotateTowardsVelocity(); 
    }
    void HandleInput()
    {
        float targetGravity = Input.anyKey ? -3.4f * Gravity : 3.8f * Gravity;
        rb.gravityScale = Mathf.Lerp(rb.gravityScale, targetGravity, Time.deltaTime * damping);
    }```

any1 know a fix?
teal viper
ashen niche
teal viper
ashen niche
ivory bobcat
real falcon
#

does anyone know why this enemy would appear hovering over the ground, but be placed properly when the game starts?

#

idk if its something to do with animations or what

rocky canyon
#

it appears the root/pivot of the character (normally at its feet) is centered at the navmeshs center point

rocky canyon
real falcon
#

if I do that, he appears in the ground when the game starts

#

I just tried it

#

it's as if the pivot changes or something

rocky canyon
#

its not using root motion is it?

real falcon
#

how do I check that?

flat tide
#

Hello! Im working in my first Game Jam I cant finish understanding somenthing, im trying to do a interactible, but it doesnt detect the collider as intended anyone could give me any advice? (The console wont recognize anything)

timber tide
#

what's the hint the IDE is giving you with overlapsphere

flat tide
#

This you mean?

timber tide
#

ooh it's asking if you want to do non-alloc prob

#

Did you debug that the input is working first off

#

Next -> check if the collider array is ever not empty

flat tide
#

Do you mind If I add you and ask you in VC?

timber tide
#

that sounds like effort

flat tide
#

Im sorry, I just dont know how to check if the collider is ever not empty

timber tide
#

What you have there seems fine, and since you're not filtering out layers it should be easy to debug. You need to start debug logging each step, or step through it using the vs debugger

#

So, check that the input is working, and throw one into your foreach that it's actually going into there

flat tide
#

Ok

#

So I did this changes to know where its not responding and I feel that the results confused me more, so everytime I press E it checks for colliders twice, but when it detects one it only checks one

#

I feel more lost then when I started

timber tide
#

It's not checking twice, it's detected two colliders here so we can say that works

#

so with that known, we can say that what you're trying to detect is not*** an Interactable

ivory bobcat
flat tide
ivory bobcat
flat tide
#

And this is when im away from it

timber tide
#

so it does work>? 🤔

flat tide
#

A bunch of items, floor, walls the interactible itself

ivory bobcat
#

Show your current !code using the proper format

eternal falconBOT
flat tide
#

So it must be the second code thats not working correctly?

ivory bobcat
#

ie the Large Code Blocks section not the Inline Code section

#

Click on one of the links provided by the bot. Copy and paste the contents of the script inside the website. Press the save button on the site. Copy the URL and post it here - it should have changed.

flat tide
#
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerInteract : MonoBehaviour
{
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.E))
        {
            Debug.Log("E was pressed");
            float interactRange = 2f;
            Collider[] colliderArray = Physics.OverlapSphere(transform.position, interactRange);
            foreach (Collider collider in colliderArray)
            {
                Debug.Log($"Collider: {collider.name}", collider);
                if (collider.TryGetComponent(out Interactable interactable))
                {
                    Debug.Log("collider detected");
                    interactable.Interact();
                }
                else
                {
                    Debug.Log("Collider was not detected");
                }
            }
        }
    }
}

#

Like that?

#
using UnityEngine;

public class Interactable : MonoBehaviour
{
 public void Interact()
 {
    Debug.Log("Interact");
 }
}
ivory bobcat
flat tide
#

Yes thats correct, but it didnt get the component and run the second code

ivory bobcat
#

Which object where you expecting that wasn't listed?

ivory bobcat
flat tide
#

A cube im testing with

ivory bobcat
#

So click the message with the Cube once and see which object in the scene is lit up (yellow)

#

It should flash once

nocturne kayak
#

is there a way to instantiate an object as a child without changing it's scale?

ivory bobcat
#

It should have been named Cube

#

And it likely did not have the Interactable component.

flat tide
ivory bobcat
ivory bobcat
flat tide
#

Yeah sorry I have it as wall(38)

ivory bobcat
#

Wall was valid

#

What's the issue again? How did we come up with the assumption that it's being checked twice?

flat tide
#

no it was just not giving the interact, now it is

#

IDK how or what change made it work

#

Its just working as intended again

nocturne kayak
timber tide
#

When you child something on the editor usually it'll try to keep the original size by changing the local scale for you. I think adding the constraints is probably the best idea if you do want to keep it child, but honestly I think you should reconsider the hierarchy and instead make this child a sibling

cobalt hinge
#

Hello, I'm having a problem where the player isn't able to jump in my webgl build, but it works perfectly fine in the unity editor. I am using the new unity input system and I'm pretty sure input is working properly but the velocity isn't being added. The video shows how after clicking or using the spacebar, the prompt goes away and the game starts, and the bird falls and then collision is detected and the game ends. I can't jump in the webGL version though. Here is the playermovement code: https://hatebin.com/amqphitpzw

timber tide
#

Make dev build, log the input, check for errors in the browser's dev console

#

Meaning, two consoles. Dev build provides one, and pressing f12 usually brings one up

cobalt hinge
#

Wow I didn’t know you could do that, I’ll try it and get back to you

drowsy oriole
#

how would I add value to a int through script

#

Like, for everytime I do "Action" it adds 1 to an int

#

Like say I wanted to make a basket ball game with an int keptScore. If I make a goal, keptScore adds 1 to itself

cosmic dagger
drowsy oriole
#

I don't know what to search, I just needed help if someone could tell me how to make this work or get me a link to learn how to do it

wintry quarry
#

You're just asking how to add 1 to a number?

drowsy oriole
#

an int, yes

wintry quarry
#

myInt += 1;

drowsy oriole
#

in script

wintry quarry
#

Short for: myInt = myInt + 1;

wicked obsidian
#

Hello devs... who are using UNITY 6.26f1? Try please to insert sprite into image component... is it only me cannot insert imported sprite?

polar acorn
#

Is your image file imported as a sprite?

wicked obsidian
#

yes..the weird thing is that in Raw Image i can insert

polar acorn
#

Show the inspector of the sprite asset

wicked obsidian
#

one sec

eager spindle
#

image only takes sprite

wicked obsidian
eager spindle
#

try click the + button

#

to find it

wicked obsidian
#

tried

eager spindle
#

are there any other scripts attached to this GameObject?

#

you can also try assigning it in code

wicked obsidian
#

nothing

wicked obsidian
eager spindle
cosmic dagger
#

vid disappeared while i was looking at it . . .

polar acorn
#

It can't take a sprite sheet

wicked obsidian
#

yesterday downloaded Multiplayer sample there was not working shaders at all, today completly new project and this thing with sprites

polar acorn
#

Your sprite is set to multiple

wicked obsidian
polar acorn
#

You'd need to drag in one of the sprite sub-assets, or use a non-sheet sprite

wicked obsidian
#

let me record i will show

cosmic dagger
#

i think smth in the sprite settings may be wrong. i couldn't finish looking at the vid . . .

wicked obsidian
#

wait a minute please setting up to record

polar acorn
#

A screenshot is fine

wicked obsidian
eager spindle
#

earlier digiholic said that your sprite mode is set to Multiple, which could cause you not to be able to assign the sprite

wicked obsidian
eager spindle
#

Do change it to single

cosmic dagger
#

set sprite mode to single and test . . .

wicked obsidian
#

changed it works thanks.... but it was default option

#

it is weird

eager spindle
#

Might be because unity thought it was a spritesheet

cosmic dagger
#

multiple means you need to select a specific sprite from that spritesheet, not the sheet itself . . .

eager spindle
#

How does your image look like?

wicked obsidian
#

image like image nothing fancy

eager spindle
#

Ah yep then that's a single image

#

You only use multiple when working with a spritesheet

wicked obsidian
eager spindle
#

There's probably a way to change it in your importer preferences

wicked obsidian
#

Anyway, thank you all. will see in import settings

amber glen
#

Does anybody know why my buttons are at the bottom like that? I want them to be in the midde.

eager spindle
#

and make their position relative to the center of that rectangle by changing their anchors

arctic ridge
teal viper
arctic ridge
#

Ah i see, thanks

#

That makes sense

winged lotus
#

Guys do anyone know how can I use github with unity?

burnt vapor
#

The only thing is having a proper GitIgnore. Also, Git has Git LFS and you should probably make sure you use that if your repo is large

#

But both these things apply to everything really, not just Unity

winged lotus
burnt vapor
#

That is an issue with your experience with Git, and it has nothing to do with Unity

#

I suggest you look up a basic Git tutorial

#

Also, these type of questions apply to the XY problem. Instead of asking how Unity works with Git, you essentially just want to know how to use Git collaboratively.

winged lotus
jaunty bay
#
    {
        collider.OverlapCollider(contactFilter, collidedObjects);
        foreach(var x in collidedObjects)
        {
            OnCollided(x.gameObject);
        }    
    }
    
    private void OnCollided(GameObject collidedObject)
    {

    }

    private void OnEnable()
    {
        interact.action.performed += PerformInteract;
    }

    private void OnDisable()
    {
        interact.action.performed -= PerformInteract;
    }

    private void PerformInteract(InputAction.CallbackContext obj)
    {

    }

    }```

hi, quick question. how can i:
-when i press the E button,
-it checks if the function OnCollided is ran,
-if yes, then PerformInteract.
night mural
#

you can have a boolean that you flip oncollision and then in update check if it's flipped and flip it back/trigger your function

#

or that's how you'd do it with normal physics events, which you may not be using?

jaunty bay
#

kay ill try

night mural
#

basically you should think of it in 2 stages:

  1. in update, collect collision data
  2. on input, check the collision data you collected and do the thing or not
onyx tusk
#

how 2 make TMP editable?

warm rock
#

dont mind me

#

!vscode

eternal falconBOT
#
Visual Studio Code guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

https://on.unity.com/vscode

eager spindle
# onyx tusk how 2 make TMP editable?

also fun facts:

TextMeshPro is for world space UI, while TextMeshProUGUI is for screen space UI. You're more likely to use TextMeshProUGUI.

TextMeshProUGUI is part of the TMPro namespace. At the top of your file, you should using TMPro;.

To edit the text of a TextMeshProUGUI, you can use the text member.

using TMPro;

public class Healthbar: MonoBehaviour {
  [SerializeField] TextMeshProUGUI hpDisplay
  public void OnHealthChange() {
    hpDisplay.text = Player.health.ToString();
  }

}
onyx tusk
eager spindle
night mural
#

or i guess no text if it's like discord, since that's just literally an input field

onyx tusk
#

i mean, u click on the object & type text in it

night mural
#

yes

eager spindle
#

you mean an input field?

onyx tusk
#

yes

night mural
#

when you add text

#

look next to it, there is input

eager spindle
#

you can set the text member

#

of inputfield

#

it will fill up the inputfield in advance

onyx tusk
#

i can't understand how 2 make it focusable

eager spindle
night mural
#

you should just be able to click in and type, but if you can't, make sure that your scene has an EventSystem in it

eager spindle
#

Also make sure that nothing is blocking the element

topaz ice
#

Hey I'm not sure exactly how interacting with the hierarchy using a script.
I'm trying to get get a GameObject of something I got from using the "public GameObject [name]" yknow the deal.

uh, How do I get the game object using a name? like I'm using the current level float, convert it to string, and try to use the name.

#

Apparently the context I'm using is... wrong. And I have no idea whats wrong about it.

modest dust
topaz ice
#

This is gonna take a while tho

#
    {
        if (Input.GetKeyDown(KeyCode.Q))
        {
            if (ShutOffGui.localScale == new Vector3(0, 0, 0))
            {
                CanWalk = false;
                ShutOffGui.localScale = new Vector3(1080, 555, 0);
                GameObject CurrentLevel =          LevelPack.GameObject.Find(level.ToString());          
                Transform wallsTransform = CurrentLevel.transform.Find("Walls");
            }
            else
            {
                CanWalk = true;
                ShutOffGui.localScale = new Vector3(0, 0, 0);
            }
        }
    }```

'level' is a float, that I just add +1 to it everytime the player touches smth specific.
But the map I'm testing on, doesn't have that, so it doesn't matter.

'Levels' in hierarchy is what I mention as 'LevelPack'

what I'm trying to do is get a system that automatically goes to the next level when touching  the specific thing, that I'm not showing in the script right now.
modest dust
#

GameObject is a class name, you cannot access it from LevelPack which I presume is a GameObject itself

#

And Find is a static method, available only from class-level, not instance-level

topaz ice
#

because thats the part I've been really annoyied about.
I mostly use ChatGPT to understand stuff, which, yes I actually learn from.

And none of the answers actually gave me something that works

modest dust
#

You can either put a new custom component onto Levels, have an array of levels there, and access it via that

runic lance
# topaz ice ``` void Update() { if (Input.GetKeyDown(KeyCode.Q)) { ...

the docs tell you that you can use the "/" character to traverse hierarchies, so it's probably going to be fine with something like:

GameObject CurrentLevel = GameObject.Find("Levels/" + level.ToString());  

but you should consider an alternative approach, as finding things by name is very error prone and slow

topaz ice
#

(from my expirience on godot, and file explorer)

runic lance
#

but try it out @modest dust suggestion, it should be much better

#

having an actual level component instead of using names

modest dust
#

Yeah, but as he says, finding things by name is both error prone and slow

topaz ice
topaz ice
runic lance
#

you could, but not really the best tool for the job
ideally your "Level" game objects should contain a component (Level : MonoBehaviour) that hold the level information
so you can either find them by type or have them referenced directly in the inspector

modest dust
#

Custom types and references will always be stronger and more flexible than finding things via name or tag

topaz ice
#

Are you telling me to make levels into files and then load through files?

modest dust
topaz ice
#

I have got alot to learn 💀

steep rose
#

all it is is making a new script which is on every level to hold your level information, which then you access like caesar said

topaz ice
modest dust
#
public class Level : MonoBehaviour // Put that onto each level
{
  public Transform walls; // or some other type
  // Some level data
}

public class LevelManager : MonoBehaviour // Put that onto Levels or whatever else
{
  public Level[] levels; // Drag each level into this array, or via script if each level is a child of this GameObject
}

// Inside your update
...
Level currentLevel = levelManagerReference.levels[index];
Transform walls = currentLevel.walls; 
#

A simple example

steep rose
#

Also I would not recommending learning by GPT as it will give you unreliable answers, I would suggest learning by documentation or these #💻┃unity-talk message

topaz ice
steep rose
#

why is it bad for you to ask questions in a help channel, that would be counterproductive would it not?

#

I would argue that you ask more questions and let someone answer them, as there is nothing wrong doing so

topaz ice
modest dust
#

There's no issue with asking a lot of questions, but know the basics at least

topaz ice
steep rose
#

the basics would be debugging, knowing what variables are, referencing, etc

#

debugging is a big one

topaz ice
#

Also after a bit of reading MEANWHILE talking here, from what I'm understanding this is just roblox tables kind of,

which just holds a bunch of whatever value you want, (which on roblox is LITERALLY JUST STRINGS), So if I want to hold values of names I could use strings

topaz ice
modest dust
#

In the same order as I sent them

#

Docs aren't really for learning, mostly if you need to search for how something works once you know the basics

steep rose
#

I would say they are for learning new things you do not know, as they explain things in an orderly manner

topaz ice
steep rose
#

it is videos, but you are suppose to follow along I believe

modest dust
#

You're supposed to follow along them and make your own project (fix an existing one) at the end using what you learned

topaz ice
#

ngl unity should def add a code-babies channel or smth

steep rose
#

you are in a beginner channel, I think that would be enough

topaz ice
modest dust
modest dust
#

Then get started and learn

steep rose
#

you should be ecstatic to learn the basics

topaz ice
#

so I'm kind of more expirienced about asking for help here than actually knowing the code by itself

bitter apex
#

that's not very healthy

topaz ice
#

about what you already told me 💀

jaunty bay
#

guys help i cant do math

#

what should my sprite resolution be if i want it to be fullscreen?

bitter apex
#

do you actually desire to use c# or unity?

jaunty bay
#

my assets are 100 pixels per unit

topaz ice
modest dust
topaz ice
#

Going to websites to pretty much read of a book or see someone do stuff is not... fun? I guess?

bitter apex
#

I mean, coming here is more beneficial than not coming here, the whole purpose of this channel is to help people

topaz ice
bitter apex
#

but learn the basics as a starting point, they've helped you out already by giving you good resources. even if it's not fun, you're not gonna get anywhere without learning

topaz ice
#

for example if I got an answer from you about the script after you sent me, like the data stuff

#

I would've just copied it and kept it in unity

#

trying to figure it out

modest dust
bitter apex
#

you learn that by going to those links lol

topaz ice
#

its like taking a phone and taking it out piece by piece trying to understand it

#

which is DEFINETLY not healthy

#

but it can teach like a very very slight bit

#

even though I could've done x5 better

bitter apex
#

if you don't know a single thing about any of those components you're going to get nothing out of it

topaz ice
#

than that very very slight bit

bitter apex
#

sure you know how to arrange them back in the way they were already arranged previously

#

but you didn't get anything out of it

#

it's a difference between understanding and just copying something

topaz ice
topaz ice
modest dust
#

No point arguing about it

bitter apex
#

i'm glad you like the thing you have come up with, just go to the linked websites

fickle plume
#

@topaz ice Instead of talking about it you should start learning.

topaz ice
#

trying to get the point right in all perspectives

#

of whats going on

bitter apex
#

one that isn't of much use to you, if you'd like to learn go to the places people have introduced to you

fickle plume
topaz ice
mortal fog
#

Hi, I'm trying to move objects using the mouse position but I can't find a way to clamp the movement to the camera/screen to avoid clipping, this is what I'm using so far.

Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10f);
Vector3 worldPos = Camera.main.ScreenToWorldPoint (mousePos);

if (bIsBeingDragged)
{
    transform.position = worldPos;
}
topaz ice
#

Personally thats what I do but it sounds like a big stretch

mortal fog
#

I was going to go that route if I can't get this to work

steep rose
#

that most likely will not respect physics if you move your mouse fast enough

topaz ice
#

wait

#

if you use settings right physics won't exactly apply, ut hitboxes still will right?

#

you can just make the drag settings to 0

#

and it won't exactly move far away depending on physics itself

#

...but also I think what you meant is that the mouse can just go through things

#

I dunno, what ever happens, happens

#

Also if you ever feel like it you could make a fake mouse, So the player is dependant on the thing that has physics meanwhile the actual mouse isn't visible

topaz ice
# steep rose I'm not sure what you mean

Well I dunno if were exactly talking about the same thing, but
If you try to move things using .AddForce with RigidBody it can't go through things.

And by making Linear Drag and Augular Drag to 0
It's gonna go perfectly accurate to the mouse

#

IF we do a bunch of math to set exactly where the mouse is

#

But I still think its a little over complication, and that we could use some other technique

mortal fog
#

Kind of janky but got it to work

Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10f);
Vector3 worldPos = Camera.main.ScreenToWorldPoint (mousePos);

if (bIsBeingDragged)
{
    if (mousePos.x - objectWidth >= 0 && mousePos.x + objectWidth <= Screen.width && mousePos.y - objectHeight >= 0 && mousePos.y + objectHeight <= Screen.height)
    {
        transform.position = worldPos;
    }
}
onyx tusk
#

how 2 make input field interactable? i mean, i have 3d tmp with component input field but when i click on it - nothing happens

jaunty bay
#

quick question,

protected virtual void start()

when i made an inherited script, i wrote
protected override void start()

question:
-do i need to write base for all of the functions to be inherited or is it by default already is?
-whats the difference if i use the new keyword?

slender nymph
#

using the new keyword instead of overriding hides the base implementation. and if some object has a reference to the object but stored as the base implementation, if it calls the method that uses the new modifier then it calls only the base implementation because the new one is only available when the object is referenced as its own type.
as for the base keyword, you would use base.start() in the overridden method if you want it to call the base class's start method too. if you do not want that behavior then you do not need to do that, calling a base class's method is really the only use for the base keyword

silver basin
#

How do I SetActive all objects within a public GameObject[] group; variable?

polar acorn
#

Use a foreach loop

silver basin
languid spire
silver basin
languid spire
#

no need to google, think.
what is the base type of group?

silver basin
#

This is the first time Im working with arrays, I dont know what base types even are

languid spire
#

does this tell you nothing?

GameObject[] group;