#💻┃code-beginner

1 messages · Page 74 of 1

rare basin
#

and assign correct ability based on the rotation

tawdry nymph
#

thats what i am trying to do

rare basin
#

how are you reading the rotation?

tawdry nymph
#

transform.eulerAngle.z

rare basin
#

Debug.Log it, see if it matches wit the inspecotr value

#

if not, try localEulerAngle

#

or just use quaternions

gaunt ice
#
void Update()
    {
        Rotation = Player.transform.rotation.z;
        AssignAbilitys();
    }
```where is the eularangle....https://gdl.space/iqaxulodax.cs
#

or the file is not updated?

tawdry nymph
#

its not completely up[ to date

tawdry nymph
gaunt ice
#

btw you dont need to check rotation in update, you check it only if you change the rotation and idk how you rotate player tf and the eulerangle.z may not be Exactly The Same as enum value, depends on how you rotate it

tawdry nymph
#

i locked rotation on the rigidbody so it won't rotate from terrain and changed the rotation with transform.Rotate(new Vector3(transform.rotation.x, transform.rotation.y, transform.rotation.z + 90));

#

i have also tried rotating with rB.rotation += 90

rare basin
#

@tawdry nymph just use quaternions

tawdry nymph
#

i don't understand those

rare basin
#

well, time to learn them then 🤷

#

we wont learn them for you 😄

rotund hull
#

how can i set up chunks and make them load in and out near the player

sharp bloom
rancid tinsel
#

whats that thing in C# called with the : that replaces if statements?

#

its not a switch is it?

rancid tinsel
#

thats the one

#

does that have any advantages apart from maybe condensing the code?

rare basin
#

it's just cleaner

rancid tinsel
#

like maybe better performance or something

rare basin
#

and more readable

#

doesn't have any performance advantages

rancid tinsel
#

but if its code that im working on myself and i find if statements easier, its prob better to stick to that right?

rare basin
#

if it's easier for you then yes

rancid tinsel
#

i guess what im asking is, its the same thing as if statements and just down to preference ultimately?

sharp bloom
rancid tinsel
#

i see, thank you

#

so if (ifStatements == easier) {sticktoThem = true;}

#

🤓

rare basin
#

can do better ;p

#

stickToThem = ifStatements == easier;

rancid tinsel
#

that works?

rare basin
#

why not

rancid tinsel
#

idk ive never written a variable like that

#

never thought to

gaunt ice
#

== operator "returns" bool

#

you can think in this way

rare basin
#
        if (age > 18)
        {
            adult = true;
        }
        else
        {
            adult = false;
        }
#

same as

rancid tinsel
#

yeah i think i understand how that works

rare basin
#
adult = age > 18;
rancid tinsel
#

just so weird i never thought of it before

rare basin
#

we learn something everyday ;p

rancid tinsel
#

for real

rare basin
#

but also, avoid if/else walls

#

if you have any

rotund hull
#

how can i set up chunks and make them load in and out near the player

rare basin
#

with several valid approaches

#

make a chunk class with list of objects in it, enable/disable it based on colliders, distance to player etc

#

basically just load/unloads objects based on certain conditions you want

sharp bloom
#

Shouldn't this work by destroy any object that touches the collider?

#

Basically I have set up a box collider around my playing area to destroy any stray projecticles

rare basin
#

yes, as long as the conditons to trigger OnTriggerEnter2D are met

#

trigger events are only sent if one of the Colliders also has a Rigidbody2D attached

rotund hull
rare basin
#

and store all chunks in that

rotund hull
#

ohhhhhhhhhhhhhhh

#

alright

#

thank you

sharp bloom
rare basin
#

atlesat one of the colliders has to have rb2d

#

and the one with OnTriggerEnter2D function muse be set to isTrigger obviously

pulsar lodge
#

Can anyone help with why my On Click() Event is not working for a button? https://gdl.space/huceyugimo.cs really only care about the first line of code under Input1(). Its not even executing that. not sure what is going on

rare basin
pulsar lodge
#

i dont think so

rare basin
#

then it won't work

pulsar lodge
#

the guide im following is pretty old (8 years), is that something newer required in unity?

rancid tinsel
#

are you using the brackeys tutorial?

rare basin
pulsar lodge
#

Nah, its a guy doing a turn based battle system tutorial

rancid tinsel
#

my bad lol

rancid tinsel
rare basin
#

t: EventSystem

rancid tinsel
#

unless the issue is something else

#

but most likely that

gusty vector
#

sorry if i broke up aquestion but i just need a quick help in this,

so i have a string based of :
"blabla 0lasdldfsjndfsjd9
blaablaa 0jdnljjanfdnsdlfsfs9"

and i wanna replace the parts between 0 and 9 (including 0 and 9) using regex but i cant figure out the pattern... any help ?

gaunt ice
#

0*9, should be some pattern like this
btw a simple two pointers algorithm can solve it

rare basin
#

string pattern = @"0.*?9";

#

i guess?

#

then just Regex.Replace(yourString, pattern, replacement)

#

but why not just use variable in this matter?

#

string someString = $"blabla0{variable}0faf";

#

then you can just put any string variable you want

#

or ints, floats

gaunt ice
#

oh .* i mess up with wildcard, is "?" necessary? since * is zero or more previous char

gusty vector
#

im just curious how

pulsar lodge
rare basin
#

? is just non-greedy

rare basin
#

without ? it onl replaces the first substring

#

"blabla 0lasdldfsjndfsjd9 blaablaa 0jdnljjanfdnsdlfsfs9"

#

it will only replace the first part

#

with ? it will replace both

gaunt ice
#

yes my pattern is searching for (zero or more of) "0" and following by "9" eg 9, 09,009

dense root
#

So for some reason I cannot drag my audio into my audio source into the inspector... any idea what's happening?

#

It's the right format (.wav)

slender nymph
#

your wav file is an AudioClip, not an AudioSource. AudioSource is the component that plays an AudioClip

spiral narwhal
#

How would I use coroutines for cooldowns etc. when I want to pause them as soon as I open the paus menu? I feel like there is a better way than yielding wait for seconds and then checking if the game is paused or not

slender nymph
#

if you're setting timeScale to 0 when you pause the game then you don't really need to change anything since WaitForSeconds will be scaled by the timeScale. If you aren't though you can instead put a timer loop in there that just increases a float by deltaTime on frames the game is not paused. you will need to check whether it is paused doing that but it will at least be accurate as opposed to using WaitForSeconds and just checking if the game is paused after the WaitForSeconds is complete

spiral narwhal
#

Ohh that's practical. So I will make use of timescale

modest dust
#

Or multiply that Time.deltaTime by your own cooldown time scale which you set to 0 on pause, since using Time.timeScale is "global", so all other code using Time will "freeze"

spiral narwhal
#

Because I don't want to freeze animations in the pause menu and such right?

modest dust
#

Right

spiral narwhal
#

Sounds good! Maybe I will try to create an interface or something for pretty much anything that is affected by pause

slender nymph
modest dust
#

But shorter

#

no need to check anything

#

just multiply by timeScale

#

it will either add 0 or deltaTime

dense root
#

For some reason my audio is playing at the beginning and end of the word sequence not the end, any thoughts?

slender nymph
#

please share your !code correctly. nobody wants to scrub through a video to try and read it

eternal falconBOT
dense root
eager elm
dense root
#

There's an if statement preventing that

slender nymph
#

Play On Awake is a property on the AudioSource

dense root
#

oh

#

By default it's play on awake

#

thank you

quick ruin
#

if I have two circle colliders how do I reference the second one in a script

slender nymph
#

for what purpose? but also you can just drag it directly into a serialized field

quick ruin
#

beginner at prefabs but ty

slender nymph
#

although typically you'd want to separate your colliders onto different child objects

cosmic dagger
# quick ruin

if you have two on the same GameObject you need to drag the one you want into a variable field manually. also, don't put more than one collider on a GameObject . . .

quick ruin
#

ones a trigger ones not idk how else to do this ;s

cosmic dagger
slender nymph
dense root
#

Yeah that's what it was @cosmic dagger

#

But I'm wondering why it plays after the user hits enter, not before as intended

#
        if (readInput.currentWord == "りんご")
        {
            audioSource.Play();
            oldImage.sprite = apple;
        }
#

You'd think it would play before the image is shown

slender nymph
#

it will start playing the same exact frame that the sprite is assigned

dense root
#

But the game is showing the sprite but not playing the audio

#

Not until after I click enter

slender nymph
#

you're probably just repeatedly calling that method which is restarting the audio clip over and over until you stop editing the input field

#

and by probably, i mean that is exactly what is happening since you call it in Update 😉

dense root
#

Oh I see

#

How do I call that method without repeatedly doing it over and over?

slender nymph
#

only call it when the currentWord variable on your ReadInput class changes. i assume that is what your currentWordChanged event is supposed to be used for despite it not being used at all

dense root
#

Yeah I didn't understand how that works

spiral narwhal
#

Is there a way to get the remaining amount of seconds when using WaitForSeconds or would I have to store it as a variable in seconds and only use WaitForSeconds each second? I'm asking because when I exit the game I would like to store the remaining cooldown

slender nymph
#

no, use a timer loop instead

cosmic dagger
spiral narwhal
#

Why is it bad practise?

rare basin
#

nothing bad in both approaches

slender nymph
rare basin
#

yes in this case

spiral narwhal
#

Oh I see

#

What is a timer loop

rare basin
#

but he said dont use WFS at all ;p

slender nymph
#

clearly referring to their issue and not every single instance of anyone wanting to use WFS

cosmic dagger
# rare basin why not

because they need to insert a specific time when using WFS and that won't allow them to get the time reamining . . .

slender nymph
gusty vector
# rare basin ` string pattern = @"0.*?9";`

srry if im breaking a question...(again) but- what could be the regex pattern to detect whether the line of a text file doesn't start with an "A" (capital AND lower case) ?

rare basin
#

^(?![Aa])

#

^ - start of the line
?! - negavite assertion

#

no actually it checks capital or lower case

#

no nvm

#

its good

#

then you can do like Regex.IsMatch(string, pattern) store it in a bool

#

and do whatever you want

gusty vector
#

gotcha! ill test stuff and brb

spiral narwhal
#
public class Timer
{
   private int baseTime, currentCooldownTime;

   public void StartTimer() => StartCoroutine(Timer);

   private IEnumerator Timer()
   {
      currentCooldownTime -= Time.deltaTime;

      if (currentCooldownTime <= 0) DoSomething();
   }
}

Do you mean something like this?

rare basin
#

that will execute just once

#

i wouldn't do it in coroutine, but just in Update

spiral narwhal
#

Ohh so in update and then with a while loop?

modest dust
#

Update() is not necessary

rare basin
#
    public float timeRemaining = 10;
    void Update()
    {
        if (timeRemaining > 0)
        {
            timeRemaining -= Time.deltaTime;
        }
    }
slender nymph
modest dust
#
float cooldown = 3f;

private IEnumerator Timer()
{
  while (cooldown > 0)
  {
    yield return null;
    cooldown -= Time.deltaTime;
  }
}
      ```
rare basin
#

in his case

#

ok nvm it will

slender nymph
#

why not, cooldown is a field so they can access it when the coroutine ends or is canceled

rare basin
#

well it depends what does he mean by "exiting the game"

spiral narwhal
#

Ok thanks everyone :) If both ways are viable I think I will use the update one because I don't like having to yield null for "no reason"

modest dust
#

Coroutine only runs when you need it

#

It's basically an Update() but for temporary tasks

spiral narwhal
#

Ohhh

#

Then I will use that, thank you!!

gusty vector
#

so basically the File is a lot of lines.. so im splitting the file by lines and checking them one by one but for somereason it seems to match up with other words that start with a ? or perhaps not even check them ??


    private string Pattern = "^(?![Aa])"; 

    private string[] STR;

    private string FinalSTR;

    void Start()
    {
        STR = OriginalFile.text.Split("\r\n");
    }

    void Update()
    {
        for (int i = 0; i < STR.Length; i++)
        {
            FinalSTR = Regex.Replace(STR[i], Pattern, "");
        }
    }

    void LateUpdate()
    {
        System.IO.File.WriteAllText("Assets/Main Assets/Turkish/AlphaSorted/" + "A.txt", FinalSTR);
    }```
slender nymph
#

three backticks to format code

rare basin
#

and why are you doing this in Update and LateUpdate?

gusty vector
rare basin
#

but do you need to do it every frame?

#

you replace the final string every frame with regex patterns

#

and every frame you write the same final string to the A.txt file

#

also afaik regex is not really optimal to use especially every frame with a loop additionaly

gusty vector
#

uhh- how could i approach this then ?

rare basin
#

Just split it and write once

#

or whenever you need

#

there is no need to change it and write every frame if it's the same

#

same with for example healthbars for your game, you don't need to set the fillImage every frame to match the current hp, just do it when player takes damage or heals

willow nexus
rare basin
#

we can't hear any sound

willow nexus
#

unmute the video and watch 4 seconds of it

rare basin
#
    public void OnPointerEnter(PointerEventData eventData)
    {
        audioSource.Play();
        imageComponent.sprite = image2;
    }
#

comment this Play()

#

and turn off playOnAwake by default

#

you are constantly playing the clip

#

that's why it's looped in the beggining, cuz its starting again and again

#

put a debug.log in OnPointerEnter

gusty vector
rare basin
#

🤷

#

not a regex issue

gusty vector
#

moved it to start like this :

    public TextAsset OriginalFile;

    private string Pattern = "^(?![Aa])";

    private string[] STR;

    private string FinalSTR;

    void Start()
    {
        for (int i = 0; i < OriginalFile.text.Split("\r\n").Length; i++)
        {
            FinalSTR = Regex.Replace(OriginalFile.text.Split("\r\n")[i], Pattern, "");
        }


        System.IO.File.WriteAllText("Assets/Main Assets/Turkish/AlphaSorted/" + "A.txt", FinalSTR);
    }```
willow nexus
#

I added audioSource.playOnAwake = false; to start
and the onpointerenter is now

```public void OnPointerEnter(PointerEventData eventData)
{
    Debug.Log("Test");
    audioSource.Play();
    imageComponent.sprite = image2;
}```

The debug runs fine and the sprite from the mouseover is fine, but the audio never plays
and if i check play on awake it goes back to playing the sound on repeat super fast

rare basin
#

at each iteration you are replacing finalSTR with the result of the regex for current line

#

meaning finalSTR has the last line stored after the loop completes

gusty vector
#

ohhhhhhhhh

rare basin
#

you understand? 😄

#

FinalSTR += Regex.Replace(lines[i], Pattern, "") + "\r\n";

#

try sth like that

gaunt ice
#

you should use stringbuilder this case...

dense root
gaunt ice
#

suppose you have 1MB file and 1K line (1KB pre line), you generated 1K,2K+3K+...+999K bytes garbage in total... (1K=1000 and 1M =1000K by disk manufacturers)

rich adder
#

we spent long time on this lol

dense root
#

I'm trying lol

#

Can you recommend a tutorial?

rich adder
rotund hull
#

how can i set up chunks and make them load in and out near the player

rich adder
rare basin
rotund hull
#

i am still confused

#

i thought i got it but i dont

rare basin
#

then just write what are you confused about

#

and what have you done so far

#

and what are you struggling with

#

instead of such general question

rotund hull
gusty vector
#
    public TextAsset OriginalFile;

    private string Pattern = "^(?![Aa])";

    private string FinalSTR;

    void Start()
    {
        for (int i = 0; i < OriginalFile.text.Split("\r\n").Length; i++)
        {
            FinalSTR += Regex.Replace(OriginalFile.text.Split("\r\n")[i], Pattern, "") + "\r\n";
        }

        System.IO.File.WriteAllText("Assets/Main Assets/Turkish/AlphaSorted/" + "A.txt", FinalSTR);
    }``` 
this literally does nothing- whatt-?!
slender nymph
#

so many arrays being allocated 😬

gaunt ice
#

and string

gusty vector
slender nymph
#

every time you do OriginalFile.text.Split("\r\n") it allocates a new array. and you do that each iteration of the loop

#

much like how it was pointed out that you are allocating strings each iteration. but this is even worse tbh

gusty vector
#

    private string Pattern = "^(?![Aa])";

    private string[] STR;

    private string FinalSTR;

    void Awake()
    {
        STR = OriginalFile.text.Split("\r\n");
    }

    void Start()
    {
        for (int i = 0; i < STR.Length; i++)
        {
            FinalSTR += Regex.Replace(STR[i], Pattern, "") + "\r\n";
        }

        Debug.Log(FinalSTR);

        System.IO.File.WriteAllText("Assets/Main Assets/Turkish/AlphaSorted/" + "A.txt", FinalSTR);
    }```

does this do ?
#

(prbbly not)

slender nymph
#

that's better. though you can split the string inside the same method you are operating on it.
you're still allocating a new string for each iteration of the loop though

gaunt ice
#

i have said that you should use stringbuilder if you want to append string continuously

gusty vector
gusty vector
gaunt ice
#

google
though i will just write a simple two pointer to split the string by "\r\n"

slender nymph
rapid dragon
#

Does anyone know good tutorial for like, a classic RPG set up? Like top down, camera moving with the character, that type of thing

fierce mortar
#

I really hate programming👍

languid spire
fierce mortar
#

my friends

languid spire
#

get better friends

fierce mortar
#

anyways is there a feature to use strings to call specific function

slender nymph
#

why would you want to do that

rich adder
fierce mortar
slender nymph
spare umbra
#

I want to be able to change the size of a square like this

#

in 2D

rich adder
spare umbra
rich adder
#

through code

#

Catlike has good examples

spare umbra
fierce mortar
slender nymph
fierce mortar
rich adder
#

i think my brain just suffered a malfunction reading that

slender nymph
#

i feel like you barely grasp how code works if you think using strings is somehow going to prevent you from calling a method

rich adder
vale sparrow
#

quick question. is there a way I could trigger a button OnClick() through event triggers?

vale sparrow
rich adder
vale sparrow
#

oh shit

#

didnt think of that

#

tysm

slender nymph
#

events can only be invoked by the object that owns them

eager elm
#

well it's a unity event, not a system one

vale sparrow
#

im using the new input system

eager elm
#

ah well he said through event triggers, not code, mb

vale sparrow
#

so some things could just not work

#

really cool thing so far, im digging it

fierce mortar
# slender nymph i feel like you barely grasp how code works if you think using strings is someho...

I don´t know how I can change my weapon without directly calling the specific shoot function for the weapon, and because of that I thought there is any way that when changing my weapon i could attach the name of the weapon shoot function to a string. And then I thought, with my stupid coding beginner brain, i could maaaaaybe convert this string to a function name to call the weapon specific function, when i pressed the Shoot Button. I know what a string is I´m just not experienced enough to know if you can change a string to a function name. Hope this was finally understandable enough.

slender nymph
#

what do you mean by "the specific shoot function for the weapon"? have you gone and made completely unrelated classes for each of your weapons instead of using a common base class that declares the Shoot method that each of the derived classes overrides?

eager elm
fierce mortar
cosmic dagger
#

or you can use a base class that contains a Shoot method . . .

slender nymph
rich adder
#

inheritance vs composition 🥵

cosmic dagger
#

composition FTW, but inheritance is still existent . . .

rich adder
#

haha yeah interfaces are awesome!

fierce mortar
#

thank you guys that really helped, gonna try that tomorrow (gonna try everything without doing beginner courses )

slender nymph
#

gonna try everything without doing beginner courses
that's a good way to guarantee you are going to struggle

slender nymph
cosmic dagger
vernal thorn
#

It doesnt work but I dont know why

using UnityEngine.SceneManagement;

public class SceneTransition : MonoBehaviour
{
    // Name of the scene to transition to
    public string nextSceneName = "Scene2";

    private void OnCollisionEnter(Collision collision)
    {
        // Check if the player (or any other object with a collider) has collided with the trigger
        if (collision.collider.CompareTag("Player"))
        {
            // Load the next scene
            SceneManager.LoadScene(nextSceneName);
        }
    }
}
rotund hull
#

how can i reference things to a list in code

#

or array

cosmic dagger
vernal thorn
cosmic dagger
fierce mortar
rotund hull
cosmic dagger
vernal thorn
vernal thorn
cosmic dagger
rotund hull
#

so i have chunks that i want to render in and out and I make the chunks in another script so they are not in the scene view

cosmic dagger
rotund hull
fierce mortar
cosmic dagger
# rotund hull in code

sure, what have you tried or google? just asking cuz if you search "how to add to a list c#," you'll get tons of answers . . .

#

you can swap list with array if you have that. make sure you know the difference between an array and a list cuz those collections are used differently . . .

vale sparrow
cosmic dagger
slender nymph
vale sparrow
#

what i wanted to do

#

was use these

#

for the event trigger

slender nymph
#

EventTrigger is entirely unrelated to your input actions

vale sparrow
#

and those are separete from the triggers

vale sparrow
slender nymph
#

you can use a PlayerInput component or your own component to do that

cosmic dagger
# vale sparrow was use these

your PlayerInput component will have events for each of your actions. you can link the method you want to call from there . . .

copper perch
#

Can I add this script to the floating joystick to stop it from spinning in circles over and over when I look left and right and hold it with my finger?

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

public class FloatingJoystick : Joystick
{
    [SerializeField] private float rotationSpeed = 5f;
    [SerializeField] private float rotationLimit = 80f; // Adjust as needed

    protected override void Update()
    {
        base.Update();

        // Limit camera rotation based on joystick input
        float horizontalRotation = inputVector.x * rotationSpeed * Time.deltaTime;
        float clampedRotation = Mathf.Clamp(transform.eulerAngles.y + horizontalRotation, -rotationLimit, rotationLimit);
        transform.eulerAngles = new Vector3(transform.eulerAngles.x, clampedRotation, transform.eulerAngles.z);
    }

    protected override void Start()
    {
        base.Start();
        background.gameObject.SetActive(false);
    }

    public override void OnPointerDown(PointerEventData eventData)
    {
        background.anchoredPosition = ScreenPointToAnchoredPosition(eventData.position);
        background.gameObject.SetActive(true);
        base.OnPointerDown(eventData);
    }

    public override void OnPointerUp(PointerEventData eventData)
    {
        background.gameObject.SetActive(false);
        base.OnPointerUp(eventData);
    }
}
solemn fractal
#

hey guys, I have this if: cs if (_uiManager.currentTime > 60 && _uiManager.currentTime < 70 && _canSpawnSkel){ _coroutineSkel = StartCoroutine(SpawnSkeletons(12)); _canSpawnSkel = false; } but even if the currentTime is like above 80 it enter this if.. what am I missing here?

cosmic dagger
fossil drum
cosmic dagger
#

you have to test it and see what happens. based on those results, you can see or tell us what occurred instead. then we can probably help with fixing the code since we have a result from the test . . .

copper perch
#

I am trying to get the unity starter assets fps controller to stop spinning in circles with the lookpad joystick

#

floating joystick

cosmic dagger
#

use links to paste your !code . . .

eternal falconBOT
pale hazel
#

for some reason a lot of times my programming app likes to suddenly be weird and when i wanna type something after something else, it instead replaces that something with something else. like if i wanna type space after print it replaces the t with space how do i fix this?

short hazel
slender nymph
#

skipped right over the part where you were suggested to use a link and where the bot says how to post large blocks of code

signal cosmos
#

aaa

short hazel
#

Beginner
Uses interface explicit implementations, lambdas, and dependency injection
Something doesn't add up

eager elm
#

brah, you need to be more specific. What is not working? What is happening, what do you want to happen?

cosmic dagger
# signal cosmos aaa

what is not right about it? does smth not work? also, this isn't a link but a wall of text (large code block) . . .

#

do you just mean code formatting or naming convention/guidelines?

signal cosmos
#

again, https://gdl.space/adokecaxew.cpp, I am a beginner and I would like to know what is not right in my code. In short, I want to mention that there will be different types of ratings in my game. I would like you to tell me what you see wrong here and what you can recommend?

#

work,link?

short hazel
#

(remove the "Hello" at the end of the link)

#

Now onto being more explicit, you need to say if you're having errors or whatever

signal cosmos
slender nymph
#

are you actually experiencing a performance issue?

cosmic dagger
signal cosmos
#

I would like to know if I have structured this code correctly from a technical perspective, I mean in terms of code professionalism

cosmic dagger
#

and they are lambdas, so you don't have a reference to the method/delegate to unsub . . .

#

if they remain until the application closes then it won't be a problem . . .

signal cosmos
#

one sec to test what you say, sry for my english

#

thx for critic

short hazel
#

No the events you subscribe to in IStartable.Start(), you need to unsubscribe from them when this instance is not needed anymore

signal cosmos
#

okk thx for comment

cosmic dagger
short hazel
#

lol, I basically just copy-pasted Random's comment

#

You can't unsubscribe from a lambda (unless you keep a reference to it somewhere), so I assume that's not the case

cosmic dagger
#

yep, they need to store them as methods . . .

signal cosmos
#

ohhh

cosmic dagger
#

if you want to be picky, const variables are PascalCase and private variables prefixed with an "_" — if following the Microsoft coding guidelines . . .

signal cosmos
#

i have other rights ;))) but ok thx

short hazel
#

Wait hold on there's something weird in this code
The rating loading on line 65 will overwrite the loading made on 64, they target the same variable
Same for saving

cosmic dagger
cosmic dagger
#

also, why do you call UpdateAndSaveRating twice in a row?

#

ahhh, SPR2 just mentioned that . . .

short hazel
#

For "good" and "bad" ratings, but they need two properties because they're stepping on each other right now

cosmic dagger
#

oh, then that's fine. they use different keys as arguments . . .

short hazel
#

You're always saving/loading the bad rating metric, because it's the last one in the subscription list

signal cosmos
#

"I want to use a single variable for the rating system, where at the beginning of the game, you choose to play for a 'badrating' or 'goodrating,' meaning you can be a good pharmacist or a bad pharmacist, and 'currentRating' is shared, as ideally they should not intersect.

short hazel
#

Well you need three properties then. One for the good rating, one for the bad rating, and one for the one you'll be choosing when the game starts

#

void UseRating(Rating r) => CurrentRating = ...

spiral narwhal
#

For a death screen, should the preferred approach be to make it its own scene and load that asynchronously on death, or make it an overlay and set the delta time to zero?

rare basin
#

So I'm making a 3D top-down view RTS game. I've watched a tutorials on how to do a selection box to select my units, but all of them are in 3d using Physics2D.OverlapAreaAll(), is there any replacement for that in 3d?

rare basin
#

yes that takes the Center

#

i need 2 points (startPos and endPos)

#

and make rectangle based on these points

timber tide
#

You can calculate the points and get a center

rare basin
#

but i guess i can calculate the center

#

nvm

#

thank you

cosmic dagger
#

yup, get that center . . .

dry tendon
#

Does anyone knows how could i transpose textures from a terrain to a plane?

#

Cause i can't use the shader on a terrain due to it has no materials...

quick ruin
#

how would I stop this during the 5 seconds to not disable the game object?

quick ruin
#

still sets it to not active

fossil drum
quick ruin
#

the stopcoroutine is functioning it still runs the next line not sure how to get between it

fossil drum
cosmic dagger
#

are you sure StopCoroutine runs? try caching the coroutine in a variable . . .

timber tide
timber tide
#

make one

dry tendon
#

for meshes i have the material option...

timber tide
#

Oh, then you do have a material

dry tendon
#

but thats the building... not the terrain

#

i don't know how to apply it to the terrain too

timber tide
#

oh, you're using actual terrain tool ah

dry tendon
#

or just convert the terrain into a plane or something like that

#

if it's posible hehe

sly wasp
#

real quick, i have a line of code that says "cam.GetComponent<Animator>().Play("introRunCam");"
im trying to replay the animation when i press a button ( i already have a function and stuff ), how would i achieve this?

timber tide
dry tendon
#

thankss

rare basin
sly wasp
rare basin
#

🤷

lament silo
#

Whenever I have one item equipped (eg. axe) and then i try to switch to a different item (in this case it's a wood log) it wouldnt switch until i free up selected slot

sharp bloom
#

Sorry I absolutely suck at math, what is the best approach for this kind of motion?

#

Non-physics I mean

severe scarab
#

quick question, which is better for unity, javascript or python

sharp bloom
#

I mean unity is in C# but just learn whatever programming language you want

severe scarab
#

can you use python or java?

sharp bloom
#

Not really

severe scarab
#

alright, thanks!

sharp bloom
severe scarab
#

are they like the same?

sharp bloom
#

Once you'll learn the basic concepts, the differences in syntax aren't really a big deal

severe scarab
#

so if I am to learn python, I basically learn C#

frosty hound
#

If your goal is to use Unity, then learn C#.

severe scarab
#

alrighty, thanks!

sharp bloom
#

So like just learn the base concepts like variables, methods, classes, etc. and you're good to go for Unity

#

Saying it because couple of years ago when I first started learning Unity, I had no clue about programming and I just copied code

#

learned absolutely nothing

runic dome
#

ok ! so i want to create actions for my player movement
but i cannot select the bind "right stick [gamepad]" for no reason
and "Delta [Mouse]" to

short hazel
runic dome
#

ok !

neon summit
#

hello, im trying to implement a simple fps camera into my scene so im watching this video. it kind of works as intended but for some reason, when i start the game, the camera starts by always pointing down. idk if this is a silly question but i cant find the reason it's happening. https://youtu.be/f473C43s8nE?si=jkmRJOJOAOmgk22g

FIRST PERSON MOVEMENT in 10 MINUTES - Unity Tutorial

In this video I'm going to show you how to code full first person rigidbody movement. You can use this character controller as final movement for your game or build things like dashing, wallrunning or sliding on top of it.

If this tutorial has helped you in any way, I would really appreciate...

▶ Play video
slender nymph
# neon summit hello, im trying to implement a simple fps camera into my scene so im watching t...

two things: first, the reason the camera starts by pointing down is because when you press the play button then move your mouse down to the game view, that is happening within the first frame so immediately the camera is rotated downward because of your mouse movement.
second, don't multiply mouse input by deltaTime. mouse input is already framerate independent and multiplying by deltaTime is to make something framerate independent. by doing that multiplication you are requiring your sensitivity to be about 100 times higher than it really needs to be and you end up with stuttery camera controls

#

oh and obligatory "use cinemachine"

neon summit
solemn fractal
#

Hey guys, when I use this snippet code cs private void Update() { if (_player.playerCurrentHeath <= 0) { Scene currentScene = SceneManager.GetActiveScene(); SceneManager.LoadScene(currentScene.name); } } When I die everything resets and works fine. BUT there is just one object that is not reseting and continue in the scene. why ?

rich adder
solemn fractal
#

DDOL ?

rich adder
tacit flame
#

So, i tried making a thing that lets me wall Jump if i collide with a Certain Gameobjects with the tag "Climbable Wall" But whenn i collide with it , not only does my character no longer have gravity effect it (not hitting the ground anymore) . It also reduces my JumpForce to below 1 when i spam space. U can see the values on the right side of my screen

solemn fractal
rich adder
solemn fractal
#

yeah, its fine. In the future I wil address this prob again. thakn you !

rich adder
#

goodluck 🙂

rich adder
tacit flame
#

right below wit

rich adder
#

um yeah I would not use OnCollider hit

#

its totally unreliable for what you want

#

You should either use triggers as a hack, or actually do Physics like raycast or other types of casts

tacit flame
#

huh?

#

Triggers as a hack, or Raycast?

#

idk wht tht means

rich adder
#

yes, triggers can be used.. which is hacky way of doing it

#

or using Physics like raycasts and such

#

wiich are the standard for this type of stuff

#

I suggest you learn about them

tacit flame
#

one or the other or both?

summer stump
tacit flame
#

Anyoen in particular worth looking at?

#

or any wowrk

rich adder
#

any would do yes

#

just to get the concept

#

then use Boxcast or something more "thicc"

#

they're just for detecting whats there

tacit flame
#

I see

#

so its like a Scanner with a small radius looking at certain point

rich adder
#

kinda

#

doesnt have to be a point, it can be a direction like boxcasts/spherecast

tacit flame
#

this seems like its cardinal directions toh

#

Can it move in all directions beyonnd cardinal directionns?

rich adder
#

if you mean a vector you can make your own directions

#

that would be kinda useless if it was only NSWE

tacit flame
#

Bett

#

Does transform.something take the value of the current position of that object ?

#

For example transform.direction in a script for a game object would ONLY show THAT game objects direction?

slender nymph
#

well transform.direction isn't a thing, but yes. the transform property refers to the current instance's Transform component

rapid dragon
tacit flame
rich adder
rapid dragon
#

Documentation as in those things explaining each mechanic from Unity’s site? Yeah I do use those a lot. Just sucks to have to search each individual thing

#

Sorry I just have some issues studying by myself. But it’s good to know they’re good resources regardless

rich adder
#

ig convex triggers but we can't do overlap or am I missing something..

halcyon osprey
#

Quick question, is it bad practice to save bits of useful code in a text file to reuse for other projects? I came across things like a camera locking script, a basic player movement script, things like that, but I couldn't possibly think of being able to remember them all

rich adder
#

or make your own libraries / dlls

#

reusing code is part of the gig 😛

tacit flame
# rich adder You should either use triggers as a hack, or actually do Physics like raycast or...

@rich adderi tried usingn Raycast w/ this functionn detereminning whether i colide with the wall or not

        Ray theRay = new Ray(transform.position, transform.TransformDirection(direction * rayCastRange));
        Debug.DrawRay(transform.position, transform.TransformDirection(direction*rayCastRange));

        if (Physics.Raycast(theRay, out RaycastHit hit, rayCastRange))
        {
            if (hit.collider.tag == "Climbable Wall")
            {
                collideWall = true;
            }
            else
            {
                collideWall = false;
            }
        }
        ```
#

same issue the player is stuck @ tht y level and never falls back down if it collides wwith a wal

#

my movement Script must be wrong

rich adder
#

yeah your whole code is probably wrong

#

also this snippet alone doesn't help

tacit flame
rich adder
#

this only changes the collideWall to false, if it hits another collider with No tag climable wall

#

it shuld also be included in the else of the main RayCast If

#

do like actually debug your bools and stuff when you add them 🤔

tacit flame
#

Line 75 i have 2 OR conditions idk if thats fuckingn it up

tacit flame
rich adder
#

separate your methods instead of jamming everything inside Update

#

its hard to read this

#

Character Controller's built in isGrounded is also very unreliable

tacit flame
#

So new raycast

#

to floor tag for is grounded

rich adder
#

again if you look at unity's example it has an overlap

#

pretty much

tacit flame
#

Unity's example?

rich adder
#

ray is too thin tho

tacit flame
#

I couldnt evenn login much less use the learnn thing

tacit flame
#

i cant add that becuase its not letting me log inn

#

which IDK why

#

any idea what i can do?

rich adder
tacit flame
#

even nafter i turnend off my vpn

#

Same issue

rich adder
cosmic dagger
tacit flame
#

ive tried it on multiple browsers with and without vpn

#

Disabled UBlock origin

#

still nothing

rich adder
#

maybe clear cache/cookies

tacit flame
#

just did

#

No diff

tacit flame
#

it wokred on my ipad

#

why is it broken on my pc

#

OK

#

So it was because of my VPN, evenn tho the connection was off

tacit flame
#
Debug.DrawRay(transform.position, transform.TransformDirection(downDirection*groundRayCastRange));

if (Physics.Raycast(isGrounded, out RaycastHit hitground, groundRayCastRange))
        {
            if (hitground.collider.tag == "Ground")
            {
                Debug.Log("Touching the Ground!");
                isTouchingGround = true;
            }
            else if (hitground.collider.tag != "Ground")
            {
                isTouchingGround = false;
            }
        }
        
        }``` How come it never reaches the elseif statement where hitground.
#

I have the bool as a public varaible so ican see if the check box ever gets unchecked

#

nvm

#

🤡

cosmic dagger
tacit flame
#

i figued it out

#
        {
            if (hitground.collider.tag == "Ground")
            {
                Debug.Log("Touching the Ground!");
                isTouchingGround = true;
            }
        }
        else
        {
            isTouchingGround = false;
        }
#

solved tht

#

had to move the else

#

Now i jus need to figure out why my character doesnnt Move back down wwhen it collides wwith a "climbable wall"

#

im like 99% sure it has to do wwith this line of my code

        {
            jumpCount = 2;
            moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); // Reads movement keys (WASD).
            moveDirection = transform.TransformDirection(moveDirection); // Turns the input into movement direction.
            moveDirection *= isSprinting ? sprintSpeed : walkSpeed; // Chooses between walk or run speed.
        }```
solemn fractal
#

Hey guys. I have a problem here. What could be the cause that I am not being able to get the value from cs _finalBossOne._finalBOCurrentHealth it is always 10 as it is his health, but here I cant get it when he receive damage, only the default value. I have the variable on the boss set as public and inside my spawnManager, I have a method that is inside update, with this part to check if his HP is 0 cs if (_finalBossOne._finalBOCurrentHealth <= 0 && _canSpawnPoison){ _coroutinePoison = StartCoroutine(SpawnPoison(12)); _canSpawnPoison = false; } but it is always 10. I am using cs [SerializeField] private FinalBossOne _finalBossOne;and assigning the boss prefab in the inspector.

cosmic dagger
solemn fractal
#

prefab in the folder

cosmic dagger
#

then you're affecting the prefab in the folder, not the one in the scene . . .

solemn fractal
cosmic dagger
#

you need to assign the boss from the scene hierarchy into the slot . . .

solemn fractal
cosmic dagger
# solemn fractal

this will change values on the prefab which has nothing to do with the scene or the game . . .

solemn fractal
#

using instantiate

#

hmm, well well

#

makes sense

cosmic dagger
solemn fractal
#

got it, will try thank you

solemn fractal
# cosmic dagger no, `Instantiate` creates a copy. you need to get a reference to the copy and ch...

ok Let me try to make the picture here and see what could it be now. I have this method inside the spawnManager ```cs
private void InvokeFinalBO(){

    if (_player.playerLevel >= 1 && _canSpawnLastBO || Time.time >= 1200 && _canSpawnLastBO){

        _camera.Follow = null;
        _canSpawnLastBO = false;
        _SpawnManager.gameObject.SetActive(false);

        DestroyAllEnemies();

        fBO = Instantiate(_finalBossOne, new Vector3(_player.transform.position.x + 5, _player.transform.position.y + 20.5f, 0), Quaternion.identity);

        for (int i = 0; i < _spawnDelays.Length; i++){
            _spawnDelays[i] = -1;
        }
    }
} ```here I instantiate the boss. What I tried now with what you said is I created a variable at the begining of the class as FinalBossOne fbo;  this method is in update. and in update i put. ```cs
void Update(){

    CoroutinesController();
    InvokeFinalBO();
    Debug.Log("BOSS HP: " + fBO.GetFBOHP());
}``` and gives me null reference.
#

debug log is after the method on invokefinalBo() in update

#

even tho I get nothing.

#

because now it is trying to get something that doesnt exist yet

cosmic dagger
solemn fractal
#

as it will spawn only when i get lvl 1.. so i cant have it like that

#

object reference not set to an instance of an object.. but might be because he will spawn only when I am level 1.

cosmic dagger
#

fBO (a lot of variable names are confusing because of abbreviation), is only assigned when the if statement is true. if it is false, fBO is not assigned and fBO.GetFBOHP will create a null reference error . . .

solemn fractal
#

fbo, first boss one

modest barn
#

I replaced a TMP Input Field GameObject and I'm not getting any Console errors. However running the game makes the editor crash inexplicably. Could someone check this out for me and let me know if it works on their end?

chrome valve
#

Is there a reason that my raycasts always return to the same point even though they were working before? i didn't touch the script or gameobject and it always sets the raycast point as the same random coordanites

solemn fractal
cosmic dagger
modest barn
#

I have no idea why

#

I can revert changes on git so I'm safe but just very confused

cosmic dagger
cosmic dagger
solemn fractal
modest barn
#

Perhaps something to do with that legacy object's components?

verbal dome
cosmic dagger
modest barn
#

It'll also test my GitHub setup as this is my first time using it

cosmic dagger
solemn fractal
#

yeah I already put a debug log every where possible and it is always 10. this is messing with my mind hahaha.. done it so many times.. crazy stuff

true pasture
#

what is this extra code after I implemented my interface? first time using them.

#

do I need it there?

verbal dome
#

Yes, you need to implement every interface you use

modest dust
verbal dome
#

Currently it will just throw exceptions to remind you to implement it

true pasture
#

no this isnt in my interface tthis is another script

#

srry my fault

cosmic dagger
#

then you know to add the implementation . . .

true pasture
#

ok thanks

cosmic dagger
modest barn
#

Yeah now worries, I'll try some stuff and see if it works itself out

cosmic dagger
#

it doesn't work at all anymore?

modest barn
modest barn
cosmic dagger
#

ouch . . .

chrome valve
# verbal dome Hard to speculate without seeing code and your setup
{
    if (rocketCooldownTimer > 0 || charges < 0)
    {
        yield break;
    }

    RaycastHit castHit;
    Physics.Raycast(cam.transform.position, cam.transform.forward, out castHit, maxRocketDistance, whatIsRocketable);

    if (castHit.collider == null)
    {
        rocketPos = cam.transform.position + cam.transform.forward * maxRocketDistance;
    }
    else
    {
        rocketPos = castHit.point;
    }
    Collider[] colliders = Physics.OverlapSphere(rocketPos, rocketExplosionRadius);

    particlePos = rocketPos;
    StartCoroutine(ParticlesPlay());

    foreach (Collider hit in colliders)
    {
        Rigidbody rb = hit.GetComponent<Rigidbody>();
        if (rb != null)
        {
                rb.AddExplosionForce(rocketKnockback, rocketPos, rocketExplosionRadius, rocketKnockback / 1.5f, ForceMode.Impulse);
        }
    } 
    rocketCooldownTimer = rocketCooldown;
    charges--;
    yield break;
}```
This is the code
keen galleon
#

Hello, I have my project in Unity that consists of a player, with its corresponding movement script where within it I have an onGround bool to check if the player is jumping or not. I also have a camera that follows this player with its corresponding Script. I need the camera ONLY when the player jumps, not to alter its Y axis. Can anyone give me a hand?

modest barn
#

How do I fix this?

#

@cosmic dagger I tried to revert my changes and this happened 😢

chrome valve
verbal dome
#

You could just use a normal method and return instead of yield break

#

Also seems like you are using the "2D" way of doing raycasts. In 3D you can just do ```cs
if(Physics.Raycast(...))
{ ... }
else
{ ... }

instead of checking if the collider is null
keen galleon
#

@verbal dome can you help me pls?

verbal dome
#

Store your jump height in a variable when you jump

cosmic dagger
verbal dome
#

And when your character is in a 'jumping' state, use that height for the camera's y position

cosmic dagger
modest barn
keen galleon
verbal dome
#

@keen galleon Additionally you can do so that the camera's y position is the minimum of it's normal position and the jump start height

verbal dome
keen galleon
#

But I still don't know how to do that, can I give you my code?

verbal dome
#

So lets say you make a new float jumpStartPosY in your movement class.
Set that float to the character's transform.position.y when you jump.
You also need a way of knowing when the player is jumping or not. So set a bool jumping to true when you jump, and set it to false when you hit the ground.
Now in your camera script, if jumping is true, limit your camera's position.y to the jumpStartPosY with Mathf.Min.

feral flax
verbal dome
chrome valve
keen galleon
chrome valve
#

the weird thing is this happened before and fixed itself and then broke again without changing anything

verbal dome
verbal dome
#

Maybe it was always broken slightly

#

But now it shows more

modest barn
#

@feral flax I'm trying to add the text

[merge]
    tool = unityyamlmerge

    [mergetool "unityyamlmerge"]
    trustExitCode = false
    cmd = '<path to UnityYAMLMerge>' merge -p "$BASE" "$REMOTE" "$LOCAL" "$MERGED"

To my .git or .gitconfig file as instructed. But I can't find either of those files in my project folder? Where are they normally contained?

#

Is it just this?

#

Its contents are:

#
[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
[submodule]
    active = .
[remote "origin"]
    url = https://github.com/AdiZ-1579887/CipherDecoderApp.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
    remote = origin
    merge = refs/heads/main
[lfs]
    repositoryformatversion = 0
#

So I'm guessing that is where it's meant to be

chrome valve
feral flax
# modest barn <@191388818895536128> I'm trying to add the text ``` [merge] tool = unityyam...

.git will be a hidden folder so you might not be able to see it. It should be at the root of the workspace folder. .gitignore is usually in the same place as the .git but it could be in other locations as you can have as many as you like and they cascade. It's also possible you don't have a .gitignore if you never created one buit I assume you'd have a lot more issues if that was the case.

verbal dome
modest barn
feral flax
#

ah, no, beside it

#

project root is fine

modest barn
#

The manual doesn't specify anything as far as I can see

feral flax
#

Yes, it won't automatically fix anything because it hasn't been run. you need to run the merge tool on the file in conflict

modest barn
#

So should I find the .exe in my Program Files?

feral flax
#

You can make git use the tool by instructing it to use the mergetool in command line. You can do that with git mergetool [path_to_conflicted_file]

chrome valve
modest barn
feral flax
#

yes, git bash would work

modest barn
#

Great. Do I have to put the path in quotes?

#

I should just try it, sorry for asking so many questions haha

feral flax
#

that's okay. It only needs quotes if the path has any spaces

#

but having quotes when you don't need them is fine

modest barn
#

Cool. Somehow I can't paste the path, it's Ctrl + Shift + V, right?

feral flax
#

not in git bash, unfortunately. I think it might be Shift + Ins

modest barn
#

Oh no

#

Shift + Ins

#

Just right-clicked to check

#

Interesting choice. Thanks

#

But... I didn't use mergetooll?

feral flax
#

weird, it looks like it thinks you made a typo somehow?

modest barn
#

I tried it again and it worked, however it's giving me an error

feral flax
#

could be an invisible character from when you tried copy pasting

keen galleon
modest barn
feral flax
#

oh, also strange...

verbal dome
modest barn
#

Is that significant?

feral flax
#

it means it can't find the folder named .git which is where the repo part of the git repo would live on your hard drive

keen galleon
modest barn
feral flax
# modest barn Is that significant?

It is essentially saying that the location you gave isn't set up as a git repo. Is it possible at all that you have the project in multiple places nad might have them mixed up? Otherwise, if the .git is there, I'm not sure why it can't find it.

keen galleon
modest barn
#

@feral flax however I'm trying to resolve the conflict manually but there are no conflicts in the file. There were 2 conflicts showing in GDesktop, I fixed that, now there is one. However when I click Show in VSCode, the .unity file opens up and there are no conflicts

#

However there is this:

#

Which is the only <<<<<<< HEAD in the entire file.

feral flax
#

It shows up twice?

timber tide
#

wat

modest barn
#

Which means it is the only conflict, correct?

timber tide
#

just delete it

modest barn
timber tide
#

how are you even getting merge conflicts with your own personal repository

modest barn
#

I should delete these three lines, correct?

feral flax
#

It looks like that file was committed with a merge conflict and this is a conflict with that conflict

modest barn
#

Evidently

feral flax
#

That's the only way to get two <<<<<<< HEAD lines in a row

modest barn
#

Sounds about right

modest barn
#

Or just the HEAD lines?

verbal dome
feral flax
modest barn
#

What does > mean?

#

Incoming?

keen galleon
feral flax
#

yeah, incoming changes

modest barn
#

Ok...

#

Can I just delete them?

#

All I care about right now is getting it working because I literally have 2 empty objects in my project - I'm not going to lose anything.

verbal dome
feral flax
#

I can't say for sure since. If these are the only places where it's showing up it looks like it's okay to delete all the <<<<<<< >>>>>>> and ======= lines

modest barn
#

First of all, should I delete those empty HEAD lines?

verbal dome
#

@keen galleon Come on, read my instructions very carefully before saying that it doesn't work. You aren't doing it right. Now youre just wasting my time

solemn fractal
#

!code

eternal falconBOT
feral flax
# modest barn First of all, should I delete those empty HEAD lines?

This is only possible because it looks like the conflict was from an insertion and nothing actually needed to be merged.

The real issue would be, if the file doesn't work after deleting those lines, that the first conflict that happened mangled the file. If that's the case then it'll be a fair bit more work to recover the file and changes and would need some git know-how.

verbal dome
#

@keen galleon Don't see you doing this anywhere

keen galleon
#
anim.SetBool("salto", true); // salto (Parametro del animator) = TRUE para que realice la animacion
enSuelo = false;
ReproducirSonidoSalto();

// OSMAL

saltando = true;
jumpStartPosY = transform.position.y;```
modest barn
#

@feral flax I removed all that jazz and now GitHub Desktop allowed me to continue the merge

#

That's obviously a good sign, but does it void the possibility of that mangled file business?

feral flax
#

Not until you can open it in Unity

verbal dome
modest barn
#

Andrew I would quite literally be so screwed without you

feral flax
#

Great news, glad I could help, ahaha

modest barn
#

Now I just have to figure out the bs issue that caused me to try and revert in the first place

modest barn
verbal dome
eternal falconBOT
modest barn
#

So annoying because there are no errors or anything so I don't know what I have to do

feral flax
verbal dome
#

@keen galleon And use english names or I can't help

modest barn
#

Oh wait you mean actual logs

#

Where are they?

feral flax
#

ah, there is a file that has the console log. It's handy because if Untiy crashes there is usually some logging that happens you can't see

modest barn
#

Found the paths. I'll send it here

#

This makes no sense to me

modest barn
feral flax
#

Did you by chance open Unity again after the crash?

modest barn
#

Yes multiple times

feral flax
#

can you send the log that has prev in it?

#

when you open a new unity instance it overwrited the Editor.log with the new one, but it does keep the previous log around

verbal dome
#

Just having the same name doesn't magically make them the same value

modest barn
#

Couldn't extract exception string from exception of type StackOverflowException (another exception of class 'StackOverflowException' was thrown while processing the stack trace)

#

What even is StackOverflow? Never heard of that

keen galleon
#

Sorry Osmal, I'm Spanish and it's hard for me to understand English.

modest barn
#

Unity Inexplicably Crashing

verbal dome
#

Referencing objects from other scripts is something you should learn as soon as possible

true pasture
#

i know this is a dumb question but Im getting confused can interfaces actually run functions themselves? or are they just blueprints for monobehaviors. Like I can't use this function in my interface because it destroys something?. Which makes me think im using this completely wrong.

feral flax
verbal dome
true pasture
#

the interface

#

so interfaces don't really do anything?

verbal dome
#

Okay the newer C# versions have default interface support

#

Which you seem to be using

#

Destroy is a method in UnityEngine.Object and anything that inherits from it, such as MonoBehaviour

#

So you can try UnityEngine.Object.Destroy

#

Or just implement it in your monobehaviour

static cedar
#

I keep forgetting that Destroy is a static method. UnityChanThink

verbal dome
#

Normally you can just write Destroy(...) if your script class is a MonoBehaviour but the interface is not

true pasture
#

yeah, okay that does work. would it be possible to implement OnTriggerEnter in an interface?

#

maybe ill just do that in monobehaviors im still figuring out the best way to do this

summer stump
verbal dome
solemn fractal
#

I really have a problem here and would love if someone would take the time to help me out.

true pasture
static cedar
#

Abstraction.

keen galleon
#

doesnt work

feral flax
cosmic dagger
keen galleon
#

and already refer to the objects and everything

verbal dome
solemn fractal
verbal dome
#

@keen galleon I took a quick look, the new part of the code seems to be OK.
Next make sure that isGrounded is actually true when you are on the ground, and same with jumping when you are jumping.
You can use the inspector, Debug.Log or GUI.Label to debug the values.

cosmic dagger
solemn fractal
keen galleon
verbal dome
#

@keen galleon I think the problem is herecs if (movementScript != null && movementScript.GetEnSuelo()) { jumping = false; }

#

Setting jumping to false in the camera script will not set it to false in the movement script

verbal dome
#

The jumping in the camera script is a copy of the bool, not the same value

#

Just remove that code ^ from the camera script and move it into the movement script.
Just set jumping to false when isGrounded becomes true.

verbal dome
keen galleon
wooden shard
#

is it bad to instantiate inside an instantiate?

verbal dome
#

Also that line is really unreadable lol

#

Don't be afraid to break it into multiple lines

wooden shard
#

thanks

true pasture
#

(Ty guys for all the help its making a lot more sense now) Whats the point of making a health int in my interface? I can't set it in the inspector like with a monobehavior, what would I do with the health int?

#

Im attaching this interface to a monobehavior with a health variable already

verbal dome
#

You could draw a health bar after getting the Health value from the interface, for example.

#

The idea is that it's not tied to any specific class

#

I'm not great at explaining this lol

true pasture
#

So how does the health stat on my monobehaviour interact with the Idamageable Health variable?

#

thats the part I dont get

verbal dome
#

The interface just says 'hey I have a health variable'

static cedar
verbal dome
#
if(someObject.TryGetComponent(out IDamageable damageable))
{
  DrawHealthBar(damageable);
}``` Simple example
static cedar
#

You can explicitly implement it. Since I personally find it redundant to have multiple access to the Health value when referring to it as the type itself.

keen galleon
#

@verbal dome I have used Debug.Log on the player's movement, and when he jumps, the bool for being on the ground is set to false and the bool for jumping is set to true. I have also deleted the part of the camera code that you told me but it still doesn't work.

verbal dome
verbal dome
#

Don't skip steps

keen galleon
#

of course

#

wait

verbal dome
#

Well show your code again

keen galleon
true pasture
verbal dome
cosmic dagger
verbal dome
#

Maybe you need to access it with IDamageable.Health but I'm not sure, I'm on an older C# version.

true pasture
#

i tried that too

static cedar
cosmic dagger
cosmic dagger
# true pasture

you have IDamageable.Health, remove the IDamageable part . . .

keen galleon
#

still not working

verbal dome
summer stump
# true pasture ive googled it, but im curious what you personally use interfaces for? Would I b...

As Lilac said, for abstraction.

  1. It's as close to multi-inheritence as there is in c#. You can have many interfaces that a class inherits from.
  2. You can also do things like TryGetComponent(out IInteractable interactable)
    And many different classes could implement their own interaction methods. The calling class doesn't have to know what implementation is actually is, or what class implements it.

There are many other reasons to use it too

true pasture
keen galleon
#

sorry

verbal dome
static cedar
cosmic dagger
#

nah, it is not mandatory . . .

true pasture
verbal dome
#

Honestly it's really annoying trying to help and you just ignore some steps

#

Read everything 5 times before replying from now on

open gull
#

I need to measure the distance between the shot object and the target object frequently, but when I shoot, I create a new variable that can't be accessed in the void update, how do I measure the distance between these 2 objects while the shots are in the scene?

I've tried using "float distance = Vector2.Distance(temporary.transform.position, targetMiddle.transform.position);" but it's no use, since it's only executed once after the click, not continuously.

(Forgive me if I didn't make sense, it's confusing even for me LOL)

static cedar
verbal dome
#

Implant lol

keen galleon
verbal dome
cosmic dagger
keen galleon
static cedar
#

[field: SerializeField] public int Health { get; set; }
@true pasture compiler will know that you implement the interface implicitly IF the access is public and the name is the same.

verbal dome
#

Good luck, I don't have motivation to help you today, sorry

#

Most likely you did something differently again

keen galleon
verbal dome
#

Just wasting my time

#

Might want to find a spanish speaking unity server if one exists

true pasture
keen galleon
#

Well nothing, thanks for the help. If anyone else can help me I would appreciate it.

keen galleon
open gull
cosmic dagger
keen galleon
#

I'm asking here for a reason, it's my last option.

static cedar
#

Idk if you did.

#

Wait.

#

I meant in the class. @true pasture

true pasture
static cedar
#

Sorry.

#

Didn't clarified enough.

true pasture
#

okay it worked

#

man this is rough ty guys for the help

static cedar
#

NGL, you could have right clicked the EnemyMono class and go to quick refactoring (I think) and you should have the Implement IDamageable.

#

And you have two options there.

true pasture
#

i did it implemented it with the Idamageable.Health version

static cedar
#

Explicitly, Implicitly.

true pasture
#

ok

#

lemme check

#

okay now it works and I see what you mean by implicit or explicit

#

okay so now I can access the health of everything Idamageable without knowing what monobehaviour its on i think right?

static cedar
#

The difference between explicit and implicit is pretty much you have to cast itself to the interface when it's explicit.

true pasture
#

like thats the main benefit right?

static cedar
#

Different Mono behaviour can also use the same interface.

#

That's the abstraction part.
You shouldn't need to know the Monobehaviour itself.

true pasture
#

Okay yeah the hard part was figuring out how to use the interface variables ty for the help!

gray bough
#

This is the inspector for the camera. When you press play the money variable is set to 100 and I added the console log on SubtractMoney method and realized the method is never actually getting called. But I do not know why

true pasture
#

or i guess soimeone said they arent variables but members

static cedar
cosmic dagger
static cedar
#

{ get; set; } are just sugar.
It basically means it makes a variable behind it automatically when used inside a class or struct.

cosmic dagger
static cedar
#

Events?

cosmic dagger
#

you created a Health variable, not a property. that's why it didn't work . . .

cosmic dagger
static cedar
#

Still field aren't they?

cosmic dagger
#

nope, a field is just a class-level variable . . .

#

they're members . . .

#

any field, property, indexer, method, or event is called a class member . . .

summer stump
summer stump
# gray bough yes

Call getcomponent in start. Or better yet, just drag the object into a PlayerMoney field.
I can only think that the GetComponent call is causing issues?

It is getting TO the point where it would call SubtractMoney..

gray bough
summer stump
gray bough
summer stump
gray bough
summer stump
gray bough
#

this is what my code currently looks like

gray bough
summer stump
#

Btw, this is why you should have more descriptive logs.
Like Debug.Log($"Trigger Collision with {other.name} by {gameObject.name}", gameObject);

If it's just the name, it is less clear where it's coming from.
You had three debugs (at least) ONLY showing a name.

gray bough
#

So I realized that the objects im clicking and "picking up" still had a different script as a component and I am no longer using that other script. So I tried taking the code from it to put into my current scripts but now the gameobjects are not being destroyed and the subtract method is still not being called

keen galleon
#

I pay $5 to whoever solves this for me. Hello, I have my project in Unity that consists of a player, with its corresponding movement script where within it I have an onGround bool to check if the player is jumping or not. I also have a camera that follows this player with its corresponding Script. I need the camera ONLY when the player jumps, not to alter its Y axis. Can anyone give me a hand?

queen adder
#

camera.transform.position = new Vector2(player.transform.position, camera.transform.position.y, `camera.transform.position.z)

#

can change depending on your game

summer stump
gray bough
queen adder
#

md?

keen galleon
summer stump
gray bough
summer stump
#

The object with the script needs a collider.

And AGAIN, what about a character controller or rigidbody?

You're not being very clear

gray bough
summer stump
#

CharacterController is a built-in movement controller
Rigidbody is a component for physics/movement

Are you moving your player with the transform?

#

You may want to just manually do spatial queries on your own like OverlapCircle

gray bough
#

No I am not, I don't have a player. I just want the player to click on objects and have a counter deincrement

summer stump
#

OnTriggerEnter is for physics collisions

gray bough
#

This is essentially a very bare bones shop function. The player mouse clicks on a still object, and a text UI component with a value subtracts the "value" (int) from their total

summer stump
true pasture
#

getcomponent takes more resources so better to call few times

summer stump
true pasture
#

its not expensive but it is best to minimize yeah

#

Should I just move all my stats to an interface?

#

or would that cause a problem? I can't think of one.

teal viper
#

Interfaces can't have fields.

true pasture
#

yeah i know

ivory bobcat
#

You could probably have a struct with those as it's contents - they're all value types.

true pasture
#

ok

#

ty

cosmic dagger
timber tide
#

An interface could work and you can just pass the class ref as the interface without exposing the whole script.

#

depends how you want to calculate it though. On the actual enemy class or some other utility class for all that.

summer stump
# true pasture Should I just move all my stats to an interface?

For what purpose? Does some script need to know max health to pass damage to the IDamageable interface? What about Attack? BounceOff?

If it makes sense then sure.

To me, I feel like IDamageable should have a ReceiveDamage(float amount) method
Maybe with an enum for damage type.

cosmic dagger
#

yeah, that makes more sense to me . . .

timber tide
#

Right, IDamagable should already have the health to pass around

#

so that's fine as is