#πŸ’»β”ƒcode-beginner

1 messages Β· Page 229 of 1

modest dust
#

(Or try debugging it yourself)

vale cradle
#

yes

#

using UnityEngine;
public class PlayerAttack : MonoBehaviour
{
[SerializeField] private float attackCooldown;
[SerializeField] private Transform FirePoint;
[SerializeField] private GameObject[] fireballs;

private Animator anim;
private PlayerMovement playerMovement;
private float cooldownTimer = Mathf.Infinity;
private void Awake()
{
    anim = GetComponent<Animator>();    
    playerMovement = GetComponent<PlayerMovement>();
}

private void Update()
{
    if (Input.GetMouseButton(0) && cooldownTimer > attackCooldown && playerMovement.canAttack())    
        Attack();
    cooldownTimer += Time.deltaTime;

}
private void Attack()
{
    anim.SetTrigger("Attack");
    cooldownTimer = 0;
    fireballs[FindFireBall()].transform.position = FirePoint.position;
    fireballs[FindFireBall()].GetComponent<FireBallscript>().SetDirection(Mathf.Sign(transform.localScale.x));
}
private int FindFireBall()
{
    for (int i = 0; i < fireballs.Length; i++)
    {
        if (!fireballs[i].activeInHierarchy)
            return i;
    }
    return 0;
}

}

modest dust
#

Once again, !code

eternal falconBOT
modest dust
#

Format your code properly first.

vale cradle
#

i don't understand that am i supposed to past my codein one of the links?

burnt vapor
#

Seems pretty self explanatory

#

Just paste your code in a code block as specified or paste large code blocks on a paste website

vale cradle
#

okay

burnt vapor
#

I also don't think PlayerAttack is a class relevant to your issue of not being able to jump

modest dust
#

Well, he did say that he can't both jump and attack

burnt vapor
#

So where's the part that handles jumping?

modest dust
#

But seeing the jumping part of the code would be nice.

vale cradle
#

there wasn't any issue with jump and attack but just stopped working since i had the issue with hearts

burnt vapor
#

So everything is fixed?

vale cradle
#

how do i share that

modest dust
#

paste the link

vale cradle
burnt vapor
#

This is not the code that handles jumping

modest dust
#

ah, ok

vale cradle
#

yes

burnt vapor
#

So is line 58 the part that doesn't work?

vale cradle
#

yes

burnt vapor
#

First of all, place a debug message in that if-statement to see if it's triggered at all. Also place one at the start of the jump method

#

See if both of these trigger

vale cradle
#

yes

burnt vapor
#

You placed the log message where I specified and they both call?

vale cradle
burnt vapor
#

Neither?

vale cradle
#

no error oe anything

burnt vapor
#

Alright, so let's see why the method doesn't trigger

#

My first thought would be wallJumpCooldown

#

At line 35 there's an if statement that mostly prevents the method from being called. Place a debug message above this statement and log wallJumpCooldown as explained in the link I shared with you

#

See what the variable value is every frame

vale cradle
#

yes

burnt vapor
#

Any luck?

vale cradle
#

no

#

i'll try re doing it

burnt vapor
#

Anything specific you get stuck at?

vale cradle
#

yes

vale cradle
#

but i'll try to figure it out somehow

burnt vapor
#

That's fine, it's not like I expect it to be done perfect. It's a very good skill to learn debugging

#

Just figure out what wallJumpCooldown is in that method

vale cradle
#

yes thankyou to both of you for helping me in this

burnt vapor
vale cradle
#

yes i am on it

burnt vapor
#

Alright I'll wait for an update

vale cradle
#

yes

vale cradle
#

I have another problem

#

is it okay if i paste the pic here?

#

i want to delete a transition but it's not giving me an option

#

in animator window

#

I want to remove the one in blue

#

i looked everywhere but it didn't explain anything related to it

burnt vapor
vale cradle
#

oh

#

okay

night mural
vale cradle
night mural
vale cradle
#

okay

#

Well it worked thankyou

keen dew
#

AI code

rare basin
#

we dont help people

#

with chat-gpt code

halcyon geyser
#

I almost believe you

#

You've put comments inside ur script explaining exactly what everything is supposed to do, yet you cant figure it out yourself?

keen dew
#

And the comments are written with perfect spelling and grammar, but in Discord you can't put a sentence together without typos?

languid spire
#

And, as if that was not enough, I see absolutely no evidence that you have even tried to debug this code

vale cradle
#

why am i getting this error

teal viper
# vale cradle

Probably a random ui bug. Clear the error and see if it happens again. Resetting the windows layout might help if it occurs again.

vale cradle
#

yes i just did it thankyou for helping

rare basin
#

yea no cap xD

north kiln
acoustic crow
#

Hello GoodMorning my friends

Hello, I wanted to ask if anyone has time to help me fix my game so I don't send it, but I would like to ask what I can change. I won't send it because I'm afraid it will be stolen. However, the problem is that there are so many little things that work quickly. I fix something, something else doesn't matter. I'd like to work through the entire game from scratch so everything is compatible, but I'm just a beginner myself and would need someone who knows Unity

frigid sequoia
#

If I want to access a class (call it Z) referenced in another class (call it Y) from a third class (call it X) (for example from a script that heals the player, and it access the player Controller and the UI Manager referenced in player controler) what is the more suited way to go? Make the class Z public in Y so I can get it from X with just the reference to Y, create public methods in Y to set anything I need in Z without the need a reference, make a reference for both Z and Y in X or it just doesn't really matter?

acoustic crow
#

Otherwise I would always describe all the problems and then you can write me the solution or an alternative if someone is willing to explain it

frigid sequoia
#

Just "fix my game" is basically asking for genie to grant you a wish

acoustic crow
#

No, that's not what I meant. Of course we have to do it together, step by step, but because it's so much, I thought I wouldn't ask because I'm bothering people here and nobody wants to help

#

I have to take a quick look at the game and browse through it, then I'll ask if you can give me just 10 minutes

#

"Google Translate is not the best lol"

vale cradle
#

can any one help me with this error

#

what do i do

#

this is the code

halcyon geyser
#

I dont think this is the correct code

vale cradle
#

for the saw?

halcyon geyser
#

Youre supposedly using some kind of AnimationEvent somewhere

vale cradle
#

i'll check

halcyon geyser
#

Or ur working on an AnimationEvent with missing information

#

As it doesnt give any specific file where this error occurs it might be the latter

vale cradle
#

does it have anything to do with one of my documents?

#

in this maybe?

modest dust
# frigid sequoia If I want to access a class (call it Z) referenced in another class (call it Y) ...

Dear lord, you're making me remember my programming exams at uni.

Depending on the situation, I either inject the reference I need, get it from a static reference manager, or if there is something in between the reference I need to access (X needs Z, X->Y->Z) then I either just grab it via a property/method in Y or call a method which Y/interface implements in order to do things with Z.

It doesn't really matter as long as the code is easy to understand, modify and expand if needed.
If I'm not sure, then I try and make it as simple as possible, so if I ever encounter any need to change it so that it can support other situations as well, I won't need to rewrite half of my project.

#

In this kind of situation, I'd probably let the player handle changing the UI and just call a method to modify his health

timber tide
frigid sequoia
#

I though the more manageable and scalable is just make the UI reference public; but I have been told to avoid making stuff public if possible so, not sure here...

autumn tusk
#

how would i put in a collision detection system

#

basically rn i have an enemy that teleports, and teleports randomly until it reaches a valid location, before spawning a smoke bomb effect

timber tide
autumn tusk
#

it spawns the smoke effect every time the enemy teleports, instead of when the enemy exits its teleportation state

#

how would i add a check to make sure the enemy is not in a teleportation state

lost hamlet
#

Is there actually any reason to not put everything public? It does help modders (tho Harmony and Traverse exist)

#

Maybe private stuff that can break easily

timber tide
#

if somethign that doesn't need to be used outside of a script it should be private

frigid sequoia
#

Probably should just create a method to heal instead of just one for taking damage, that should do it

frigid sequoia
brave compass
autumn tusk
frigid sequoia
lost hamlet
#

which makes it easier for me to understand even if i forget about it

autumn tusk
frigid sequoia
brave compass
# lost hamlet I don't really have a problem with that, tho i mostly break up my stuff in small...

So, for example, say you make an inventory system. You might store items in a List<Item>. But to add items to the inventory, you might need to do more than just add things to the list. For example, you might want to enforce a limit on the number of items, or weight of items. For that, you have the AddItem(Item) method, which does those things. But if you make the List<Item> also public, you might be tempted to just add items directly into the list, because you might forget about the AddItem(Item) method.

lost hamlet
#

Oh yeah i just put useless stuff in private, i.e. stuff that don't need to be touched. i mostly talked about stuff that direct access wouldn't hurt

frigid sequoia
lost hamlet
#

I just tend to remember how everything works

#

assuming i don't stop working for a few weeks

brave compass
frigid sequoia
#

That's the reason

#

If you are confortable using public go on

#

Is just good habit to avoid it

alpine glen
#

it can make debugging your issues a nightmare

lost hamlet
#

in fact i'm working on mods with other people and we have guidelines and such

alpine glen
#

your working alone with other people?

#

0-0

lost hamlet
#

Nah in a team

#

We have a funny name linked to the game too

frigid sequoia
lost hamlet
#

That honestly is pretty close to how i live

alpine glen
acoustic crow
#

I have a menu script that requires me to drag and drop many public GameObjects or panels into it, which is fine. The issue arises because these objects exist in the world and everything works there, but when I need to apply this to the main menu scene, it also requires these objects to be present in the main menu.

How can I solve this problem, or what do I need to change?

#

😦

#

Or to put it another way, how do you do it?

teal viper
#

If these objects are essential for the proper working of the menu, then you have no option but to have them in the main menu scene as well.πŸ€·β€β™‚οΈ

acoustic crow
#

There must surely be an easier solution to this. also performance-friendly

#

If everything has to be loaded in the background to work, that's performance intensive, but writing another script for it just ruins the overview

teal viper
#

Think why it depends on them and look for a way to eliminate the dependency

#

At least in certain situations(like a different scene)

queen adder
#

Hello, it is not really a code error but here is my issue:
I cant rotate my camera around on unity. I can only go up, down, left and right, but not rotate to different angles. It used to hold right nouse button and move mouse around but it is not working it is just moving left and right. plz help

burnt vapor
#

Not a code issue? Is this related to the main editor camera then and not some ingame camera?

acoustic crow
#

I also had the bug sometimes and was always able to solve it because the unity control somehow didn't work

acoustic crow
#

please tell me whether it worked or not

acoustic crow
#

So if you hold down the right mouse button (1) you still can't look around?

rocky canyon
#

ur heart rate needs to be in the 80 -85 range for it to work correctly 😜

queen adder
queen adder
rocky canyon
#

id hate having that on my screen

#

i know i stress enuff no need to remind myself heh

#

but yea i see ur drag box when u right clicked.. it shouldnt do that..

acoustic crow
rocky canyon
#

you dont have probuilder do u?

rocky canyon
#

click this lock icon

#

ur axis' are locked

queen adder
rocky canyon
#

np mate

queen adder
#

LOL i never wooulda known

rocky canyon
#

yea ive had that issue once.. its hard to discover since the icon is sooo small

queen adder
#

also, ty Hungriger for helping too πŸ™‚

rocky canyon
#

and no one ever really clicks it on purpose

#

πŸ˜„

acoustic crow
#

no problem, I'll help you and you help me. That's what the discord is for, we learn together and help each other

queen adder
#

πŸ™‚

sage mirage
#

Hey, guys! I got an issue here. So, whenever I click the play button on my main menu scene I see that. Check my code as well.

languid spire
#

So there is no gameobject called Player

sage mirage
#

Yes probably in my main menu scene

#

Do I have to like maybe copy paste from the other scene my player game object on that scene?

#

My game manager prefab is used across the other scenes

#

That's why I ve made it as a prefab

#

And the other managers

queen adder
#

I am having another error again. Mild NSFW

tulip stag
#

Sorry, I'm still new to using interfaces. I've used them for a method before and it works fine. Why is it not picking up on that string right there?
This is what my interface looks like:

{
    //Interface for general actions
    public interface IAction
    {
        string actionName { get; }
        void Cancel();
    }
}```
Should I make a whole method called GetActionName() and within my action scripts do 
```void GetActionName()
{
        return actionName;
}```
I'm sure this will fix my problem but I'm wondering if there's a simpler implementation
tulip stag
#

oh it just had to be public 😭

wintry quarry
buoyant rune
#

can anyone help me with these two problems that i have, the first one being when the enemy collides with the player the player just drops down into thte tiles and the second problem being the enemy just phases through the walls

#

my enemy is meant to track the player when it enters it its perimeters and it does do that successfully

#

however if i wwalk upwardsyou can see what the enemy does

chrome wadi
#

google tells me that this is a problem of Unity. How do I fix this? Because my code works so far everything

languid spire
chrome wadi
rocky canyon
#

it be like that sometimes

languid spire
#

the only thing you can do to fix it is to not have any windows open that use graphs

rocky canyon
#

try a different version

chrome wadi
#

Is there a big difference? because I use : 2022.3.6f1

queen adder
#

I can't upload! idk what is wrong

rocky canyon
#

nah not really.. all 2022+ are similar

#

2021 is even good imo

languid spire
#

yes, upgrade to the latest 2022.3 version

chrome wadi
#

Okay thanks i try it ^^

buoyant rune
#

with unity, how do i configure visual studio permanently

#

like i configure it but everytime i re launch it , i gotta do it again

cosmic dagger
#

πŸ€” you (should) only have to do it once . . .

burnt vapor
#

I assume the default editor option is not saved

buoyant rune
buoyant rune
#

quite stuck

autumn tusk
#

how do i stop a child from teleporting with its parents

teal viper
teal viper
earnest tendon
#

hello, running into a small issue with something, im trying to make it so when i pick up a coin the value changes using scriptable objects, the item count on the scriptable object increases but the text doesnt update when i pick up the coin, ive looked it up but i keep running into the same issue where the value in game doesnt go up and remains at 0

languid spire
eternal falconBOT
carmine elm
#

How can i rotate the axes from an Transform?

earnest tendon
languid spire
#

This says you do not

acoustic crow
#

😦

#

can someone help me with this text

teal viper
vale cradle
#

lol

acoustic crow
#

Yes, I know, but can you help me fix it?

vale cradle
#

i got erros

teal viper
acoustic crow
#

Error 1

MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEngine.Object.Internal_InstantiateSingle (UnityEngine.Object data, UnityEngine.Vector3 pos, UnityEngine.Quaternion rot) (at <f7237cf7abef49bfbb552d7eb076e422>:0)
UnityEngine.Object.Instantiate (UnityEngine.Object original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation) (at <f7237cf7abef49bfbb552d7eb076e422>:0)
UnityEngine.Object.Instantiate[T] (T original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation) (at <f7237cf7abef49bfbb552d7eb076e422>:0)
Effects.PlayExplosion (UnityEngine.Vector3 position) (at Assets/Scripts/Play/Effects.cs:10)
BulletScript.Die () (at Assets/Scripts/Play/BulletScript.cs:49)

Code

 private void Die()
    {
        PlayAudio("Explosion");
        effectsScript.PlayExplosion(transform.position); <---
        Destroy(gameObject);
    }
teal viper
# acoustic crow Error 1 ``` MissingReferenceException: The object of type 'GameObject' has been ...

The cause is self explanatory:

MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.

And looking at the stack trace you can tell that it was thrown by UnityEngine.Object.Internal_InstantiateSingle which was called from UnityEngine.Object.Instantiate, which was called from UnityEngine.Object.Instantiate[T] which was called from your code Effects.PlayExplosion in file Assets/Scripts/Play/Effects.cs line 10.

vale cradle
#

Please help me with these errors

buoyant rune
teal viper
vale cradle
#

i did

teal viper
acoustic crow
#

@teal viper okey i try it

teal viper
# vale cradle i did

Great, so find the missing reference and either make sure it's assigned or that you make a null check.

vale cradle
#

this is my code but i still did understand

teal viper
vale cradle
#

16

teal viper
#

No

#

Well, yes. But there's one before that

#

13 and 16

vale cradle
#

yes

teal viper
#

What does null reference exception mean?

vale cradle
#

i don't really know i am new to this

queen adder
#

I can't upload for some reason 😦

teal viper
vale cradle
#

em

teal viper
eternal falconBOT
vale cradle
#

like to copy the address of the argument?

buoyant rune
teal viper
teal viper
#

!code

eternal falconBOT
buoyant rune
#

oh

vale cradle
#

Null means like you have to put some value to it?

buoyant rune
rocky canyon
#

null means

teal viper
#

There's not much we can help you if you don't know what a null is even.

vale cradle
buoyant rune
teal viper
vale cradle
acoustic crow
#

OK, most of the erros are gone but I still have one

Error2

NullReferenceException: Object reference not set to an instance of an object
CoinScript.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/Scripts/Play/CoinScript.cs:34)

CoinScript

if (other.gameObject.CompareTag("Player"))
        {
            Destroy(gameObject);
            PrefsSave.instance.IncreaseCoins(Value); <-------
        }
        if (other.gameObject.CompareTag("Meteor"))
        {
            Destroy(gameObject);
        }

Prefssave

public void IncreaseCoins(int value)
    {
        currentCoins += value;
        PlayerPrefs.SetInt("Money", currentCoins);
        UpdateUI();
    }

i hope someone can help me

teal viper
# vale cradle Sorry

No need to be sorry. I'm not asking these questions to blame you or something. Just learn the basics properly and you'll see how easier it is to get through these kind of errors.

buoyant rune
acoustic crow
#

as soon as I touch a coin

private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.CompareTag("Player"))
        {
            Destroy(gameObject);
            PrefsSave.instance.IncreaseCoins(Value); 
        }
teal viper
acoustic crow
#

i dont understand?

vale cradle
#

I am actully like seeing the environment of unity engine and my uni is going to start with c# ( i know i can start right away) my uni has actually told us to create a 2D platformer game so i was going throught a yt tutorial for that but i am stuck on this erroe so i was asking for help

teal viper
vale cradle
carmine elm
teal viper
vale cradle
#

thankyou for helping

acoustic crow
#
NullReferenceException: Object reference not set to an instance of an object
CoinScript.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/Scripts/Play/CoinScript.cs:34)

teal viper
acoustic crow
#

No, I don't know what the error means

teal viper
acoustic crow
#

I dont use this in unity before

#

you mean puplic gameobject coin?

teal viper
acoustic crow
#

I don't understand why you can't explain it to me, because maybe I know, but I'll tell you another way, just tell me an example

teal viper
#

Because we can't make a C# basics lecture here in the discord, it's not what the server is for.

acoustic crow
#

All you have to do is write one sentence that explains it, but if that's too difficult for you, okay...

languid spire
rocky canyon
#

if its 2d and a sprite theres a flip boolean

teal viper
modest dust
carmine elm
#

i want the vector to be flipped

#

i m making a shooting

#

script

rocky canyon
#

on the sprite component theres that Flip boolean

carmine elm
#

i don t mean th

#

that

wintry quarry
# carmine elm i want the vector to be flipped

to invert a vector you can multiply it by -1.
To rotate a vector you can multiply it with a Quaternion. For example to rotate 90 degrees clockwise on the Z axis you can do:

Vector3 rotatedVector = Quaternion.Euler(0, 0, 90) * originalVector;```
rocky canyon
#

not sure what u mean by vector to be flipped then... if u want the vector flipped u can just change the vector

carmine elm
rocky canyon
#

i posted a link w/ all the rotation methods earlier..

wintry quarry
#

are you wanting to rotate this object? Or just a vector?

carmine elm
#

just a vector

rocky canyon
#

that'd be a 180 degree Rotation

#

on the Y axis

wintry quarry
#

looks like 90 degrees counterclockwise on the z axis to me

rocky canyon
#

its 2D... the z points forward

wintry quarry
#

yes

#

and we are rotating around the z axis

rocky canyon
#

if u rotate it on the z its flipping upside down

wintry quarry
#

90 degrees counterclockwise on the z axis will get that image, assuming the arrow pointing left is the green arrow and the one pointing up is the red (they drew them as both red)

#

I can see how you are saying 180 degrees on the y

rocky canyon
wintry quarry
#

yeah

rocky canyon
wintry quarry
#

it's unclear which they want though

#

both are valid

carmine elm
#

thanks

rocky canyon
#

as mentioned before

wintry quarry
hollow zenith
#

Does foreach over List<> iterate in order?

shell sorrel
#

yes

hollow zenith
#

nice, I assume dictionary is a case where it doesnt?

wintry quarry
wintry quarry
shell sorrel
#

Dictionary does not have a order

hollow zenith
#

Cool, I knew that one of them is not in order and needed to be sure since I am writing a priority list and its important that it happens in order πŸ˜„

shell sorrel
#

if you wanted could used a OrderedDictionary or keep a list of keys

#

generally if it has a index it is ordered

hollow zenith
#

Ah yes thats what I remember.
What is sorted list tho?

#

It seems to be a dictionary?

shell sorrel
#

what is the exact type you are talking about

wintry quarry
#

SortedList is really a sorted binary tree

#

IDK why they call it a list

#

it's almost the same as SortedDictionary too

shell sorrel
#

you will prolly never need to use that type

hollow zenith
#

Alright, good to know, thanks. I will keep using List since it does what I need it to.

shell sorrel
#

List if you want a list of items, that is ordered or you want to access by index

#

Dictionary, if you want to access it by some other sort of key and do not care about the order

#

like a string key being common for accessing it by a id or name

hollow zenith
#

Yep I use that, recently I even used HashSet since I needed a dictionary without value.

gaunt ice
#

it is just a list

wintry quarry
#

fine it's a list that maintains internal sorting

#

SortedDictionary is a tree

#

but they have almost identical APIs

#

your error message is telling you exactly what the problem is

#

you can't call new GameData(); in the field initializer like you have there

#

you need to do it in a method like Awake or Start

teal viper
#

It's written in the error details

wintry quarry
#

the line where the error is obviously

#

the line where you have written new GameData();

teal viper
#

It even says at "path":line number

queen adder
#

I'm having trouble adding my maze generator to a background sprite so that it draws on the background instead of at the empty object and the ways I've tried haven't worked well can anyone help with this?

timid marlin
#

Im trying to fix this code where when i collect a coin, it gets destroyed and adds to my points, i dont know what the problem is and how to fix it

wintry quarry
timid marlin
#

what..

wintry quarry
# timid marlin
  1. Looks like the thing you collided with doesn't have the "PlayerCollectCoins" script attached to it.
  2. Your IDE is not configured
teal viper
timid marlin
wintry quarry
eternal falconBOT
timid marlin
#

it was just colored 2 mins ago

swift crag
#

If it was working, kill the editor and reopen it

timid marlin
#

ok its fixed

red siren
#

Hi, I have a shader that changes the a render texture that I use to render the screen tot he player. I want to store those changes and apply them back to the main texture. Sort of to keep the effect and create a permanent change on what the player is saying. I'm using a render texture and a temporary render texture to store the changes, then applying them back to that main texture. I'm in Unity 2022.3, using URP.

`using UnityEngine;

public class ShaderTextureUpdater : MonoBehaviour
{
public Material material;
public RenderTexture mainRenderTexture;
public RenderTexture tempRenderTexture;
public string mainTextureProperty = "_MainTex";

void Start()
{

    mainRenderTexture.filterMode = FilterMode.Bilinear;
    mainRenderTexture.wrapMode = TextureWrapMode.Clamp;

    tempRenderTexture.filterMode = FilterMode.Bilinear;
    tempRenderTexture.wrapMode = TextureWrapMode.Clamp;
}

void Update()
{

    Graphics.Blit(mainRenderTexture, tempRenderTexture, material);
    Graphics.Blit(tempRenderTexture, mainRenderTexture);
    material.SetTexture(mainTextureProperty, mainRenderTexture);
}

}
`

This doesn't work for some reason, anybody got any idea why this might be?

#

I wonder if Graphics.Blit doesn't work in Unity 2022.3, but that sounds a bit farfetched.

chrome wadi
#

if i collect Gem 2 first it works that my gemcount is 3 but if i collect first gem 3 and then i collect gem 2 gem count is 3 and if i collect the last gem gemcount is 5 idk why he count +2 if i collect a other coin first anybody know what i did wrong ?

wintry quarry
#

your code should just be:

GemCount++;
gems[GemCount - 1].SetActive(true);```instead of that big `if` chain.
#

they can also all just have the Gem tag.. don't make a different tag for every gem

chrome wadi
#

array better in start or awake ?

wintry quarry
#

I don't really understand the question

chrome wadi
#

did it but it resolved not my problem. Wait a moment pls

sage mirage
# acoustic crow OK, most of the erros are gone but I still have one Error2 ``` NullReferenceEx...

Just to refer, whenever you want to destroy a game object you actually don't have to destroy it, as well as with instantiation. I know with that I am not helping you with your current issue but what I mean is it is better to disable and enable your game objects wherever you want rather than destroying them, for example if you have game objects to instantiate it is better to use Object Pooling method for these purposes πŸ™‚

chrome wadi
halcyon geyser
#

ohboy

wintry quarry
willow scroll
#

Also why would gemCount be less than zero?

chrome wadi
willow scroll
# chrome wadi

We usually use !code to show our code, unless you want to show syntax errors

eternal falconBOT
willow scroll
# chrome wadi

So let's break it down. If smth collides with a gem, this gem gets destroyed and a random gem is set active with a 33.(3)% probability.

#

That's the exact probability for the same gem to be destroyed and spawned, causing it being collected 2 times

chrome wadi
#

and how i fix that

willow scroll
#

You may call a random gem which wasn't the one something touched?

chrome wadi
#

the first gem always count +1 but the secong and thierd count as +2

#

ah wait mb i fogert that i have 2 colliders at my palyer xD

willow scroll
feral oar
willow scroll
#

The first gem will be counted +2 if you collect the gem with index 0

willow scroll
feral oar
#

might fix it counting the gem as more than what it should be

willow scroll
#

you have to get the instance of the collected gem to not activate it, probably

willow scroll
dusky quartz
#

hello, are any of you familiar with greedy pathfinding

swift crag
#

I guess Djikstra's is greedy

dusky quartz
swift crag
#

I've recently implemented A*, so I hopefully know how it works

#

(yeah, they're different algorithms, but they have the same vibe)

gaunt ice
#

set h to be 0 no matter where vertex is, then it is djikstra

swift crag
#

right!

dusky quartz
swift crag
#

No, this was for goal-oriented action planning

#

which creates new states to explore as it goes

#

so there's no "pre-existing" graph

#

All you need for A* is a set of nodes you haven't visited yet!

final kestrel
brazen canyon
#

Hey guys
I have this Bool variable.
If the raycast shot from Player hit the target, I'll set this to true.

#

In another class I have this Bool variable to store the Bool from the other class I showed above
But it seems like the Hit is not receiving from HitTarget ?

languid spire
#

are you expecting Hit to change when hitTarget does?

timber comet
#

Before you instantiate

polar acorn
#

If there's no error and the second script exists at all, then you're definitely setting Hit to controller.HitTarget

#

Whatever value controller.HitTarget has when this script starts, Hit will have

brazen canyon
polar acorn
brazen canyon
polar acorn
#

all you've shown is getting a boolean in Awake which, unless there's errors, is definitely happening

timber comet
languid spire
polar acorn
timber comet
#

Before he instatiate the object

timber comet
polar acorn
#

Yeah, there's a good amount of ambiguity here. @brazen canyon maybe you should provide actual context and !code, which objects and which scripts these are on, and what you actually expect to be happening that isn't happening

eternal falconBOT
timber comet
polar acorn
past ice
timber comet
polar acorn
polar acorn
slow beacon
#

Hey everyone which unity course I should take to learn advance scripting and game development?

brazen canyon
languid spire
brazen canyon
polar acorn
timber comet
slow beacon
eternal falconBOT
#

:teacher: Unity Learn β†—

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

slow beacon
#

I want particular course link

brazen canyon
timber comet
willow scroll
languid spire
brazen canyon
slow beacon
timber comet
#

Making a tycoon game is very difficult

languid spire
slow beacon
slow beacon
timber comet
slow beacon
slow beacon
#

These tycoon type game

polar acorn
willow scroll
slow beacon
timber comet
timber comet
brazen canyon
polar acorn
#

You're getting the value of TargetHit at the time the code is running and storing that value in Hit

bitter scaffold
#

Dear everyone, I hope to get help from you. I am building aviator crash game, but I am a beginer so I don't know how to do it,
Currently I have built like this
Now I don't know the graph function for airplane, would you please help me this one?
any tips will be fine.

willow scroll
# timber comet I don’t remember how they are called

Singletons is something that allows to have a some kind of "static" instance for a non-static class. I don't think this's a great explanation though. They usually look like this:

GameManager.Instance.MyMethod();

You can find a plenty of tutorials (not necessarily on youtube)

slow beacon
#

@willow scroll can you send me some good yt tutorial so I can learn intermediate level project

brazen canyon
polar acorn
timber comet
brazen canyon
#

I want Hit to change when hitTarget changes
I want the Hit to be true when hitTarget is true, Hit to be false when hitTarget is false

polar acorn
#

You're setting Hit to whatever value TargetHit is at the time that line runs

slow beacon
timber comet
polar acorn
#

if you want to use the value currently in TargetHit, just use TargetHit and don't make a new boolean at all

buoyant rune
#

!code

eternal falconBOT
languid spire
brazen canyon
polar acorn
timber comet
polar acorn
brazen canyon
timber comet
languid spire
#

which i s what I already told him

timber comet
timber comet
willow scroll
brazen canyon
timber comet
frozen stream
#

what do I do if I have a building player failed error but no other errors supporting it?

polar acorn
timber comet
timber comet
summer stump
#

What is the bug?
What does "loading so ??" mean?

acoustic crow
#

Yes, no plan, I don't even have that many objects, but it's there and then it loads

Do I need a loading screen or have I made a mistake? What do you think, when do you use a loading screen or can I not preload all objects?

summer stump
acoustic crow
#

When I pressed start the game froze briefly for 1 second or just 0.5ms but I don't want that

look at the astronaut

timber comet
summer stump
#

But that is very normal and expected

#

Not a bug. A LOT of games do that haha

acoustic crow
#

Yes, it takes 2 seconds on my cell phone and I can't preload it

what is asynchronous?

timber comet
timber comet
acoustic crow
#

Thank you

summer stump
acoustic crow
#

I'll take a quick look, thanks for the link ❀️ I'll get back to you later

lost anvil
#

what does { get; set; } actually mean in an interface?

polar acorn
#

In an interface, it means anything implementing that interface must implement a property by that name with a get and set

languid spire
lost anvil
languid spire
#

yes that will work, a property is just a fancy variable

polar acorn
lost anvil
short hazel
#

Use an auto-property with { get; set; } and the compiler automatically creates a variable (a field) the property will access.

lost anvil
languid spire
#

define not working

lost anvil
#

when i pick up an item i can still pick up another one

#

so i can pick up 2 at a time which is unwanted

wintry quarry
#

and not try to pick up a second thing

short hazel
#

Your issue is unrelated to using a property instead of a field

wintry quarry
#

yep just a basic data/logic issue

languid spire
#

I think he wants a static variable, that wont work with an interface

lost anvil
#

ah right so just inside the item script itself?

polar acorn
wintry quarry
wintry quarry
#

for example you might have a Item currentlyHolding; variable to track the item you are currently holding. If it's null you know you're not holding anything and can pick something up.

lost anvil
#

okay ill have a go cheers

frigid flume
#

hello, is the HasKey method useful here ? or i should delete delete it

short hazel
frigid flume
#

i want 0

short hazel
#

If I remember correctly you can use .GetInt("Force", 0) - the second argument is the default value if the key isn't here

frigid flume
#

ok thanks :)

dawn kestrel
#

This is more of an animation question, but I wasn't sure where to ask, and I figure what I'm trying to do overlaps with something I could do in code: is it possible to set an offset on just one layer of a multilayer asset (such as a .psd)? The aim is to have just one material/texture on the object, but have the "eyes" mapped to a transparent part of the texture, with a variety of eye textures below it that I can switch to on the fly.

If it makes a difference, this is for a vrchat avatar.

wintry quarry
zinc warren
#
RenderTexture renderTexture = Render3DObjectToTexture(obj);
if (renderTexture != null)
{
    rawImage.texture = renderTexture;
}

private RenderTexture Render3DObjectToTexture(GameObject objPrefab)
{
    RenderTexture renderTexture = new RenderTexture(Screen.width, Screen.height, 24);

    GameObject cameraObject = new GameObject("RenderCamera");
    Camera renderCamera = cameraObject.AddComponent<Camera>();
    renderCamera.targetTexture = renderTexture;
    GameObject obj = Instantiate(objPrefab);

    obj.transform.position = renderCamera.transform.position + new Vector3(0, 0, 10);
    obj.transform.LookAt(renderCamera.transform);

    renderCamera.Render();
    Texture2D texture = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.RGB24, false);
    RenderTexture.active = renderTexture;

    texture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
    texture.Apply();

    RenderTexture.active = null;

 //   Destroy(cameraObject);
 //   Destroy(obj);

    return renderTexture;
}

Hi, why is it only showing the render texuture when im not destroying the camera and object?

tulip stag
#
        [SerializeField] DEBUGCursor cursorInstance;

...
                    if (cursorInstance == null)
                    {
                        Instantiate(cursorPrefab, hit.point, Quaternion.identity);
                    }

How can I store that instance of cursorPrefab I just instantiated in my cursorInstance variable?

swift crag
#

reference the prefab as a DEBUGCursor, not a GameObject

#

Instantiate returns an object with the type of the object you gave it

#

so if cursorPrefab is a GameObject, you get back the GameObject

#

You can reference a prefab as a GameObject or as any component type on the root of the prefab.

tulip stag
#

Yesyes. I want to instantiate this GameObject, that is prefab'd, then immediately store it in a variable

swift crag
#

If cursorPrefab is a GameObject, passing it to Instantiate will give you a GameObject.

polar acorn
swift crag
#

You can't store that in cursorInstance.

#

But if cursorPrefab is a DEBUGCursor, then Instantiate will return a DEBUGCursor

tulip stag
#

So I just changed cursorInstance into a GameObject, right?

swift crag
#

That is the opposite of what I suggested.

#

I said you should make cursorPrefab be a DEBUGCursor

#

I presume you want to do things with the DEBUGCursor component.

tulip stag
#

Not really, no

polar acorn
swift crag
# tulip stag Not really, no

If you literally don't care about whatever cursorInstance is, then I guess you can make it a GameObject. This is fine if your game doesn't care at all about what components a debug cursor has

#

But that's not very common.

tulip stag
swift crag
#

I would still prefer to reference the prefab as a DEBUGCursor

#

This means I can't assign something that isn't meant to be a debug cursor to the field

#

and if I wind up needing to put some logic on a debug cursor later, I don't have to make any changes here

swift crag
#

I almost never refer to prefabs as a GameObject

#

none of these are prefabs, but the same idea holds

#

all I do with these things is active/deactivate and move them

tulip stag
#

So now both of them are of the type DEBUGCursor. What's the syntax for me to take Instantiate(cursorPrefab, hit.point, Quaternion.identity); and store it in cursorInstance?

swift crag
#

Just store the returned object into cursorInstance

#

that's all

pallid nymph
#

(I'm really sad the server doesn't allow me to post just "=") πŸ˜…

tulip stag
#

oh.

#

🫑 ‼️

languid spire
zinc warren
languid spire
willow scroll
polar acorn
#

That's how you store the new object in a variable

swift crag
#

I was going to comment on that, but I was surprised that destroying the camera would have an impact after calling Render()

willow scroll
cosmic knot
#

Does anybody have any experience with using navmesh in unity?

swift crag
#

ah, but you aren't actually using texture at all; you're returning the render texture you created (which is going to be a leak if you don't dispose of it). Perhaps that's how the spooky time-traveling behavior happened.

swift crag
cosmic knot
#

I have a problem with my project. I'm using vuforia for area targets and I want to use navmesh to create a mesh for the floor so I can then guide the user to the destination. Basically indoor navigation

#

But the tutorial is outdated and the ai navigation no longer has the bake button

random cedar
#

hello i was adding a rigidbody to a cube to not skip the wall but its stuttering and not move can someone give me the solution plz !! no code just from inspector

zinc warren
zealous geode
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(fileName = "New Ghost", menuName = "Ghost")]

public class GhostInfo : ScriptableObject
{
    public string ghostWord;

    public int damage;

    public bool isDead = false;

    public void Initialize()
    {
        ghostWord = assignWord();
    }
    public string assignWord()
    {
        string[] wordList = { "perro", "gato", "casa", "libro", "silla", "manzana", "pelota", "coche", "mesa", "flor" };

        int randomWord = Random.Range(0, wordList.Length);

        return wordList[randomWord];
    }


    public void compareWord()
    {
        if(PlayerType.playerInput != null)
        {
            if (PlayerType.playerInput == ghostWord)
            {
                isDead = true;
                PlayerType.playerInput = "";
            }
        }
    }
}

Hello, I need some help in trying to understand why my boolean isDead is always true. To make it go true it gets compared with a player Input via an Input Field. This is the script:

    void activateInput()
    {
        InputFieldObject = Instantiate(InputFieldPrefab, canvas.transform);
        inputField = InputFieldObject.GetComponent<TMP_InputField>();
        inputField.ActivateInputField();
        inputActive = true;
    }

    void deactivateInput()
    {
        Destroy(InputFieldObject);
        playerInput = inputField.text.ToLower();
        Debug.Log(playerInput);
        inputActive = false;

    }

playerInput is declared as a static public string.

Using a script called Enemy, when the enemy prefab spawns, I call Initialize() to name it then on it's Update I check if it died or not.

    void checkDeath()
    {
        ghostData.compareWord();
        Debug.Log(ghostData.isDead);
        if (ghostData.isDead == true)
        {
            Destroy(this.gameObject);
        }
    }
swift crag
#

you make a new render texture, then make a new texture, then read into the new texture, then...return the render texture

languid spire
swift crag
#

eh, it looks reasonably close to the example on the Camera.Render page

#

it's just wrong

languid spire
#

we saw it when he first posted it a few hours ago

swift crag
#

ah

random cedar
# polar acorn How are you moving the object

float movespeed = 5f
float xValue = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed;
float zValue = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;

transform.Translate(xValue,0,zValue);

polar acorn
zealous geode
# polar acorn Where do you assign `ghostData`

Oh, let me show you, I was reaching the message typing limit, so I was trying to make it as short as possible.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Enemy : MonoBehaviour
{
    public GhostInfo ghostData;
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        checkDeath();
    }

    void checkDeath()
    {
        ghostData.compareWord();
        Debug.Log(ghostData.isDead);
        if (ghostData.isDead == true)
        {
            Destroy(this.gameObject);
        }
    }
}
frigid sequoia
#

All the component assignement parameters have to be referenced manually in the inspector each time, which is... very inefficient considering I have to create like several dozens for these scripts. It is fine if I assing these references at awake or should I like... make an editor tool like a button to assing all of these in editor with just one press?

shut spade
polar acorn
eternal falconBOT
random cedar
polar acorn
cosmic knot
#

I see that there are way too many people here with problems so if anybody wants to help me, I'm willing to pay at this point. I've been stuck for the past 2 weeks and it's driving me insane

zealous geode
polar acorn
zinc warren
zealous geode
#

Becuase if it doesn't, then this is the issue probably

polar acorn
zealous geode
#

When I declare it on the ScriptableObject script. It's in one of my last messages

polar acorn
#

That is what value it's set to when you make a new SO

#

You never set it to false

random cedar
polar acorn
obtuse axle
#

um hello, i have a question about jumps and running, I have a character in 3D that can jump and sprint, but when i jump while running, first the character doesn't keep its running momentum midair, and second i feel like when the character jumps while running, it doesn't jump as high as when im not running. Do you know why it does that? i can provide some screenshots if you need

random cedar
edgy prism
#

Hello, I am trying to enable a UI gameobject with a singleton only problem is its never awake until I call Script.i.SetActive() so its it ok to assign i in start or should I use something like

static FishingUI()
{
    i = FindObjectOfType<FishingUI>();
}
polar acorn
short hazel
edgy prism
safe aspen
#

Hey! anyone got any idea how I could restart Time.time when the scenemanager loads the scene?

fierce shuttle
eternal falconBOT
polar acorn
fierce shuttle
short hazel
#

After a compilation, when exiting play mode, etc.

safe aspen
edgy prism
safe aspen
#

and i want it to go to 0*

short hazel
pallid nymph
short hazel
#

Constructors are public ClassNameHere() and static ClassNameHere(), notice that they don't have a return type like Awake does, it returns void

eternal falconBOT
obtuse axle
eternal falconBOT
edgy prism
fierce shuttle
obtuse axle
#

i know it's messy but im just discovering things here

safe aspen
#
    {
        Time.timeScale = 1;
        tryAgainButton.SetActive(true);
        gameEnd.SetActive(true);
    }

    public void RestartGame()
    {
        Time.timeScale = 2;
        SceneManager.LoadScene(0);
    }```

was trying smth and put Time.timeScale from 0 to 1 and the 2nd one to 2 and my player is running hella fast for some reason lol
languid spire
#

example

short hazel
#

If each value needs to be separated by a newline, you can join them with string.Join()

string joined = string.Join('\n', s1, s2, s3, s4);
// '\n' creates a newline
#

Else, you can use string concatenation or make an interpolated string to have more control over the format of your final string

fierce shuttle
safe aspen
# fierce shuttle a timeScale of 1 means 100% normal speed, so a value of 2 would be 200%, if your...

well my movement shouldnt be based on time tbh lol

anyways, another problem i got is that the time starts from 1 and till it becomes 1, the ui for the time i got is blank.

    {
        if (Time.time >= 0)
        {
            timerText.text = Time.timeSinceLevelLoad.ToString("#,#");
        }
    }

    public void AddScore()
    {   
        scoreValue++;
        scoreText.text = scoreValue.ToString("#,#");
    }

    public void UpdateAmmoInfo(int currentBullets, int maxBullets)
    {
        ammoText.text = currentBullets + "/" + maxBullets;
    }

    public void OpenEndScreen()
    {
        Time.timeScale = 0;
        tryAgainButton.SetActive(true);
        gameEnd.SetActive(true);
    }

    public void RestartGame()
    {
        Time.timeScale = 1;
        SceneManager.LoadScene(0);
    }```
#

anything i might be missing?

#

btw Time.time >= was to 1, just changed it

fierce shuttle
# obtuse axle https://gdl.space/ekagosecox.cpp

Im not too familiar with CharacterController as I usually use Rigidbody more, though I believe the general rules still apply, you would probably want to only apply Move once at the end, after all your calculations, and modify a Vector3 that represents your current movement direction and jump/gravity velocity, you also would normally want to apply deltaTime only once as well, this tutorial may help with implementing a jump and gravity, although the example is in 2D, since up/down is the same in both 2D and 3D (y-axis), the logic should work the same: https://gamedevbeginner.com/how-to-jump-in-unity-with-or-without-physics/

It also looks like your changing the position of your transform and also trying to set Move, you would normally want to do one or the other, depending if you want your movement to respect physics (using the CharacterControlllers "Move" func) or not (setting the transform position)

Learn how to jump in Unity, how to control jump height, plus how to jump without using physics, in my in-depth beginner's guide.

fierce shuttle
safe aspen
#

true, removed it

#

but still, time starts showing blank then 1

#

idk why it doesnt show 0 on restart

frigid flume
safe aspen
#

congrats!

frigid flume
#

πŸ’ͺ

buoyant knot
frigid flume
#

a line is a line

slender nymph
#

you should consider using better names for your variables, as they are now they don't currently convey what they are supposed to be for. also any time you find yourself using numbered variables you should be using a collection like an array or list

frigid flume
#

they mean something in french but yes list would have been better

buoyant knot
#

bfa6 means nothing in any language

frigid flume
#

is it a good idea to export my project as apk before it is finished, to show to friends for example ?

frigid flume
low path
#

your UI should modify underlying settings data. when you open it up, it should check the state of that data and set its own fields based on that data.

slender nymph
#

you would need to show code. but you should be loading your saved setting in Awake and assigning it to the sliders when loaded

frigid flume
#

yes i know don't worry i'm just happy everything works fine

buoyant knot
#

am I fair to style police here? because I feel like this man is going off the deep end

low path
#

separate the UI from the state it represents.

fierce shuttle
acoustic crow
#

so I should do 2 canvases and not all in one?

low path
#

2 canvases?

buoyant knot
#

multiple canvases is good

low path
#

well... i don't think that's the issue though...

#

the issue is that they need some data structure like a don't destroy on load manager that stores settings state.

buoyant knot
#

whenever any one element in a canvas changes, unity needs to effectively redraw the entire thing from scratch. So it is generally good to have multiple canvases, especially if you have one part of your canvas constantly animating

low path
#

and then the UI should refer to that thing and set itself based on that, and control that data based on user manipulations of the UI

frigid flume
#

i am a complete noob but could'nt you use playerprefs ?

buoyant knot
#

playerprefs is the devil

frigid flume
#

no

safe aspen
buoyant knot
low path
#

the "cleanest" way is probably to use like a text file that you read and write, if you want to preserve the values across sessions.

frigid flume
#

then json maybe (my knowledge ends here)

buoyant knot
#

playerprefs saves things to your registry. even if you uninstall, whatever you wrote stays there.

frigid flume
#

is it bad to export project as .apk before finished ? is it the way updates are done, juste replace the old .apk by a new .apk ?

buoyant rune
#

tryna click the drop down icon for the animation but literally nothing happeneing???

buoyant knot
#

so if you are KerbalSpaceProgram, and store a level file of several GB to playerprefs, and later uninstal KSP, KSP might still be taking many GB of data on your computer

frigid flume
#

make the app so good no ones wants to uninstall it

low path
buoyant rune
timber comet
#

How can I add an event for when a Button is selected so I don’t check for that every frame?

timber comet
rich adder
timber comet
rich adder
#

nothing wrong with sending events from a ui child object to a main UI manager

acoustic crow
#

Can someone help me? If I set my options canvas to 0, I can open the option menu but nothing can be clicked. If I set it to 1, I can close it but the sliders won't move

as info the mainmenucanvas is at 0

and the loading screen to 1

Everything works in the world but not in the main menu

but why

slender nymph
final kestrel
#

I still have to invoke the UnityEvent someplace in my code right?

#

I invoke then I choose what to react in my inspector

tender stag
#

lets say i have a variable called maxSpeed, how do i only add enough force to reach that speed
rb.AddForce(slopeMoveDirection.normalized * );

low path
#

just add the force and in update, limit your velocity to max speed

tender stag
#

cant do that

#

cant directly set or change velocity

tender stag
#

which is how fast the force gets added

low path
#

the game already implements acceleration

#

f=ma

lofty sequoia
#

Getting an issue where it appears like I'm being given access in the inspector to a parent's member despite it being private (but SerializeField is interfering?)
MyParentClass
private List<int> _myPrivateList;

MyChildClass : MyParentClass
private List<int> _myPrivateList; // specific to ChildClass, not overriding

The inspector shows 2 fields for My Private List

#

[SerializeField] is exposing a private member to child classes via the inspector

slender nymph
#

private members are still part of child classes, they just cannot be accessed or modified by those children

frigid sequoia
#

Shouldn't this be working? Is there any step I am missing? Cause the CustomEditor Tags are not being colored and the console is showing this error

slender nymph
#

configure your !IDE

eternal falconBOT
tender stag
low path
#

i think if you want to add enough force to achieve a certain velocity, the forcemode.velocitychange will do that, instantly

frigid flume
#

hello, there is a thing that i do beause i've seen tutos guys do it but i don't understand why.
Why do they always create an emptyobject, attach a script to it, then attach the emptyobject to a button, instead of attaching the script to the button directly ?

low path
#

do you instead want a velocity cap?

tender stag
#

i want to limit the player speed

#

but i cannot directly clamp the magnitude

tender stag
#

or set or change the velocity

frigid flume
#

ok thanks so it's just like that ^^

lofty sequoia
slender nymph
#

serializing values is not the same thing as being able to access and modify the private members in the code

lofty sequoia
#

Ok, so should I treat those members as protected basically?

slender nymph
#

that private member is still part of that class, as i pointed out. it's just not accessible within the code because it is not exposed to that class

low path
#

why can't you directly set or change the velocity?

lofty sequoia
#

Protected from the perspective of the inspector? I know in code it still works normally

slender nymph
#

so you know how you can serialize a private variable despite it not being exposed to other classes? it's literally the exact same concept here

lofty sequoia
#

Oh gotcha, that makes sense

uneven oriole
#

Can anyone help me, im trying to make a game and I need to change a variable when two gameobjects colide with eachother. I've attatched the code

slender nymph
#

why did you declare OnCollisionEnter inside of OnCollisionEnter

uneven oriole
#

ehm

#

i didnt even realise

polar acorn
slender nymph
#

the warning you are receiving should have given you a hint towards the problem

uneven oriole
#

let me test it now

#

So with this code its still not working. I might not have everything up the right way

slender nymph
#

is the log printing

frigid flume
#

do someone knows why this occurs, but only to the 4 last scenes i try to load ?

using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;

public class MusclesMenuScene : MonoBehaviour
{
    public string ForceMenu;
    public string TricepsMenu;
    public string DosMenu;
    public string BicepsMenu;
    public string JambesMenu;
    public string EnduranceMenu;
    public string VitesseMenu;
    public string EquilibreMenu;
    public string FlexibiliteMenu;

    public void ButtonForce()
    {
        ChangeScene(ForceMenu);
    }
    public void ButtonTriceps()
    {
        ChangeScene(TricepsMenu);
    }
    public void ButtonDos()
    {
        ChangeScene(DosMenu);
    }
    public void ButtonBiceps()
    {
        ChangeScene(BicepsMenu);
    }
    public void ButtonJambes()
    {
        ChangeScene(JambesMenu);
    }
    public void ButtonEndurance()
    {
        ChangeScene(EnduranceMenu);
    }
    public void ButtonVitesse()
    {
        ChangeScene(VitesseMenu);
    }
    public void ButtonEquilibre()
    {
        ChangeScene(EquilibreMenu);
    }
    public void ButtonFlexibilite()
    {
        ChangeScene(FlexibiliteMenu);
    }
    public void ChangeScene(string scene)
    {
        SceneManager.LoadScene(scene);
    }

}```
uneven oriole
#

no its not

slender nymph
frigid flume
#

i added the scenes in the build earlier

polar acorn
polar acorn
#

Why do you have so many functions

frigid flume
#

i love writing

uneven oriole
frigid flume
#

you know why i am making this script ? i had a different script for each scene at start

polar acorn
polar acorn
frigid flume
#

but why can't my scenes loads correctly

uneven oriole
eternal needle
slender nymph
slender nymph
uneven oriole
brazen canyon
#

Hey guys
Does Static make a class accessible from other classes even though they're not in a same GO ?

polar acorn
slender nymph
polar acorn
eternal needle
uneven oriole
#

thank you, it works now

brazen canyon
frigid flume
#

ok that's why x)

slender nymph
polar acorn
frigid flume
#

i'll try my best

#

i'll let you know

acoustic crow
low path
#

code please

frigid flume
#

i can't convert Button to String

acoustic crow
#

i need a script that a slider working?

low path
#

do you not have any scripts?

acoustic crow
#

i havit a uicontroll for that

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UIController : MonoBehaviour
{
    
    
    public Slider _musicSlider, _sfxSlider;
    
    public void ToggleMusic()
    {
        AudioManager.Instance.ToggleMusic();

    }
    public void ToggleSFX()
    {
        AudioManager.Instance.ToggleSFX();

    }
    public void MusicVolume()
    {
        AudioManager.Instance.MusicVolume(_musicSlider.value);

    }
    public void SFXVolume()
    {
        AudioManager.Instance.SFXVolume(_sfxSlider.value);
    }
}
#

I'm desperate

frigid flume
polar acorn
frigid flume
#

it was a bad ida but anyways i can't figure it out

polar acorn
#

Literally just make a function that takes a string and changes to that scene. That is all that needs to be in the script

#

Call that function on your button. Pass in the string.

frigid flume
#

but where do the string cames from

#

how do i define which button calls which string

polar acorn
#

when you set the function on your button

swift crag
#

A UnityEvent can pass a constant value to your function.

#

(for certain types, at least)

frigid flume
#

so this is enought ?

swift crag
#

ints, floats, and strings for sure

polar acorn
fading rapids
#

can someone help me in Unity talk

#

its not a code problem tho

polar acorn
polar acorn
frigid flume
#

well i didn't knew i could add a parameter identificator to a button

#

my script gone from 50 lines to 5

polar acorn
frigid flume
#

at least a beginner coudl understand how it worked if he didn't knew a parameter could be added to a gameobject '-'

#

the new script is not beginner friendly

tender stag
#

Fixed Update rb.AddForce(slopeMoveDirection.normalized * acceleration);

Update ```Vector3 flatVelocity = new Vector3(rb.velocity.x, 0, rb.velocity.z);

if(flatVelocity.magnitude > moveSpeed)
{
Vector3 limitedVelocity = flatVelocity.normalized * moveSpeed;
rb.velocity = new Vector3(limitedVelocity.x, rb.velocity.y, limitedVelocity.z);
}```

#

the thing in update is limiting the velocity, but its not setting the new velocity in the correct direction, which would be slopeMoveDirection

swift crag
#

onClick is a Unity Event

swift crag
#

UnityEvent lets you set up callbacks in the inspector.

#

A "callback" being a function that you call when something happens, basically

polar acorn
frigid flume
#

i don't know how to call these i "learned" in french :)

polar acorn
#

If you don't want to flatten your velocity, why are you going out of your way to do it

frigid flume
tender stag
swift crag
#

sounds good; i think you've got it!

polar acorn
frigid flume
#

thanks for your help ^^ (even if it gave me more work)

tender stag
#

this also works

#

but it makes my character bounce

#

when walking up slopes

#

im not sure why

#

let me send a video

tender stag
lost anvil
#

how would i go about making an inventory script to simply hold my picked up gameobjects in an array and scrolling down or up equips them?
ive looked around for about 15 mins but couldnt find anything

tender stag
#

but here i cant jump

#

anyone?

tender stag
tender stag
#

why

polar acorn
#

Pretty sure you're gonna need to do some math. You can get the non-jumping part of your velocity with ProjectOnPlane using your slope normal. Then you can see how much greater your projected velocity is than your max speed. You want a vector with that difference as the magnitude, but in the opposite direction to your projected velocity. Then you add that vector to your original velocity, and you'll have slowed down your projected velocity enough that you're kept in your speed range

tender stag
#
slopeMoveDirection = Vector3.ProjectOnPlane(moveDirection, slopeHit.normal);```
polar acorn
#

Also that slope move direction is not your current velocity, that's just the direction

#

You specifically want the velocity vector projected on the plane, magnitude and all

tender stag
# lost anvil how would i go about making an inventory script to simply hold my picked up game...

simplest way, have a holder on your player, where you have all the models of the items (the items which the player will see in his hand), make a script, just have an integer in there called ID, attach this script to the model in the players hands and on the object in the world, make them have the same id, and when you pick the object up with a raycast just disable the ground object so you cant see it since you picked it up, add the object to the items array, have another array of all the possible items (the items in players hands), and then just scroll through the items you have in the inventory and compare id's with the other array

rich adder
#

use a float value to clamp then use that in Quaternion.euler

tender stag
#

im so lost

polar acorn
# tender stag i know you explained it but could you help me out
  1. Use ProjectOnPlane to get the current velocity projected on the slope
  2. Check if that vector's magnitude is greater than your max move speed
  3. If it is, subtract the max move speed from that magnitude
  4. Create a vector of that length, in the opposite direction of your projected vector
  5. Add that resulting vector to your original velocity
tender stag
polar acorn
#

That's steps 1 and 2 so far

tender stag
#

yeah i know

#

im not sure what the error means

polar acorn
#

You aren't doing anything with the result

tender stag
#

do i store it as a float?

polar acorn
#

Is it a float

tender stag
#

well yeah

#

magnitude

polar acorn
#

then it would indeed make sense to store it in a float

dusky dirge
#

hello! I'm getting this error after ive added, then disabled, and removed a script. I've tried reimporting everything, cleaning my cache, restarting unity editor + my PC, and I am yet to find a fix. This is happening both when I run the game, and in the editor.

error: TLS Allocator ALLOC_TEMP_TLS, underlying allocator ALLOC_TEMP_MAIN has unfreed allocations, size 208
log: Allocation of 38 bytes at 0000020790500110

EDIT: I FOUND A FIX

update: just had to update my Unity version LOL

tender stag
polar acorn
tender stag
tender stag
polar acorn
#

That's the direction you want to use. The magnitude is the difference between your magnitude and your max speed

#

A vector is a direction times a magnitude

tender stag
#

so like this?

frigid sequoia
#

For reals, what am I doing wrong? Why is this not working? This is not overriding the Editor at all it isn't getting the reference to the Editor class to begin with and I don't know why

polar acorn
frigid sequoia
jaunty heath
# tender stag

id suggest to use proper variable names, "o" and "a" are quite nothing saying, does not help with readability

tender stag
#

im gonna read and try to understand more of what it does

polar acorn
tender stag
# polar acorn yes
Vector3 o = -slopeVelocity.normalized * a;

rb.velocity = rb.velocity + o;```
tender stag
#

i dont feel like i've done the last step right

#

oh i did

frigid sequoia
polar acorn
tender stag
polar acorn
#

as to the highlighting, it's probably a misconfigured !ide

eternal falconBOT
frigid sequoia
tender stag
#

sometimes i jump higher and sometimes lower

polar acorn
tender stag
#

and on flat ground

tender stag
#

i want them to be straight

polar acorn
# tender stag they take me away

Once you're no longer touching the slope, you should no longer be using the slope's normal but Vector3.up for this calculation

#

Since you're no longer standing on angled ground

frigid sequoia
polar acorn
frigid sequoia
#

Oh, it does show here actually

#

Do I really have to declare all the child script? That would be ridicolous

polar acorn
#

So it looks like it doesn't affect child classes. There might be a way to do that but I don't know it

pallid nymph
#

You need to pass some param to the CustomEditor attribute if I recall correctly

tender stag
#

my terrain is going to be curved

polar acorn
sly wasp
#

Hello
https://pastebin.com/rcu9LVQy
I have a script here that adjusts the UV of a white vertex color on the mesh (I have the mesh as one object to save resources, making the eyes white in the vertex color helps the script target which part)
The only problem is that it scrolls on the UV weirdly on the eye instead of tracking the bone

tender stag
#

like that

#

right?

#

he still jumps randomly

polar acorn
#

Seems like it

tender stag
polar acorn
tender stag
#

alright

polar acorn
#

especially if your jumps are away from the ground instead of straight up

frigid sequoia
#

Thxs

tender stag
sterile moon
#

I'm trying to figure out how to get the layer system for the camera to work to make it look like carried objects are not clipping, but I use URP so I dont see how its doable

night mural
frigid sequoia
#

I cannot like... attach a variable to a string in the inspector like this right?

tender stag
#

that was with this bit of code

#

im not sure why my character was bouncing

#

when walking up a slope

frigid sequoia
#

You have to send a Raycast down and detect the normal of the slope and change the force vector to work on that direction

tender stag
#

i have that

#

thats what slopeMoveDirection is

frigid sequoia
#

If slopes are not neccesary I would HIGHLY encourage you to avoid them

tender stag
#

thing is i have 90% of them done

frigid sequoia
tender stag
#

since i switched my method of clamping the speed

#

its been happening

frigid sequoia
#

I think you are just trying to clamp velocity in the object axises, while the force is been applied in the normal vector

#

I mean, I would clamp the speed overall and then, in the next step ,add the Y axis force that doesn't need to be clamped for the jump

teal viper