#💻┃code-beginner

1 messages · Page 491 of 1

cyan crag
#

yea

#

thats what i thought

near wadi
#

you'll have to open the scene again once it reloads. do not worry, it is not lost or anything

cyan crag
#

ima go to bed

#

i got a soccer game tomorrow

obsidian granite
#

i'm constantly adding a force to an object, yet it's not constantly speeding up. i'm confused because i thought constant force = constant acceleration = constant speed up?

rocky canyon
#

Check the Drag property on your Rigidbody. If it's not zero, the force will continuously be counteracted by drag, which might limit how much the object speeds up.

#

but you are correct.. constant force will continually speed up, once it breaks thru friction

full coral
#

I made a trail renderer attach to the mouse, similar to fruit ninja – where it only slashes on clicks – but it only works in orthygraphic camera (because it omits the z-value to create the trail). But the problem is it ONLY works in orthographic camera. is there a way to get it to work with perspective camera? I am making a 3d game in unity and i am trying to use it to attack 3d monsters to progress through the stage

#

Im rusty with unity, i normally use ue, but i can clarify better if i need to

atomic holly
#

Hello,
I don't understand when I declare the variable and assign it the instance, when I call the input function, it doesn't work but call directly with the instance, it works well

using UnityEngine;
using UnityEngine.InputSystem;

public class DialogueTrigger : MonoBehaviour
{
    [SerializeField] private Dialogue dialogue;

    private bool isInRange;
    private DialogueManager dialogueManager;

    private void Awake()
    {
        dialogueManager = DialogueManager.instance;
    }

    public void InputDialogue(InputAction.CallbackContext context)
    {
        if (isInRange)
        {
            //dialogueManager.StartDialogue(dialogue);
            DialogueManager.instance.StartDialogue(dialogue);
        }
    }
#

When I use the dialogueManager variable, I have this error ```c#
NullReferenceException: Object reference not set to an instance of an object
DialogueTrigger.InputDialogue

full coral
north kiln
#

!code

eternal falconBOT
languid spire
cerulean tulip
#

How do I learn without being in tutorial hell

languid spire
topaz mortar
# cerulean tulip How do I learn without being in tutorial hell

depends on how much you already know
it's usually recommended to do 3 simple tutorial games so you learn what unity can do
then after that just think of a simple game you want to make, keep it short & small, then build your game, you can watch tutorials, but don't follow them anymore, watch first, then do yourself after you're done watching the tutorial, if you just keep following tutorials you will never actually learn how to do it

#

tutorial hell is really not a thing unless you allow it to be

cerulean tulip
#

Is that tutorial hell?

topaz mortar
#

you need to understand code, not remember it

#

you use tutorials to understand how you do something
then you use your own brain and look up how tools & functions work to use them yourself

#

for example, you want to spawn 10 monsters
you go find a tutorial that shows you how to spawn monsters, the tutorial uses a for loop
it's critical that you do not learn that for loop by hard or copy/paste it, once you know you need a for loop, you close the tutorial
then you open google and look up how a for loop works in C# and you write it yourself, that's how you learn

#

the reason you do it like this is because the next time you need a for loop for something else, blindly copy/pasting it or typing it from memory won't work, since you don't need it for exactly the same thing
you need to understand why you're using a for loop, what that for loop does and how it works
so the next time you need one, you know what it's for and how to use it

eternal needle
# cerulean tulip But what if I just remember the code?

if you dont understand the fundamentals, you'll struggle the entire journey spending a day for something that should be an hour of work.
think of even like learning math. for example if you're asked to solve the area of a circle you're not just gonna remember "radius 1 means its pi" and so on for every number. you would learn the actual equation

#

if you understand what the code does, you can apply it elsewhere

willow scroll
#

I remember watching tutorials some time ago, and trying so hard to remember the shown multiple times line of code "text.SetText(scoreText.ToString())". It's much better if you understand how this code works, rather than what it does

static wasp
#

guys, is there a way to make isTrigger work on specific objects only, and not the others?

#

i was told to ask it in this channel

near wadi
#

show the code you are using for the trigger at this point

static wasp
#

i want the isTrigger off, except for a certain group of objects

near wadi
#

.. this is something i would do in code. maybe there are layers, or some other way, but i am not aware of it

static wasp
static wasp
near wadi
#

well, pretty sure it is. i think you just do not grasp the basics yet?

static wasp
#

in that discussion, he wants to check if it triggered objects, i don't want it to check, i want it to make the collision isTrigger for some objects only

#

or the opposite

#

i want the player to have isTrigger while colliding, but not with the floor

near wadi
#

ok, i think it is going to trigger (barring layers or some other technique) on anything that it is capable of triggering with. then, what you want to control is what it does with that info. lets say your trigger opens a door. well, then you could use if statements in your code to say, 'pseudocode' if that thing that just trigger the trigger was the thing that i Want to be able to trigger the trigger that Open the Door. else, Do Nothing, or something else

#

beyond that, i will leave it to people who know more than me, and your own googles

static wasp
near wadi
#

no. a trigger is a trigger. who cares what triggers it. but if the thing that registered as triggering it is not the thing you want, then tell the trigger to do nothing

#

or i am just not understanding what you are trying to accomplish

static wasp
near wadi
#

Multiple colliders perhaps then? i do not think it can be both, by my experience there is very limited. and probably back to the regular chat room, since yeah, this did not go the code route as expected

static wasp
topaz mortar
#

what's the usecase anyway for needing a trigger? why not just use the collider functions?

#

another option is to turn off gravity for that object

static wasp
topaz mortar
#

so just add a secondary empty object with a trigger collider

static wasp
#

oh wait

topaz mortar
#

you keep the original collider?

static wasp
#

i think i understand what you mean

topaz mortar
#

but I don't understand why you don't just use the collision functions instead of the trigger functions then?

static wasp
#

do you mean like, make the first object ignore collisions for specific objects, but the second object which is at the same location acts as a trigger?

#

is that what you mean

topaz mortar
#

if that's what you need? I don't know what this is for

#

and it seems like bad design

#

why do you need a trigger instead of a collision?

ruby python
#

Just wondering, what is the virtue/benefit (If any), of using a list of Transforms over using an array of Transforms?

static wasp
short hazel
topaz mortar
#

use a collider, remove all the layers you don't want it to collide with

ruby python
short hazel
#

Yes

ruby python
#

Okay, cool. Thank you 🙂

static wasp
# topaz mortar so use layers

forgot to mention that the objects that move through it also collide with it, just those objects are still able to move through it

topaz mortar
#

so yeah, just keep the regular collider, remove everything except the floor
then add a secondary trigger collider

static wasp
topaz mortar
#

why would it be slow?

static wasp
#

might cause some lag

topaz mortar
#

what is many?

static wasp
#

maybe more

#

i still don't know exactly how much

topaz mortar
#

hmm, really depends on what you're doing, could be fine
you may want to look into #1062393052863414313

static wasp
topaz mortar
#

I'm building a 3d tower defense game.
I have a hex grid, monsters use A* to find their way to the target walking over the hexes
When I click a hex, I build a tower on it, making it unwalkable
What's a good way to make all my monsters recalculate the path?
Is the event system a good usecase for this? Is it fast enough?

steep rose
#

if you are using the unity built in AI nav you can do that built in

eternal needle
topaz mortar
#

hmm need to think about it some more
each monster can be at different location, so they might have different paths after a tower is built
so I need a way for each monster to individually calculate their new path

#

My idea was to draw a main path and then recalculate that when a tower is placed
Monsters will then just try to find the quickest path back to that main path

#

What I'm asking for is how to have each individual monster recalculate their path when I place a tower

#

I was thinking of throwing an event when I place a tower
All monsters would be listening for that event and recalculate their path when it's triggered

willow scroll
#

Throwing an event is the best way to do it

eternal needle
cerulean tulip
steep rose
cerulean tulip
steep rose
#

thats the second

#

close

short hazel
#

That's the third???

steep rose
#

unless an array counts 0

short hazel
#

Indices start at 0

steep rose
#

forgot that 😂

#

shouldnt have used an array

cerulean tulip
eternal needle
cerulean tulip
#

Oh alright

cerulean tulip
#

public?

eternal needle
eternal needle
#

And I dont use trig at all really, everything I've done can be solved using built in vector or quaternion math

cerulean tulip
#

I meant to ask do you know any good trig tutorials?

cerulean tulip
eternal needle
#

I dont know what you mean. A vector is a vector

steep rose
#

vector "math" just uses a vector, so it is a vector

pulsar meteor
#

how to hide unhide a canvas with a bool

topaz mortar
short hazel
willow scroll
cerulean tulip
willow scroll
#

Are you referring to the mathematical version of vector?

cerulean tulip
willow scroll
#

In mathematics, as previously mentioned, since vector is written as AB, with the start at A and end at B, you can clearly read its direction. Unity's Transform doesn't have the direction property, although it has forward, right and up to represent its direction based on its rotation

cerulean tulip
#

nvm I think I'm just confusing my self

#

It's just where something is pointing right?

willow scroll
pulsar meteor
#

how can i get a varible from a other script it is public

willow scroll
cerulean tulip
willow scroll
pulsar meteor
#

how

cerulean tulip
willow scroll
#

Google how to access variables from another classes in C#

pulsar meteor
#

public float level; this is the var i already have it

#

i cant find it on google

cosmic dagger
cosmic dagger
pulsar meteor
willow scroll
#

If it's inside of the MonoBehaviour, you need to either make is a Singleton, if it's some kind of Manager (e.g. GameManager), make it static, this way no object reference is needed, or get the reference to your MonoBehaviour in another class by e.g. serializing it in the inspector or getting the Component from another object

cerulean tulip
#

And it will rotate if the player rotates?

willow scroll
#

From my experience, most frequently, non-singleton scripts don't have variables to be accessed by other scripts

languid spire
cosmic dagger
cerulean tulip
cosmic dagger
cerulean tulip
sharp sigil
#

guys is there a way for me to pause my script for 5 seconds? like the script doesent do anything for 5 seconds

languid spire
sharp sigil
#

but i have the script do nothing for 5 secs how do i explain that

steep rose
#

coroutine

#

use one

cosmic dagger
languid spire
#

to start with are you talking about a script or a method on a script?. Little details like that

sharp sigil
#

thank you

#

a whole script

languid spire
steep rose
#

you can pause sections

sharp sigil
#

ill try the coroutine

steep rose
#

you can make another script to turn off the script using a coroutine

#

if you want, but theres no need

languid spire
#

even then public methods are still executable

cosmic dagger
# sharp sigil a whole script

you'll need a bool variable to flip in order to stop execution . . .

-# NOTE: you can only stop Update methods from executing; any outside script calling a public method or accessing a public member will still take place.

languid spire
#

So you would need to add a bool into every method to stop it's execution

restive ridge
#

anyone know good beginner tutorials for unity c#

ivory bobcat
eternal falconBOT
cosmic dagger
restive ridge
willow scroll
eternal falconBOT
#

:teacher: Unity Learn ↗

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

pulsar meteor
#

how can i change that text in the code

languid spire
pulsar meteor
#

my unity disconnected from my unity

#

!ide

eternal falconBOT
pulsar meteor
#

why isdnt it working

steep rose
#

are you trying to change text on the TMP text or are you trying to change the gameobject name?

pulsar meteor
steep rose
#

click on the TMP text in the heirarachy and just change it

pulsar meteor
#

with code

#

i need to chane it more then 1 time

steep rose
#

use text.text = "something";

#

i believe thats how you do it

#

but i suggest you !learn how to use unity

eternal falconBOT
#

:teacher: Unity Learn ↗

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

pulsar meteor
#

it doesnt work i tested it already

#

it was TextMeshProUGUI

steep rose
#

what was?

pulsar meteor
#

TextMeshProUGUI

steep rose
#

you have to give the class of the variable TMP_Text

#

not TextMeshPro

cyan crag
#

and its still not working

#

should i restart?

vocal marlin
#

How do you make a grid layout group not start in the exact corner but offset a little

#

if that's even possible

torn marlin
#
public class Fruit : MonoBehaviour, IGrabbable
{
    public event EventHandler onThisGrabbableCollected;
    void OnCollisionEnter2D(Collision2D other)
    {
        if(other.collider.TryGetComponent(out Player player))
        {
            player.GrabbableHandle(this);
        }
    }

    public void Collect()
    {
        StartCoroutine(OnGrabbableCollectedCoroutine());
    }

    private IEnumerator OnGrabbableCollectedCoroutine()
    {
        onThisGrabbableCollected?.Invoke(this, EventArgs.Empty);
        yield return null; //somehow managing to wait until the animation is played using the above invoked event
        Destroy(gameObject);
    }
}```I have two scripts, one for logic and one for visuals attached to the same object, I want to call the animation playing method in visual script by invoking the onThisGrabbableCollected event but, the catch is the fruit will immediately be destroyed as soon as the animation even starts to play
#

If there is a better way than using Coroutines, I will be glad to hear!

cosmic dagger
torn marlin
#

oh I deleted the message

#

sorry ;)

cosmic dagger
#

@torn marlin a coroutine will work as well, but you'd need to know the length of the clip to yield the coroutine. an animation event will automatically call the (public) method on the script when the time reaches the event . . .

swift elbow
# cyan crag ok so now i just cant test my game

If deleting library didn't help, I would try making a new project in a newer unity version and testing that. Then you can just import all of your assets from your old project into your new one

cyan crag
torn marlin
cosmic dagger
#

animation events are simple and easy to use. i'd try that first . . .

torn marlin
#

I most of the times get in the headache of refactoring which takes away all the fun of programming a game

#

sed

#

lol

#

both the scripts are in same gameobject btwnotlikethis

#

uhh but I still need to return the total time of animation

cosmic dagger
# torn marlin how do you refactor your code?

i only refactor when i need to, but my style is a bit different. i like building systems and mechanics—or at least, learning how to. it's use a modular (component-based) approach when creating scripts called composition. you stack individual scripts to create the entity . . .

torn marlin
#

thanks!

cosmic dagger
cosmic dagger
# torn marlin

i would subscribe to events in OnEnable and unsub in OnDisable . . .

torn marlin
#

now it will be better to use an action rather than an event

cosmic dagger
#

grabbing internal references (components on the GameObject) is best done in Awake and grabbing external references (components from other GameObjects) is best done in Start . . .

torn marlin
#

I really didnt knew that difference

cosmic dagger
torn marlin
#

I always had this in mind that awake and start had something to do with call time difference

pulsar meteor
#

!code

eternal falconBOT
pulsar meteor
modest dust
#

Elaborate.

pulsar meteor
modest dust
#

What exactly isn't working?

#

Which piece of code?

pulsar meteor
#

the e interact on the item doesnt do anything

modest dust
#

And what are you trying to do and what is the result?

pulsar meteor
#

that de text changes from the canvas

modest dust
#

Does the Interact() method from NPCInteractable get called?

pulsar meteor
#

i think so

modest dust
#

Don't think so, check it

pulsar meteor
#

if (collider.TryGetComponent(out NPCInteractable npcInteractable))
{
npcInteractable.Interact();

            }
modest dust
#

Add a Debug.Log into it and confirm it

pulsar meteor
#

it does get called

#

the first text works but the second doesnt work

modest dust
#

Is the uiText located on a GameObject under Canvas1?

#

Because you're explicitly setting it inactive one line above changing the text

pulsar meteor
#

i think i found it

modest dust
#

And?

pulsar meteor
#

but i cant ad scripts

#

[SerializeField] private ItemInteract itemInteract; this is that little code

modest dust
#

Obviously, you can only add instances of this class, not scripts

#

Same as with your Canvas1, Canvas2 and uiText

pulsar meteor
#

how can i ad scripts

modest dust
#

You cannot.

pulsar meteor
#

oke

modest dust
#

What you're looking for is referencing a specific class instance

#

If it's somewhere on your scene / is a prefab and always the same, then just drag it into the field

#

Otherwise think of a method to provide your NPCInteractable instance with an appropriate instance of ItemInteract

serene mango
#

Hi! I've got an question that I'm not sure about how to solve it the best. I have an chunk generation for my game that works async with the unity job system. Once a chunk is finished generating I instanciate all the corresponding gameobjects in update() the next time it gets called. However, Instanciating multiple chunks at the same time causes some major laags in that frame because instanciating is very expensive. My approach would be to use coreroutines to only generate one chunk at a time. My question is, is there a way to automatically determine how long the current frame took and pass depending on the frametime the work to the next frames? So as many objects get instaciated at the same frame as possible without risking to cause laags?

gilded stag
#
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class HoleScript : MonoBehaviour
{
    [SerializeField] GameObject ball;

    // Start is called before the first frame update
    void Start()
    {
        ball.SetActive(true);
    }

    // Update is called once per frame
    void Update()
    {


        if (Physics2D.Raycast(transform.position, Vector2.down, 0.51f, LayerMask.GetMask("Hole")) && ball.activeInHierarchy)
        {
            ball.SetActive(false);
        }
        if (!ball.activeInHierarchy && Input.GetKey(KeyCode.Mouse0))
        {
            ball.transform.position = new Vector2(0, 0);
            ball.SetActive(true);
        }
        Debug.Log(ball.activeInHierarchy);
    }
}
#

im trying to get a ball to spawn in when the mouse clicks after it goes in the hole in a golf game

#

the ball going into the whole works find but then i can get it to spawn back

modest dust
#

If that script is on the ball then it is also obviously deactivated alongside the ball

neat bay
#

Has anyone got htis problem before when enterling playmode? and if so, does anyone know how to fix it?

#

It was completely out of the blue

#

i swear i haven't done anything to cause this

modest dust
#

Explain "doesn't work"

pulsar meteor
#

i dont know what but it doesnt sent the singnal to the other classes

#

if (collider.TryGetComponent(out NPCInteractable npcInteractable))
{
npcInteractable.Interact();

#

this 1

modest dust
#

Then debug it

pulsar meteor
#

i did i know the probloem dont now how to fiks the problem

modest dust
#

Also consider printing out text that actually means something

#
foreach (Collider collider in colliderArray)
{
  Debug.Log($"Player interaction detected {collider.gameObject.name}");
  ...
}
#

Check if it's detected first

#

If it is, check if the detected object actually has NPCInteractable component on it

#

If it doesn't, check if it has a detectable collider

pulsar meteor
#

the with thing is my npc

modest dust
pulsar meteor
#

yes

modest dust
#

And it's not detecting it I guess

pulsar meteor
#

wait in the wrong spot

modest dust
#

So is it detecting it or not?

pulsar meteor
#

i get the error only by the npc

#

and yes

modest dust
#

Yes, because your itemInteract is null.

pulsar meteor
#

but i dont now wats is wrong with my script

#

then

modest dust
#

Exactly what I just said

pulsar meteor
#

the npc is detected

modest dust
#

You're trying to call CanGetItem() on itemInteract but itemInteract is not assigned to anything

pulsar meteor
#

yes it is

#

(out NPCInteractable npcInteractable

modest dust
#

Dear lord

#

Are you even reading?

#

I'm talking about itemInteract, not npcInteractable

#

You even sent a screenshot of the field being unassigned earlier

pulsar meteor
#

yea i am reading its just i am trying fikxing myselff also

modest dust
#

Then start with assigning that field to something

pulsar meteor
#

to what i cant do the script and i cant at the item

modest dust
#

Screenshot the item you're trying to drag into that field

pulsar meteor
#

just the only thing i can at

modest dust
#

Seeing the inspector would be nice.

pulsar meteor
modest dust
#

Then drag that into the field

pulsar meteor
#

i did

modest dust
#

Show it

pulsar meteor
#

now it worked

#

cinda

modest dust
#

Meaning?

pulsar meteor
#

the text doesnt change but i think i know how to fiks

steep rose
#

i told you how to change it

pulsar meteor
#

yea i know

steep rose
#

did you follow what I said?

pulsar meteor
#

but there i accedently delted the function

steep rose
#

deleted what?

pulsar meteor
#

the change text function

steep rose
#

Text.text = "something";?

pulsar meteor
#

yea

steep rose
#

then write it again?

#

im not sure what the issue is

#

if you deleted it, rewrite it

pulsar meteor
#

i am doing that

steep rose
#

good

ruby python
#

Could someone please take a look and see if they can see where I'm going wrong please? Cause this is driving me nuts, been stuck on it for about 6 hours now. 😦

https://hastebin.com/share/uhocanarow.csharp

https://streamable.com/885x5s

The 'forward' part of the piston (bit that should be attached to the wheel(s) is losing it's position (staying static in world space by the looks of it), which causes the 'root' part of the piston (part that's connected to the body of the rover)

Watch "2024-09-21 16-30-27" on Streamable.

▶ Play video
pulsar meteor
#

why doesnt this work

toxic cloak
#

what dosent works

ruby python
pulsar meteor
#

first time it works the second time it doesnt and it is beacause my level shit doesnt work

#

i fikset it nerver nind

drowsy oriole
#

how do I make a list of normal gameobjects

rich adder
#

you add GameObject to the type for List

drowsy oriole
#

like this?

rich adder
#

like wat?

drowsy oriole
#

private List<GameObject> Maps;

languid spire
drowsy oriole
languid spire
#

exactly, if you dont know how to use something go and read the docs, that is what they are for

drowsy oriole
#

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

public class MapSwappingTrigger : MonoBehaviour
{
private List<GameObject> MapLeaving;
private List<> MapJoining;

private void LeaveMap()
{
    void OnTriggerEnter()
    {
        MapLeaving.SetActive(false);
    }

}

}

drowsy oriole
#

I'm literally asking for help

rich adder
#

what is this ? List<> MapJoining;

#

List always wants a T List<T>

drowsy oriole
#

idk I forgot how to do gameobject lists

rich adder
#

you literally have it done above it

drowsy oriole
#

no, it gives me errors

#

it says they're wrong

rich adder
#

the one above it would not give you errors no

steep rose
drowsy oriole
rich adder
steep rose
rich adder
#

always need a loop to do something in each one

drowsy oriole
rich adder
steep rose
#

foreach loop

#

realized while loops dont do that 😅

drowsy oriole
#

idk how to do that i'm dupid

rich adder
#

for loop is just a fancy while loop

steep rose
#

nice to know

rich adder
#

actually read this page it shows all you need to know

steep rose
#

i could actually use that page 😂

rich adder
# steep rose nice to know
 int i = 0;
 int items = targets.Length;
 while (i < items)
 {
     var target = targets[i];
     i++;
 }
or 
 while (i++ < items)
 {
     var target = targets[i];
 }```
#

for loop it just basically makes everything inline

steep rose
#

im just starting to learn loops and arrays due to me makng my own AI for unity game

#

so im not the best but i kinda understand them

languid spire
rich adder
#

ah yes I always forget we can do that

rich adder
#

imagine 100 crystals/coins pickup items spinning... now you have 100+ update loops running (assuming they're near by player)
Thats insane
Instead of 1 update loop that rotates all of them, all you need to offset each one beginning rotation so they all spin with variance

steep rose
#

when i set up the basic AI movement using arrays and such to pick a point randomly, i was estatic

#

very fun to mess around with

rich adder
#

yeah very good usecase is also AI for almost all things lol

#

valid points / targets, actions

steep rose
#

yeah currently i have a random int and it uses that int to give the Bot a position to rotate to and to go too

#

im thinking of making it so if the point is higher on the y axis than a threshold and the current position of the Bot, then make the Bot jump to reach the point

wanton canyon
#

Im trying to filter for specific enum types, but it's giving me a console error. How do I...?

steep rose
#

well whats the error

wanton canyon
#

I got it :D

ruby python
versed zinc
#

!code

eternal falconBOT
versed zinc
keen dew
#

Stuck how?

languid spire
versed zinc
versed zinc
languid spire
versed zinc
keen dew
#

the reloading state is on

versed zinc
keen dew
#

apparently it does

versed zinc
#

uh why?

keen dew
#

Show the GunData script

versed zinc
#
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

[CreateAssetMenu(fileName = "Gun", menuName = "Weapon/Gun")]
public class GunData : ScriptableObject
{
    [Header("Info")]
    public new string name;

    [Header("Shooting")]
    public float damage;
    public float maxDistance;

    [Header("Reloading")]
    public int currentAmmo;
    public int magSize;
    public float fireRate;
    public float reloadTime;
    [HideInInspector] public bool reloading;
}```
languid spire
#

ah, your SO is being updated when you play in editor. you need to reset it's values

versed zinc
#

so I just set it in start to 0?

keen dew
#

The SO shouldn't store the reloading state at all, it should be in the gun script

versed zinc
#

its just the data

keen dew
#

yeah and the state is not data

versed zinc
#

ok ill try rn

keen dew
#

Same with currentAmmo

versed zinc
#

ok

#

done

#

ill try to play rn

versed zinc
full coral
#

im trying to format code for cs in discord but whenever I do the and then the cs, it just treats the cs as normal text and doesnt format it

silk night
#

!code

eternal falconBOT
full coral
#

ya i got that, just the cs part isnt working for me

silk night
#

its not as good as your ide

#

but does some basic highlighting

#
        private async UniTask Shoot()
        {
            _fxParticle.Play(true);     
            await UniTaskTools.AwaitSeconds(0.5f, CancellationToken, awaitCancelBehaviour: UniTaskTools.AwaitCancelBehaviour.CancelAndStop);
            _viewPool.Despawn(this);
        }
full coral
#

example:

blarg
#

idk what im doing arong

#

wrong

silk night
#

the cs needs to go right after the ` things

polar acorn
silk night
#

not in the next line

full coral
#

ya i was doing that

upper forge
#

How do i get a gameobjects position and then set a different gameobject to that position expect make the x vale a little behind and not directly on top?

full coral
#
private void
polar acorn
full coral
#
public void Test(){
  int x = 0;
}
#

why does that work, i feel dumb

silk night
polar acorn
#

private void as the entirety of a line is not code

rich adder
full coral
#

i have c# code i took from VS but its not working

polar acorn
full coral
#

nvm

#

i made a fruit ninja tutorial for a blade slashing in Unity3D, but it only works with a orthographic camera and i was wondering if there was a way to get it working with perspective camera

eternal falconBOT
silk night
#

please use one of the paste sites 😄

polar acorn
#

You put cs on a different line again and also that definitely should be in a bin

full coral
#

yea i got it working earlier, then tried again and its not working, sorry

#

i realized and deleted it

upper forge
polar acorn
#

Literally, with +

#

add whatever displacement you want

silk night
full coral
#

sorry for the spam

upper forge
#

So when i do this code and subtract some on the x to make it go behind it puts the dog too far down and not level like the first picture

rich adder
upper forge
balmy dagger
#

i am a coding master now

#

the C# wizard

languid spire
upper forge
#

ohh i would just do 0

rich adder
balmy dagger
#

after spending an hour and a half reading libraries and docs i got the look script to work and the move script to work

#

this stuff easier than making roblox games though

#

C# to me makes more sense than La

#

Lua

#

except for like vectors and stuff

cosmic quail
balmy dagger
#

using System;
using System.Collections;
using System.Collections.Generic;
using JetBrains.Annotations;
using UnityEngine;

public class plrCharCam: MonoBehaviour
{
public GameObject plrCharCamera;
public float vertRtLim = 90.0f;
public float verticalRotation = 0.0f;
public float lookSens = 90.0f;
void Start()
{
//Check
Debug.Log("plrCharCam working.");
Cursor.lockState = CursorLockMode.Locked;
}

void Update()
{
    //Get Axis
    float xAxis = Input.GetAxis("Mouse X") * lookSens;
    float yAxis = Input.GetAxis("Mouse Y") * lookSens;

    transform.Rotate(Vector3.up * xAxis);
    verticalRotation -= yAxis;
    verticalRotation = Mathf.Clamp(verticalRotation, -vertRtLim, vertRtLim);
    plrCharCamera.transform.localRotation = Quaternion.Euler(verticalRotation, 0, 0);

    
}

}

#

second one unfinished because im adding jumping

upper forge
cosmic quail
#

what is the system.security.cryptography for?

#

why do your class names start lowercase

rich adder
cosmic quail
#

i thought you were a master

balmy dagger
#

i am a master

#

code works = master

rich adder
#

code works until it doesn't then you question your sanity and skills

#

wait till you get imposter syndrome

balmy dagger
#

wait bruh what is the security thing

#

Contains the common language runtime implementation of the Authenticode X.509 v.3 certificate. This certificate is signed with a private key that uniquely and positively identifies the holder of the certificate.

#

does bro know my maiden name and location 💀

rich adder
#

you added that , remove the using

cosmic quail
#

why did you add that?

balmy dagger
#

i didnt add that

#

it was default

rich adder
balmy dagger
#

all i added was the main code

languid spire
rich adder
#

wherever you copied it from had that or VS deduced it somehow from a class..

balmy dagger
#

i didnt copy anything

#

i wrote it

languid spire
#

bull shit

balmy dagger
#

on my life

#

i didnt copy it

#

i read libraries and docs and wrote it

#

i copied a couple lines in the main script

#

but not that

languid spire
#

that is standard code from 99% of beginners tutorials

balmy dagger
#

well idk lmao

#

i didnt add that

rich adder
balmy dagger
#

and i didnt copy it

rich adder
#

which libraries would that be

balmy dagger
rich adder
#

we didn't need the whole pastefest could've just said where

balmy dagger
#

just giving links

cosmic quail
languid spire
balmy dagger
#

im so confused now

#

why did it use JetBrains too

languid spire
#

because YOU told it to

rich adder
#

we weren't there how should we know

balmy dagger
#

is there like a reason it would do that by default?

rich adder
#

if you paste code visual studio tries to find a matching class / namespace for that class

cosmic quail
languid spire
#

not by default, these thing happen when people who dont know how to code dont pay attention to what they are doing

balmy dagger
#

bruh 😭

#

i didnt copy code or anything

rich adder
upper forge
#

Got it working, but what would be the reson that the animations isnt working after it gets teleported?

steep rose
#

by accident

rich adder
rich adder
steep rose
#

weird 😅

balmy dagger
#

i downloaded like icons for vs code earlier

rich adder
#

sounds productive

balmy dagger
#

idk i looked it up and it said extensions or copying code

steep rose
#

he could also have gotten weird things from a suspicious VS download

#

or another program downloading VS

rich adder
balmy dagger
#

im gonna make a fresh file and see if it adds it

steep rose
balmy dagger
#

now it doesnt add it kekwait

ruby python
#

I just want to preface this by saying, I get that people get busy etc. and people may not have an answer.......but.....

I haveta ask, have I done something wrong? Is there something wrong with the way I ask questions etc. ?

I only ask because the last few questions about problems that I've asked (apart from a simple one this morning), have gone completely unanswered.

I get that I may be over-reacting, but if I'm doing something wrong, I'd prefer to know. 😕 (The questions I've asked recently have been long, but that's just to try and provide as much info as possible. 🙂

balmy dagger
#

a purple monkey is probably going to pop up on my screen soon

cosmic quail
steep rose
#

you didnt do anything wrong though 🤔

languid spire
balmy dagger
#

i suggest thugging it out and learning to code

cosmic quail
rich adder
steep rose
full coral
#

I made a fruit ninja mechanic but it only works with orthographic camera and not perspective camera and I dont know how to get it to work with perspective

ruby python
#

Ah crap, that one is my bad, I thought I'd deleted the other one.

languid spire
#

use a paste site

full coral
rich adder
#

also this ^

full coral
rich adder
# full coral can you ellaborate?

you zerod out the Z already I see that should help already, but because propsective you're dealing with depth / frustum projection

ruby python
full coral
#

i know how to do it in unreal but struggling with unity

languid spire
upper forge
full coral
balmy dagger
#

give me 2 numbers below ten

#

a = int(input("enter a number"))
b = int(input("enter a number"))

def whichone():
if a + b > 10:
return "nuggets"
else:
return "spaghetti"

whichone()

#

it will decide what i ear

#

eat

ruby python
rich adder
balmy dagger
#

i used chat gpt

#

im gonna eat nugget s

full coral
languid spire
rich adder
balmy dagger
#

wait ididnt add print lmao

balmy dagger
#

its code related

#

is it not

rich adder
#

Its not a unity related code question/topic . no

balmy dagger
#

allergic to fun

steep rose
#

Ask questions and discuss anything related to beginner coding concepts in Unity

#

for unity only

rich adder
balmy dagger
#

no memes in general chat 🤓 👿

rich adder
#

better me telling you than a mod believe me lol

frosty hound
#

Enough noise already.

steep rose
frosty hound
#

Move along @balmy dagger

balmy dagger
#

move along pal, dont make the alpha angry 👿

frosty hound
#

!mute 1062436270581743616 14d spam

steep rose
#

rip

eternal falconBOT
#

dynoSuccess mbmma._. was muted.

steep rose
#

i knew that was coming

ruby python
#

Okay, here's a new video of the issue with Logs.

If you watch the video, at the end I go through the affected objects. The logs say that the positioning is correct etc. but the inspector and the scene view tells a different story. I'm really confused as to what's happening.

(Apologies for the bit of faff before I switch to 'local' mode, Unity keeps defaulting back to global.

https://streamable.com/2e4wdh

Watch "2024-09-21 19-52-13" on Streamable.

▶ Play video
#

I've split the code up a bit (seperated out the input controls and the suspension control into seperate scripts for later)

Here's the suspension script.

https://hastebin.com/share/ediqinadam.csharp

ivory jasper
#

im kinda confused on how to use OnTriggerEnter2D... why is this not working?

#

this is the code

swift elbow
rich adder
ivory jasper
#

ohh oops

#

thx

ruby python
#

Okay moving on from the suspension thing cause it's driving me nuts.

However I have a new question.

A while ago I was given this code to use for an interaction system...I'm struggling to remember by whom I was given it by, but I think it was @rich adder

public class Interactable : MonoBehaviour
{
    public UnityEvent OnInteract;

    public void Interaction()
    {
        OnInteract.Invoke();
    }
}

My question is, has something changed with the way Unity does events in c# because this is no longer working that way I remember (I could be remembering wrong and missing something completely obvious, but it no longer works in my old project where I first used it. 😕

rich adder
ruby python
#

No, my bad, wasn't navarone, it was @wintry quarry

ruby python
#

Yep, me being a collosal part of the male anatomy. lol. Sorry.

Think it's time for bed.

tawny quarry
#

Hello, i need help i try to learn Unity i make a tower defense but i can't move the ennemy to my tower because is not assigned but i can't assigned it, if sombody can help me i am good to to a voice chat

cyan crag
#

im trying to fix this

wise spoke
#

I dont know if its for beginner, but my methods dont work when I build my game but they are perfectly fine in the editor

finite dove
# cyan crag can someone tell me why my cylinder isnt appearing when i click a button like a ...

do you have a log shown? for Debug.Log("Cylinder enabled.");?

       if (cylinder != null && spawnPoint != null)
        {
            // Enable the cylinder and move it to the spawn point
            cylinder.SetActive(true);
            cylinder.transform.position = spawnPoint.position;
            cylinder.transform.rotation = spawnPoint.rotation;
            isCylinderEnabled = true; // Set flag to prevent re-activation during cooldown
            Debug.Log("Cylinder enabled.");
        }
        else
        {
            Debug.LogWarning("Cylinder or SpawnPoint is not assigned.");
        }
cyan crag
#

no i dont

#

its prob the colliders?

finite dove
#

or even does this function is called? EnableCylinder();

if ((other == leftHandCollider || other == rightHandCollider) && !isCylinderEnabled)
        {
            if (other.gameObject == cubeButton)
            {
                EnableCylinder();
            }
        }
cyan crag
#

i only know a little coding

#

thats all

finite dove
#

ok when you run the games does one of this debug. is shown on your console

Debug.LogWarning("Cylinder or SpawnPoint is not assigned.");
Debug.Log("Cylinder enabled.");
cyan crag
#

No

#

none of the debug logs are shown

finite dove
# cyan crag none of the debug logs are shown

ok then we can add another debug on the collider.

// Example
Debug.Log($"Other : {other.name}")
if ((other == leftHandCollider || other == rightHandCollider) && !isCylinderEnabled)
        {
            if (other.gameObject == cubeButton)
            {
                EnableCylinder();
            }
        }

on this part of code, Add Debug for this

other.name 
and also add this 
!isCylinderEnabled
cyan crag
#

ok

#

i added a few stuff so

#

its not done yet tho

finite dove
# cyan crag ok

as long as you dont add a new logic/validation that related to your problem in your code that you shared earlier it's fine.

cyan crag
#

wdym?

finite dove
cyan crag
#

ok

finite dove
#

yes correct, now when you run, can you show me the debug result

cyan crag
#

yes

#

lemme test rn

#

ill send pics of the debug logs

#

no debug logs

finite dove
cyan crag
#

all i get

finite dove
# cyan crag

errmm is this for AR/VR thing? i havent got to playaround with it. so i dont know how to answer it.

cyan crag
#

im using that

finite dove
# cyan crag this

yes im aware and i dont know how to answer it, cause i dont have any experience with it UnityChanOops

cyan crag
#

frick

finite dove
# cyan crag frick

but i assume it's same like 2D or 3D one, then you need to make sure your gameobject collider works first. the one that have MyActor Script. once you do that then make sure the Debug Log shown on your console. UnityChanCelebrate

cyan crag
#

should i do the soda machine after cause im making like a chipotle type of game

steep rose
cyan crag
#

ok my bad

steep rose
#

someone that is more knowledgeable in this type of stuff will help you better than we can 😅

cyan crag
#

ok sorry

steep rose
#

you're not in trouble, dont be

cyan crag
#

ok

frank flare
#

so uh lol when I try to move the car forward it just flips

private Rigidbody otherPlayer_rb;
    public Rigidbody Wheel1;
    public Rigidbody Wheel2;
    public Rigidbody Wheel3;
    public Rigidbody Wheel4;

    void Start()
    {
        // otherPlayer_rb = GetComponent<Rigidbody>();
    }

    public void move(float speed)
    {
        if (Wheel1.angularVelocity.magnitude < 2) {
        Wheel1.AddRelativeTorque(Vector3.right * speed * 100f);
        }
    }

    public void rotate(float speed)
    {
        Debug.Log(otherPlayer_rb.angularVelocity.magnitude);
        if (otherPlayer_rb.angularVelocity.magnitude < 1f)
        {
        otherPlayer_rb.AddRelativeTorque(-Vector3.up * speed * 100f);
        }
    }

Here's a video with details on what's going on.
I guess it's a problem of fixedjoint setting or something because the whole model rotates with the wheel, meaning the whole model and the wheel are depending on each other

#

could be because I don't use wheelcollider which I highly doubt

steep rose
#

but like i said you probably want to look into using a wheelcollider or raycast/spherecast based wheels

#

you could use hinge joint as well

queen adder
#

ooooh didn't know we have OnBecameInvisible and OnBecameVisible, this is handy

frank flare
#

because before messing with wheels I want to have at least something working

#

I tried using configurable joint but there's too much of stuff there

rocky canyon
#

unity's wheel colliders are a PITA..

#

use simulated wheels/ raycasts

frank flare
rocky canyon
#

it depends tho tbh.. if u want a realistic car controller u might want to use wheel colliders and just brute force thru tuning them to work for you

#

if ur going more for an arcade feel i'd definately do raycasts and forces

#

my example is super primitive tho.. theres alot u could do to make it more realistic.. i was just having fun w/ the bouncey spring suspension lol

frank flare
#

well I don't even really know how to make a game so I guess everything working somewhat nice would be ok for me, I will just use hinge joint then add wheel colliders on wheels

rocky canyon
#

yea, then ur still in the learning process.. try out everything

#

get a feel for what works for u.. and try to lean into that

steep rose
#

I would suggest a raycast/spherecast suspension/wheels

#

they are way better imo

steep rose
#

i gave you the Documentation for it

bold iron
#

how do i scale my game to a normal scale? Each time i create a object such as a scroll view its always 100x bigger than my character.

silk night
bold iron
silk night
#

I think the default cube is just 1x1 pixel

#

And if you import an image that will be huge compared to that 1x1

deft grail
#

so it will be bigger

#

you need to zoom out to edit UI

#

your game is inside the camera view, the Canvas (ui) is a lot bigger

cosmic dagger
queen adder
vagrant harness
#

the documentation and EVERYONE says and shows that it does

teal viper
queen adder
#

@teal viper

    private void Update()
    {
        if (Input.GetMouseButton(0) && canShoot) Shoot();
    }
    public void Shoot()
    {       
        var b = Instantiate(bullet, shootPoint.position, shootPoint.rotation);
        b.AddForce(shootPoint.forward * bulletSpeed, ForceMode.Impulse);       
    }

I removed the fire rate code because its irrelevant

swift elbow
teal viper
teal viper
queen adder
teal viper
queen adder
teal viper
queen adder
teal viper
#

So it moves with the camera?

#

How do you move the camera?

queen adder
# teal viper How do you move the camera?
        float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity;
        float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity;
        xRot -= mouseY;
        yRot += mouseX;
        cam.transform.rotation = Quaternion.Euler(xRot, yRot, 0);

Theres other code in the camera but its irrelevant

teal viper
#

It is relevant - Where is it called from?

queen adder
#

Im assuming im gonna have to find a way to make the gun update before the camera somehow

teal viper
teal viper
#

One thing you could try is modifying the execution order of the scripts such that the camera is updated earlier.

queen adder
#

Okay, thats probably it
Yes im gonna figure out how to do that now

#

Thanks

#

That actually worked, changing execution order is very simple.

fickle halo
#

I am new to unity, but have professional experience as a software engineer. I'm struggling to find guides or tutorials for implementing a fps character controller that look high-quality (everything looks very simplified and poorly structured sot that beginners can understand). And tutorials that are up to date, i.e using the latest input system and delta time usages.

languid spire
eternal needle
fickle halo
#

cant find it on github repo

fickle halo
#

i dont know what I dont know

#

why is there not just an official "make an FPS controller using newest input system" guide from Unity

#

why must i rely on amateur youtubers for this

eternal needle
languid spire
fickle halo
#

i have read the input system doc.

languid spire
#

Also Camera and/Or Cinemachine for your camera control

As I said, you should not need to be told how to learn

eternal needle
# fickle halo so first time ever unity user, which api docs do I read on how to make an FPS WA...

When i was just starting out, I'd skim over a few tutorials just to see what exists relevant to what I want. You're at the stage where that's pretty much all you should be learning. What exists, and what it's used for.
It's so incredibly unlikely to find any guide on making exactly what you want for movement. Unity's docs will have very simple examples to show the methods. A lot of the time that code isnt even great

languid spire
fickle halo
eternal falconBOT
#

:teacher: Unity Learn ↗

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

eternal needle
#

Steve did list above a bunch of relevant things for that too

fickle halo
#

    void Update() {
        Vector3 move = new Vector3(moveInput.x, 0, moveInput.y) * speed * Time.deltaTime;
        controller.Move(move);
    }```
#

this happens every frame, which seems inefficient

#

is there a different callback to put this on

#

and do I have to do this * Time.delta thing? I heard that was old

teal viper
fickle halo
teal viper
teal viper
fickle halo
#

"move by the amount of nothing"

teal viper
#

There might be some overhead. You can make a check and not call it of you want.

fickle halo
#

what would the check me?

languid spire
teal viper
#

If the input is 0, then don't move it

rich egret
#

hey

#

someone know why i cant to change nearClipPlane component?

teal viper
rich egret
#

The camera is not locked, I tried to do it manually and through a script

teal viper
#

But you should be able to modify it.

#

If you can't, then something else is resetting it.

rich egret
teal viper
frank flare
#

what's wrong with the car? why does it fall slowly and why is it flipping? yesterday it would do high jumps when it would touch the ground with it's wheels

#

oh yeah if I'll put rigidbodies values on these wheels to 5 or 20 it will jump

frank flare
pulsar meteor
#

why cant i get the public var i treid 2 thibngs

solemn bobcat
#

Is there any naming convention for static equivalents of methods? I'm creating some grid utilities and I want to be able to call those from the base class instance or from a particular grid type class that doesn't have an instance.

public override Vector2Int[] Rotate(Vector2Int[] initialVectors, int rotation) =>
  RotateStatic(initialVectors, rotation);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector2Int[] RotateStatic(Vector2Int[] initialVectors, int rotation)
{
  // code
}
fickle halo
#

can I write an extension method for MonoBehavior? to have globally for all new scripts

short hazel
#

Yes you can put any type for an extension method

fickle halo
short hazel
#

In your case the parameter would be this MonoBehaviour mb

fickle halo
#

I have a folder Utilities/ with a file MonobehaviorExtensions.cs

short hazel
#

Put it in a static class, you cannot put extensions elsewhere or you'll get a compiler error

fickle halo
#

it is not finding the extension

#

I have it in a static class

#

still, my script files dont find it

short hazel
#

If you're calling the extension from a MonoBehaviour itself, you need to do this.TheExtensionMethod()

#

Because extensions are lowered down by the compiler to YourExtensionsClass.TheExtensionMethod(this)

fickle halo
#

./Utilities/MonobehaviorExtensions

using UnityEngine;

public static class MonobehaviorExtensions
{
    public static void Log(this MonoBehaviour monoBehaviour, string message)
    {
        Debug.Log($"{monoBehaviour.GetType().Name}: {message}");
    }

./Assets/MyScript.css

public class MyScript : MonoBehaviour {
  void start() {
    this.Log() // not found!
  }
}
short hazel
#

Not found as in you get a compiler error? Or you don't get the log

fickle halo
#

does not contain a definition for 'Log' and no accessible extension method 'Log'

#

also it is crucial that I can type this as Log and not this.Log, otherwise I will just abandon the approach

#

is that not possible?

short hazel
#

Ah yeah it's probably because you're calling it from MyScript, so it searches an extension that is declared as this MyScript.
You can make the method just static (non-extension), and put using static MonobehaviorExtensions; at the top

#

Then you'll be able to use Log() directly

languid spire
#

works perfectly

public static class Extensions 
{
    public static void Log(this MonoBehaviour monoBehaviour, string message)
    {
        Debug.Log($"{monoBehaviour.GetType().Name}: {message}", monoBehaviour.gameObject);
    }
}

public class MyScript : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        this.Log("Steve");
    }

}


short hazel
#

Yeah that actually works, so your issue is somewhere else

fickle halo
#

ugh csharp keeps formatting my curly braces

#

I have editorconfig turned on

#

which normally takes priority

fickle halo
#

@short hazel @languid spire OK but i actually need this to be a property, like a getter. No () invokation

#

unity is complaining about that

short hazel
#

A property that logs when you set it? Like Log = "my message";?

fickle halo
#

no its not actually parameterized and isnt a log

#

its a constant number

#

well not a constant numbe

#

im making an alias delta for Time.deltaTime

#

I want to write delta instead.

#

delta => Time.deltaTime

#

so in a script

movement * speed * delta```
languid spire
#

so whats the probllem

    float delta { get { return Time.deltaTime; } };

short hazel
#

Take your static class and make a public static property: public static float Delta => Time.deltaTime;
Then with using static ... it'll work

fickle halo
#
public static class CustomExtensions {

    public static float delta { get { return Time.deltaTime; } }```
short hazel
#

Note that this hurts readability since people not used to your codebase now have to look where delta comes from. I wouldn't recommend doing these things

fickle halo
#

I guess it doesnt need to be for monobehavior, but just globally accessible?

short hazel
#

It doesn't. You have to do using static CustomExtensions; everywhere you want to use it

fickle halo
#

right... in C# you make static classes with static methods to have toplevel functions. If forgot

languid spire
fickle halo
#

Yes I'm not a C# developer

short hazel
languid spire
#

so maybe learn it first

fickle halo
#

that is what i'm doing

languid spire
fickle halo
#

if your suggestion is to stop what im doing, tell my game dev team to pause for a few weeks while I go read a dry textbook on general C# constructs... then I think we have different learning styles and priorities

#

we're doing C# just to get unity working. we have no prior experience in it

#

but have worked in other enterprise OO languages.

languid spire
#

I think we have a different concept of what being a 'professional software engineer' actually means

fickle halo
#

i've never found that sort of resource an optimal learning strategy

#

learning as I build has always been what works for me. Can't just read books on a programming language in the abstract, never works (for me)

elfin hatch
#

how dare you be a beginner in a beginner channel... 🤔

#

Wasn't aware all beginners are professionals

fickle halo
#

I've worked professionally as a software engineer, I'm just new to Unity and C#. I can transfer most of my knowledge from other languages (typescript, scala, kotlin, python), just need to translate and google a bit. For sure, going through an entire C# course from scratch would not be optimal in my opinion (in terms of time spent)

elfin hatch
#

you probably know more than me, and if you're not welcome, I sure as hell wouldn't be.
I think he's confusing this channel with #archived-code-advanced

fickle halo
#

i agree the tone became abrasive quickly out of nowhwere, i appreciate your reassurance

#

anyway i probably contributed to it too.

elfin hatch
#

it made me feel unwelcome, when in reality I think a "beginner" channel is meant for us.

languid spire
fickle halo
#

in order for the extension method to hook onto MonoBehavior, there needs to be a this parameter in the signature

#

so I was confused when the other guy got rid of that

#

but then realized he was suggesting to ditch the "monobehavior extension" approach, and just create a global function

elfin hatch
languid spire
#

but this is C# basics, nothing to do with unity specifically which is why I directed you to the C# documentation

languid spire
neat bay
#
pauseSound?.Play();

Does anybody know why I'm getting this error even though I have a null check?

eternal needle
neat bay
neat bay
lapis frigate
#

anyone have like a general direction for me to how to create a level system in a turnbased combat game?

neat bay
#

if the script isn't even in the scene, how is it causing the error?

eternal needle
neat bay
eternal needle
keen dew
#

It's not really possible to say without seeing more of the code. But put this line before the line that throws the error and see what it says right before the error:

Debug.Log($"{name} in scene {SceneManagement.SceneManager.GetActiveScene().name} is trying to play audio");
neat bay
#

"SceneManagement"?

keen dew
#

Actually this is better:

Debug.Log($"{name} in scene {scene.name} is trying to play audio");
keen dew
neat bay
#

wait ok, now it says that the scene which isn't even loaded is trying to play audio?

#

what's the reason for this?

keen dew
#

Literally impossible to say without seeing the project

#

start debugging

short hazel
#

Note that if you have code like this:

Debug.Log(1);
SceneManager.LoadScene("otherScene");
Debug.Log(2);

The second log will run before the scene is loaded. LoadScene schedules the new scene for loading, which won't happen until next frame, meaning the rest of the code across the objects finishes executing first.

neat bay
#

wait even though this is really simple let me just double check, I'm loading the scene correctly here right?

SceneManager.LoadScene(0, LoadSceneMode.Single);
#

oh wait actually i think I understand

#
private void OnEnable()
{
    if (!animatorManager.animator.GetBool("Death"))
    {
        if (playerControls == null)
        {
            playerControls = new PlayerControls();
            playerControls.Misc.PauseMenu.performed += ctx => PauseGame(); // Subscribe to the PauseMenu input event
        }

        playerControls.Enable(); // Enable the PlayerControls
    }
}

private void OnDisable()
{
    if (!animatorManager.animator.GetBool("Death"))
    {
        playerControls.Disable(); // Disable the PlayerControls
    }
}

So I have this code for my input system, would I have to call playerControls.Disable(); before unloading my scene or no?

#

because I only get the error when I try to pause

short hazel
#

If you don't want to respond to the event while the script/object is disabled then yes you need to unsubscribe

neat bay
#

ugh i feel dumb

#

thank you

#

it worked

short hazel
#

This will also ensure a proper cleanup when the object is destroyed when you call Destroy or the scene unloads

stone pilot
#

Why is this script working in the editor but it's not working when I build the game?

using UnityEngine.Experimental.Rendering.Universal;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;


public class Resolution : MonoBehaviour
{
    public GameObject cam;
    public PixelPerfectCamera pixelPerfectCam;

    void Start()
    {
        if (cam != null)
        {
            pixelPerfectCam = cam.GetComponent<PixelPerfectCamera>();
            if (pixelPerfectCam == null)
            {
                Debug.LogError("PixelPerfectCamera component not found on the camera!");
            }
        }
        else
        {
            Debug.LogError("Camera is not assigned in the Inspector!");
        }
    }

    public void LowRes()
    {
        if (pixelPerfectCam != null)
        {
            pixelPerfectCam.enabled = true;
            pixelPerfectCam.assetsPPU = 4;
            pixelPerfectCam.refResolutionX = 320;
            pixelPerfectCam.refResolutionY = 180;
            pixelPerfectCam.upscaleRT = true;
        }
    }

    public void MediumRes()
    {
        if (pixelPerfectCam != null)
        {
            pixelPerfectCam.enabled = true;
            pixelPerfectCam.assetsPPU = 8;
            pixelPerfectCam.refResolutionX = 512;
            pixelPerfectCam.refResolutionY = 288;
            pixelPerfectCam.upscaleRT = true;
        }
    }

    public void HighRes()
    {
        if (pixelPerfectCam != null)
        {
            pixelPerfectCam.enabled = false;
        }
    }

    public void StartGame()
    {
        SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().buildIndex + 1);
    }
}
#

Look up 👆

neon ivy
#

I'm making wall detection system based on the normal vector.

public bool IsWall(RaycastHit hit)
{
  float dotProdMapped = MathAE.Remap(-1,1,0,1,MathF.Dot(hit.normal,down.normalized)); //MathAE is just a static class with a remap function in it among other functions
  return dotProdMapped < 1-(tolerance / 360) ? true : false; //tolerance is an angle in degrees
}

though for this to work I'd need a bunch of raycasts sampling normals from all over to get an average.
is there an easier way to sample multiple normals in a given direction?

queen adder
#
    void DisableRagdol()
    {
        for (int i = 0; i < parts.Length; i++)
        {   
            Destroy(parts[i]);
            Destroy(colliders[i]);
            Destroy(joints[i]); //Line 30
        }
    }

This causes Index was outside the bounds of the array, at line 30, but its working as expected

teal viper
stone pilot
#

in the editor it works perfectly

#

when I build the game it doesn't work at all

teal viper
fossil harness
teal viper
stone pilot
#

What do you mean?

#

yes I did

#

It even worked it in the editor

teal viper
#

In the build. Not the editor.

stone pilot
#

Yes i did

#

and still didn't work

teal viper
teal viper
stone pilot
#

debug

queen adder
teal viper
stone pilot
#

Well its my first time having this issue

#

And idk what to do

fossil harness
stone pilot
#

How can I know if the code is being called in the editor

teal viper
neon ivy
stone pilot
#

I will search that up

neon ivy
teal viper
queen adder
teal viper
fossil harness
queen adder
neon ivy
teal viper
fossil harness
#

It might be a little ugly, but you could make the loop iterate till parts.length - 1 then add Destroy(parts[^1]) and Destroy(colliders[^1]) after the loop

queen adder
#

And I dont want to trouble any of you

short hazel
#

Or if you expect that all three arrays are the same lengths, and that it's not normal otherwise, then you could add an if statement before the loops that checks the lengths and throws an exception if that's not the case.

#

Or use a Debug.Assert() call to do that in one line

void fable
#

Hey, Im trying to add characters in the project but for some reason it wont show in the sprite section and I cant add it as an component. Any idea what im doing wrong?

#

Sorry if the picture isnt really clear I took it from my phone cuz otherwise you wouldny see it all

slender nymph
void fable
#

i can take a screenshot but then you wouldnt see the sprite thing bevause it clicks away

slender nymph
void fable
#

Ok ill ask it there

slender nymph
#

if you plan to ask your question in a more relevant channel, then be sure to show the import settings for the sprite you are attempting to use

fervent abyss
#

hi yall

i turned on Convex for the MeshCollider, and now my player cant get inside of the mesh? its like when I turned Convex it covered the hole part......

slender nymph
#

not a code question, but that's exactly what happened.

elfin hatch
versed zinc
#

guys help im trying to make the bullet go to the midle but it goes a little left. here is the code

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

public class PlayerShoot : MonoBehaviour
{
    public Transform gunBarrel;
    private float bulletSpeed = 100f;
    public Camera playerCamera;
    [HideInInspector] public Target target;

    public void Start()
    {
        target = GetComponent<Target>();
    }

    public void ProcessShoot()
    {
        Debug.Log("Player Shoot");

        GameObject bullet = GameObject.Instantiate(Resources.Load("Prefabs/Bullet") as GameObject, gunBarrel.position, gunBarrel.rotation);
        bullet.transform.Rotate(0, 0, 90);

        Ray ray = playerCamera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
        Vector3 targetPoint = ray.GetPoint(1000);
        Vector3 direction = (targetPoint - gunBarrel.position).normalized;

        bullet.GetComponent<Rigidbody>().velocity = direction * bulletSpeed;
    }

    public void DamageTarget(int damageToTarget)
    {
        target.life = target.life - damageToTarget;
    }
}```
and here how it does please help
languid spire
versed zinc
languid spire
#

so you need your bullet to Look At the targetpoint first

versed zinc
#

but how? set the rotation?

languid spire
#

yes

versed zinc
#

how do I get it?

versed zinc
#

thx

kind drift
#

Let’s say I am trying to use post processing… the glow effect shows on the scene but not on the game screen… any idea why?

deft breach
#

maybe if u press play?

fervent abyss
#

i have no idea but why is my MeshCollider not moving with the object?

kind drift
night raptor
deft breach
#

can u show video?

fervent abyss
night raptor
deft breach
#

oh make sure to check collision detection to continous in the rigidbody

#

maybe continous collision detection will work with convex collider

#

mesh collider

night raptor
deft breach
#

ive had that sometimes i just go through colliders and with continous collision that never happens

night raptor
#

he is not suffering from any tunneling issues as far as I'm aware

deft breach
#

ah ok sry i understood the issue wrong

livid nova
#

Having trouble with one of brakeys tutorials, https://www.youtube.com/watch?v=jvtFUfJ6CP8

In the tutorial, I can't get the grid box to appear TS: 3:10

Does anybody know what could be going wrong?

Let's learn how to make 2D pathfinding using A* with and without code!

● Check out Skillshare! http://skl.sh/brackeys17

● A* Pathfinding Project: https://arongranberg.com/astar/

····················································································

❤️ Donate: https://www.paypal.com/donate/?hosted_button_id=VCMM2PLRRX8GU

► Join...

▶ Play video
keen dew
#

Show a screenshot of your editor

quick cobalt
#

    private bool spoilable = true;
    private void Update()
    {
        if (this.transform.rotation.z == -90 & spoilable == true)
        {
            spoilTrash(1);
            spoilable = false;
            Debug.Log("spilled");
        }

        if (this.transform.rotation.z == 90 & spoilable == true)
        {
            spoilTrash(2);
            spoilable= false;
            Debug.Log("spilled");
        }
    }```

Im a bit confused, this did work before without the spoilable bool
the spoiable is true in the beginning, at first i thought i used it wrong since i only wrote & spoilable
languid spire
#

that will never have worked

quick cobalt
#

Weird, it did use the function though just unlimited

#

Whats wrong with it? Okay tbh it was >= 90 and <= 90 before

languid spire
#

nah, rotation is a Quaternion not Euler angles also never check a float for equality

quick cobalt
#

Yeah the description of Quaternion already scared me but i just wanted to check if it rotated

languid spire
#

rotation.z will not contain the values you are expecting

quick cobalt
#

Give me a hint where to look

quick cobalt
#

Oh i thought im completly wrong with my approach

ashen frigate
#

hi ive tried playing with the code but i didnt manage to do double jump can u plz help me fix it ?
https://paste.ofcode.org/bEQtdgYgUf772Z4ynCpvRJ
im using rigidbody for the physics
and the new controls script

    playerInput.CharacterControls.Jump.started += onJump;
    playerInput.CharacterControls.Jump.canceled += onJump;

to
void onJump(InputAction.CallbackContext context)
{
isJumpPressed = context.ReadValueAsButton(); //if jump press true
}

void handleJump()
{
if (isJumpPressed)
{
if (grounded)
{
rb.AddRelativeForce(Vector3.up * 10);
countJump = true;
//ChangeAnimationState(PLAYER_JUMP);
}
else if (countJump)
{
rb.AddRelativeForce(Vector3.up * 10);
countJump = false;
//rb.AddRelativeForce(Vector3.down * 3000 * Time.deltaTime);

        //ChangeAnimationState(PLAYER_JUMP);
        //Debug.Log("JUMP!");

    }
}

}
private void OnCollisionEnter(Collision collision)
{
grounded = true;
countJump = false;
}

private void OnCollisionExit(Collision collision)
{
grounded = false;
//countJump = 1;
}

quick cobalt
burnt vapor
eternal falconBOT
burnt vapor
ashen frigate
burnt vapor
#

For example, try logging isJumpPressed, countJump and grounded

#

Try logging methods in general to see if they are called

ashen frigate
#

ive tried that

#

ive tried count for int and bool

burnt vapor
#

Please share those results so we can continue pinpointing the issue

ashen frigate
#

still didnt work

steep rose
#

saying it didnt work doesnt solve anything

ashen frigate
ashen frigate
#

didnt work

#

ive tried working on void handleJump() function didnt work

#

ive tried working on void onJump(InputAction.CallbackContext context) didnt work

steep rose
ashen frigate
#

im at lost

steep rose
#

show your debug results

#

and still, saying "it didnt work" solves nothing, tell us how it didnt work, what didnt work

ashen frigate
#

i got no debugs

steep rose
#

you just said you debugged

ashen frigate
#

i mean at the console

steep rose
#

what, what did you debug to the console?

ashen frigate
#

mine called testerMoveSet