#💻┃code-beginner

1 messages · Page 304 of 1

queen adder
#

can you explain to me how to do that? i just started using unity like a week ago sorry

eternal falconBOT
sly mountain
#

How can i use this if statement to find if int waterDrank has ever been as high as int itemPrice?

public class DiscoverItemLogic : MonoBehaviour
{
    public int waterDrank;
    public int itemPrice;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    void isRichEnough(bool richEnough){
        
    }
    // Update is called once per frame
    void Update()
    {
        if(waterDrank)
        {

        }
    }
}
willow scroll
hot palm
#

You mean like

if (_waterDrank == _itemPrice
{
  // Code
}
sly mountain
#

hold on

#

i need to explain more

hot palm
#

You can either check if it is the same value == or if it is the same or more with >=

willow scroll
sly mountain
#

my bad hold on

willow scroll
sly mountain
#

im using the if statement to enable the item after the user gets enough cash, but If it only checks for when waterdrank is >= itemprice, wont the item dissapear after their cash goes lower

hot palm
#

Something like

sly mountain
#

so for example if it costs 1000, the user unlocks it, but then they spend and their money goes back to 200 for example, wont the item disable?

rich adder
sly mountain
#

i just have it there rn

#

to check

hot palm
sly mountain
#

to check if the user has enough at all times

rich adder
#

once you purchased, store it in the inventory

#

there is no way they can disable it if you already own it

willow scroll
hot palm
sly mountain
#

I want this to only be shown once they have enough cash basically

willow scroll
sly mountain
vocal marlin
rich adder
#

once amount is lowered, you update ui accordinly

hot palm
sly mountain
#

cause im not sure what you mean by that fully

sly mountain
#

thanks

willow scroll
rich adder
sly mountain
#

I'll give it a read

#

thanks

rocky gale
#

how do i make a cinemachine virtual camera rotate with your mouse like a freelook camera?

hot palm
#

There is the POV Setting under Aim

#

there is also a free cam in cinemachine

rich adder
rocky gale
#

ik but i need to use a virtual cam

rich adder
#

you don't even need any Aim or Body settings

#

there is built in one Orbital

rocky gale
#

wdym

willow scroll
#

The started, performed and canceled actions are called when the input is started, changed while being held or canceled respectively.
If you have an action of type Value with the control type Axis, the started and performed actions will be called simultaneously just once when the action is triggered.
E.g. pressing the Space button on the Value Axis action looks the following way

started
performed

... the button is released
canceled

In your case, neither making the player fly, nor changing the global value and then using it in the Update in the method subscribed to the performed action won't work.

For your flying logic I'd suggest first unsubscribing your Fly method from performed and instead performing the logic in the FixedUpdate.
Get the flight direction by reading the float value of the Value Axis action and apply the continuous force to the Rigidbody considering its mass using the default ForceMode.Force.

private void FixedUpdate()
{
    float flyDir = _flyAction.ReadValue<float>();

    if (flyDir != 0)
        _rigidbody.AddForce(flyDir * flySpeed * 100f * Time.fixedDeltaTime * Vector3.up);
}
hot palm
rich adder
rocky gale
hot palm
#

You want to rotate it from a POV or around an object?

rocky gale
#

im tryna make over the shoulder cam and i want to rotate around player

rich adder
#

so use freelook?

rocky gale
#

but how do i do over the shoulder with thta

#

i want offset

hot palm
rocky gale
hot palm
#

wdym by freelook

#

I understand like fly around camera

rocky gale
#

is that virtual cam

#

which cam is that

hot palm
#

yes

#

virtual

rocky gale
#

oh ok

#

no ye i have the shoulder offset but i want it to rotate with mouse

slender nymph
#

the CinemachineFreeLookCamera is a virtual camera

#

it's just one specfically designed for 3rd person camera controls

rocky gale
#

ok

hot palm
rocky gale
rich adder
#

what is "shoulder offset" mean

hot palm
#

this is offset

rocky gale
#

like camera to the right a lil

hot palm
#

the camera follow is my eye

rocky gale
#

that just a freelook no?

hot palm
#

No this is pov

rocky gale
#

oh

rich adder
rocky gale
#

but camera doesnt rotatd

rich adder
#

you'd have to manually do it via code in that case

rocky gale
#

with rotatearound?

rich adder
#

look at the Unity third person controller demo, it has that

hot palm
#

yeah. It's code you can do almost anything with code

rich adder
#

forgot how they do it

rocky gale
rich adder
#

they just use tpc mode and it rotates around

#

with shoulder offset

hot palm
rocky gale
#

ok il look

#

th

graceful lintel
#

blushie 🍿

hot lily
rich adder
# rocky gale ok il look

apparently is this

  private void CameraRotation()
        {
            // if there is an input and camera position is not fixed
            if (_input.look.sqrMagnitude >= _threshold && !LockCameraPosition)
            {
                //Don't multiply mouse input by Time.deltaTime;
                float deltaTimeMultiplier = IsCurrentDeviceMouse ? 1.0f : Time.deltaTime;

                _cinemachineTargetYaw += _input.look.x * deltaTimeMultiplier;
                _cinemachineTargetPitch += _input.look.y * deltaTimeMultiplier;
            }

            // clamp our rotations so our values are limited 360 degrees
            _cinemachineTargetYaw = ClampAngle(_cinemachineTargetYaw, float.MinValue, float.MaxValue);
            _cinemachineTargetPitch = ClampAngle(_cinemachineTargetPitch, BottomClamp, TopClamp);

            // Cinemachine will follow this target
            CinemachineCameraTarget.transform.rotation = Quaternion.Euler(_cinemachineTargetPitch + CameraAngleOverride,
                _cinemachineTargetYaw, 0.0f);
        }```
rocky gale
rich adder
#

see edit that was character, this is camera

rocky gale
#

oh

#

where can i find the ddmo

rocky gale
#

thx

willow scroll
honest haven
#

hi i have a current turn int on my battle manager but in my other script i cant get access to it. dont understand why

#

Cannot resolve symbol 'currentTurn'

hot palm
#

What is the exact error you get?

short hazel
honest haven
short hazel
#

BattleManager.instance.currentTurn?

#

If that's declared in that BattleManager

languid spire
honest haven
#

in my battle manager under active battlers it returns if the current turn is an enemy or a player

honest haven
#

i dont get it

short hazel
#

Yes and there it can get it because you're already in BattleManager

#

But outside of that class, you must refer to it like usual

languid spire
honest haven
#

sorry im lost can you see where im doing it differently?

short hazel
#

When you open a [] it doesn't magically switch the context into the other class

#

You're not doing it differenly, that's what the problem is

honest haven
#

even if im calling it on a instance?

short hazel
#

Yes

honest haven
#

i see

hot palm
#

You can only pass parameters from the calling class

languid spire
#

Here
both variables are on the same script so you need to access them the same way

honest haven
#

BattleManager.instance.activeBattlers[BattleManager.instance.currentTurn].isEnemy) {

#

thank you

stuck palm
#

How can i make like a global static variable that i can access from anywhere?

#

like i want this specific array of 4 colors that i dont want to keep readding into my scripts

hot palm
#

have a static class with a static variable

stuck palm
hot palm
#

You can just do something like this

public static class Information
{
  public static Color[] MyColors =
  {
    // Colors
  };
}

(correct me if I'm wrong)

#

You could also have a class with singleton reference have a public variable, which you then access through an instance of said class

soft kernel
hot palm
soft kernel
#

Didn't know that

hot palm
#
stuck palm
hot palm
stuck palm
hot palm
#

I think you can choose different approaches no?

stuck palm
#

from the docs it looks like its strictly 0 to 1

hot palm
stuck palm
#

huh

summer stump
hot palm
#

This is from the base map color of a material

stuck palm
#

either way, i found a website that does 0 - 1 calculations

hot palm
#

Yeah depends on how you implement it in the end

short hazel
#

Converting from 0-255 to 0-1 is as easy as dividing all values by 255

slow marlin
#

can someone help with Physics.CapsuleCast? it will only occasionaly detect (1 out of 100 times or smthing) objects.

rich adder
slow marlin
#

ok, thx. One sec. (i can post the question here right, i couldn't find if there was a particular channel for help)

hot palm
#

It's about coding so yeah

slow marlin
#

ok, so i got a problem with a capsule cast. If I Debug.Log(); it it will nearly only put out true's and only occasionaly a false. This seems to happen on spesific points but i dont know why. Is something wrong with the code?: (one sec typing it in with the ! code thingy)

eternal falconBOT
slow marlin
#

oops, bit too big

hot palm
#

No you need to do

// Code
#

Or you copy it into a .txt and send the txt here

slow marlin
#

done

hot palm
#

Yeah or like this

#

You want to make the player move when the capsuleCast is NOT colliding?

slow marlin
#

when it is not colliding the player should be able to move yea

hot palm
#

Okay

#

So the problem is, that it is colliding when you dont want it to?

#

If the player has a collider attached, it may collide with the players collider. Try using a layermask

slow marlin
hot palm
#

Are you casting it from the bottom of the player or the middle of the player?

summer stump
# slow marlin done

You should put in a Debug.DrawRay to check the direction and distance of the cast, make sure it goes where you want it to

slow marlin
hot palm
summer stump
hot palm
#

Ah mb I thought about sphere cast

slow marlin
#

o, ok

hot palm
#

Also I would probably recommend sphere cast

#

unless you need a capsule

slow marlin
#

i do unfortunately need the capsule on the moment

hot palm
slow marlin
#

i already looked at that one, but thanks still

hot palm
#

Oh okay

#

Well I assume you made a mistake somewhere in the cast, but idk what you want to achieve and where stuff has to be

#

Probably fastest if you trouble shoot it yourself

summer stump
#

I think a layermask was suggested earlier? That could help

hot palm
#

Yup

slow marlin
hot palm
#

Try simulating the problem in a test scene

summer stump
eternal needle
slow marlin
slow marlin
#

or 4 depends how you look at it

hot palm
#

Aslong as you are using 3D Colliders..

slow marlin
#

i am

eternal needle
# slow marlin i am

there can be a lot of issues here, like if the cast is starting inside an object. in 3d the cast wont hit something it starts inside. You can use Debug.DrawRay to visualize stuff, vertx also has this https://github.com/vertxxyz/Vertx.Debugging to visualize casts.
I think your first 2 points are wrong though
Physics.CapsuleCast(transform.position, transform.position + Vector3.up * playerheight
because playerheight is somewhat a random number here.
Plus you are also moving the transform before the cast, you arent using canMove anywhere in the moving logic

slow marlin
#

ok, thx. i will look into that

hot palm
#

lol

#

ur right

obtuse veldt
#

Hi, I am currently trying to put a pink icon on a gameobject so I can see it, but I still cannot. May someone help?

hot palm
#

Do you have gizmos enabled in sceneview?

obtuse veldt
#

I think I have

#

I managed to do it, I had to disable 3D icons

obtuse veldt
hot palm
#

Np, great website

sly mountain
#

Hey guys, how can i reference an integer from another script? In one of my scripts I need to reference an integer created in another.

ruby marsh
#

it should be a public variable

sly mountain
#

ahhh ok thanks

#

i've been wondering what that means lol

#

public vs private

eternal needle
sly mountain
#

Oh alright.. So how can I create a method to do this which I can call in other scripts too?

eternal needle
#

i strongly suggest doing c# outside of unity first. learning stuff like this can be done way faster especially if you arent trying to deal with unity bugs at the same time. plus unity will take way longer to compile

sly mountain
#

👍

#

Thanks for the help

blissful spindle
#

https://hatebin.com/hbfqtheqnz Hi, I have a problem with animations, the problem being that the "UI(popup)" animation plays out on starting the scene but then doesnt play again when the racast is in a collision with a gameObject that has the layer Interactable.

#

oh couldnt it be just that the animation is called over and over again?

#

just tested it out and can (MABY) confirm that that was not the case

young fossil
#

Hey guys, I have a game manager script that is persistent. How can I make sure the references between levels (unity events) are not lost?

young fossil
young fossil
#

Delete the first log and keep the one inside the LayerMask if statemen then tell me if it still logs everytime

#

I know you're aware but the two Debug.Log lines are the same, so it's confusing. It may be logging the collision of the raycast but not the LayerMask part

blissful spindle
#

its registering

young fossil
blissful spindle
blissful spindle
young fossil
#

Then if that log is correct, it has fired the animation 376 times

blissful spindle
young fossil
#

With the new script you sent, when does the Debug.Log fire?

#

Is it whenever a new object in that LayerMask enters?

#

Sort of like KeyDown

blissful spindle
#

I spams the console with the name of that object when I am looking at it

#

it

#

if that helps lol 😄

young fossil
#

So yea, it my understanding it is still firing the animation every frame when your object is colliding with the LayerMask

#

That bool check is not working and I don't believe it is a good way to check

#

There is an old legacy method called Animation.IsPlaying which would check if the animation finished or not

blissful spindle
#

and couldnt it be that this script is on another gameObject that the animator?

#

its theonly thing that comes to my mind now to be fair

young fossil
#

But you shouldn't use it, instead you can do:

  1. Based on time. Do a timer that gets the animation length in seconds (this is ideal)
  2. Use a key frame event at the end of the animation that sets your bool isPlaying to false (unreliable)
  3. Apparently Animator.GetCurrentAnimatorStateInfo replaces the old legacy method. Here
umbral fox
#

how do i make a gameObject move forward along the x and y axes based on it's z rotation in a 2d game?

blissful spindle
young fossil
#

For the timer you can use coroutines, then it gets the animation length, waits until finished then sets the isPlaying bool to false.

#

I do really think it is the bool playing up

blissful spindle
umbral fox
#

how to move a gameObject move forward in 2d?

vagrant fjord
#

i have a bullet script and even though i am trying to make it dissapear when colliding with an object it just phases through. ill link code here: https://gdl.space/tuqulugoqu.cs

blissful spindle
vagrant fjord
#

can it be any of them

blissful spindle
vagrant fjord
#

not working. Any tips?

blissful spindle
#

show me your bullet in the scene with inspector

vagrant fjord
#

bullet on the right

blissful spindle
vagrant fjord
#

ok

blissful spindle
vagrant fjord
#

no i dont it lags my game

blissful spindle
#

it explecetly says there needs to be a rigidbody attached to either of these objects

vagrant fjord
#

trying now

#

still not working it just increases speed of bullet

deft grail
vagrant fjord
#

kk

untold raptor
#

So i have a bunch of slots that may increase and decrease over time in my game, is there a way of adding the Slot's gameobject dynamically? (via code in the second screenshot)

vagrant fjord
#

still broken

deft grail
vagrant fjord
#

ill try that

blissful spindle
vagrant fjord
#

i tried to make it move by rigidbody and it collides every now and again but the others just phase

deft grail
vagrant fjord
#

ok ill send code

deft grail
vagrant fjord
#

trying now

spiral narwhal
#

In C#, can I forgo event signatures if I don't need them?

        public void SubscribeToServices()
        {
            // is not interested in the current and max turn number 
            TurnService.Instance.OnTurnStart += SimulateSpaceshipMovementForAll; 
        }

        // is forced to define the signature -> quite bloaty
        private void SimulateSpaceshipMovementForAll(int currentTurn, int maxTurn)
        {
          / ...
        }
vagrant fjord
#

its still broken however some of them collide and bounce off

short hazel
#

You can add a lambda in between, but you lose the ability to unsubscribe from the event.
+= (_, _) => YourMethod();

summer stump
vagrant fjord
#

trying now

spiral narwhal
vagrant fjord
#

omg it works tysm

craggy inlet
#

can someone help my intellisense isn't working for unity its not coloring the words at all

#

my package is installed on visual studio for unity

vagrant fjord
#

can someone help me with the destroying of my bullet? code is here:

spiral narwhal
#

What's wrong

vagrant fjord
#

its not destroying the bullet

spiral narwhal
#

Is it a 2d game?

vagrant fjord
#

nope 3d

spiral narwhal
#

Does it have a collider

thorn holly
vagrant fjord
thorn holly
# vagrant fjord no

Well, you can’t use on trigger enter if one of them isn’t set to isTrigger

#

Use on collision enter

vagrant fjord
#

alr

grim pecan
#

i downloaded the EZ Camera Shake asset but i cant add the script thats in the video? like its not popping up in the "add componant" for me even though it is in the video

craggy inlet
#

i wish I could figure out when I create a script it doesn't color any words other than the typical words built into c#

vagrant fjord
thorn holly
vagrant fjord
#

hold on im trying somethiong that might

dense walrus
#

hello complete beginner here! i am currently following a tutorial for crouching and sprinting in my 3d game. all the code is working and the button mapping is working but for some reason the actual crouching and sprinting in game doesnt work. please help and lmk if you need to see my code or the tutuorial im using. Thanks!

summer stump
#

The parameter also needs to change

vagrant fjord
craggy inlet
#

ok so visual studio 2022 works with intellisense is there any reason to use 2019 instead of 22 if Im using version unity 2021?

vagrant fjord
summer stump
#

Takes Collision, not Collider

grim pecan
summer stump
vagrant fjord
#

ok got it

dense walrus
vagrant fjord
#

will this work?

slender nymph
dense walrus
#

pls somone help

thorn holly
#

Post your code

slender nymph
dense walrus
thorn holly
#

My time has come. I’ve put this off as long as I can, but there’s nothing else left to do. I have to shudders learn how to use text mesh pro.

thorn holly
dense walrus
#

wdym

summer stump
eternal falconBOT
rich adder
eternal falconBOT
#

mad No

Be mindful, if someone requests your code as text, don't send a screenshot!

dense walrus
#

it says my code is too long to send as a message

#

i think i found the problem tho

thorn holly
#

Read the pop up

grim pecan
#

i cant figure out whats wrong

thorn holly
summer stump
#

See the "large code blocks" section

dense walrus
#

sry i joined discord literally 5 min ago

summer stump
#

No worries

summer stump
tender stag
#

'Rigidbody' does not contain a definition for 'enabled' and no accessible extension method 'enabled' accepting a first argument of type 'Rigidbody' could be found (are you missing a using directive or an assembly reference?)

#

im on unity 2022

#

anyone?

summer stump
tender stag
#

they used to

summer stump
#

Not that I ever remember

tender stag
#

so just set it kinematic?

grim pecan
#

im prolly missing something aloong the way

summer stump
slender nymph
# tender stag they used to

incorrect. Rigidbody does not inherit from Behaviour, it inherits directly from Component which does not have an enabled property

summer stump
tender stag
#

i swear i remember being able to disable them

thorn holly
grim pecan
summer stump
grim pecan
#

yes

young fossil
#

What is a good way to orgnaise my levels? Right now I have a GameManager is in DoNotDestroyOnLoad, I use functions like GameManager.LoadScene(string sceneName) for serialisation. But the issue I've ran into is now the references are lost when the scene changes

summer stump
# grim pecan yes

Find the script you want and just drag it on instead of looking through add component

tender stag
slender nymph
thorn holly
#

It varies game to game though

slender nymph
young fossil
#

Wait I will paste what I said earlier because I know that might be vague

#

So let's say my GameManager handles a method called LoadScene(string sceneName)

I use unity events so when the player from the main menu clicks "Play Game", it fires LoadScene("Level1")

Okay so it does exactly that woohoo. But then it gets to Level1 and the player wants to return to the menu. GameManager, which is persistent, cannot be referenced on the "Back to menu" button because it didn't exist already in that level, only MainMenu.
I can reference the level objects in static fields. But the issue is they are not serialized and that's really what I am aiming for.
The reason a method like GameManager.LoadScene(string sceneName) exists is again, due to serialisation

thorn holly
young fossil
thorn holly
#

Does that make sense?

young fossil
#

Yes, but what about general methods like LoadScene and scene transitions?

thorn holly
#

There are a couple ways to do it. You could make the scene manager switch scenes, or make the scene manager call a method in the game manager that switches scenes

young fossil
#

Hm, I see. Thank you noodle

thorn holly
#

Ofc

swift crag
#

I like to leave the "game manager" in charge of scene transitions

#

It often needs to run code before and after a scene change, so it just makes sense

undone harbor
#

My character starts with a y value of the transform to be 0.03, but as soon as I start walking it bumps up to 0.08

#

I am making sure moveDirection.y = 0, before updating the position

#

Could there be an issue with the animation. root motion is off

thorn holly
young fossil
#

How I'll try it if you are interested is
SceneManager.LoadScene goes inside MainMenu.PlayGame

young fossil
swift crag
#

I use a big coroutine when doing scene transitions

young fossil
#

the FSM runs code before and after the scene is loaded

swift crag
#

The coroutine itself is responsible for fading out, triggering the scene load, and fading back in

young fossil
#

For example, pausing the game

swift crag
#

Then it runs another coroutine based on which scene is being loaded

#

so entering a game scene causes it to run a "start game" coroutine

tender stag
cosmic smelt
#

hi im new to coding and i need help with a 2d project i have tried youtube tutorials but you need specific code that i have done a different way and i dont know what to do the thing that i am trying to do is make wall jumping in a simple little platformer i have made movement using youtube tutorials but there is nothing for the code i used and am unsure on where to go please help

swift crag
#

which yells at the scenario controller, which yells at all of my other controllers and then starts the game

tender stag
#

and this is random

#

cause i then picked it up and dropped it again and it worked properly

eternal needle
#

i would add some bright glowing material to highlight where dropPosition is while playing

tender stag
#

i debugged it

#

and it does get set to the drop position

#

but instantly gets set back

#

to its original position

#

or some other position

#

the position is also random

#

i checked through every script and nothing is manipulating the position

eternal needle
eternal needle
#

visual studio debugger, it will pause execution and you can play line by line

tender stag
#

im using vs code

eternal needle
#

unlucky

young fossil
#

You'll get a better response I think

eternal needle
# tender stag im using vs code

I would try recreating this issue in a barebones environment, no scripts anywhere else. With the minimum amount of scripts present, you can try following through whats happening. Add a lot of debugs around
Although the debugger would really make this easier

#

whoever wrote this question has their priorities in the wrong places. maybe you're better off not joining that club 😛

swift crag
#

weird rephrasing of your math homework

#

isn't this pretty much just asking if every power of 13 is coprime with 1003

#

oh god i'm getting nerd sniped here

#

this has nothing to do with unity and also nothing to do with programming in unity, so...

young fossil
#

also you're in the programming server, I'd ask there

whole idol
#

yes

grim pecan
#

So i downloaded a weapon asset pack and the weapons are prefabs, how do i make them not perfabs

tender stag
#

but i still dont understand

eternal needle
#

Well time to move on and make your own bigger, better gaming club. It's a math question, written extremely poorly imo, probably by a student who wants to act smart.
Dont waste your time on silly things like this, you'll NEVER need to do this for a game. Start your own project and have fun 🙂

tender stag
#

could u help me understand why this has an affect? @eternal needle

#

i set the interpolate on the items

#

to none

#

and suddenly it works

swift crag
#

do you set the position on their transforms directly

#

if so, that's the problem

swift crag
#

Interpolate causes the Rigidbody to set the position of the transform every frame

tender stag
#

item.transform.position = dropPosition.position;

swift crag
#

this will clobber the position you set

#

you need to set the position on the rigidbody itself

#

this will tell it to move there in the next physics update

tender stag
#

oh

summer stump
swift crag
#

With interpolation disabled, the rigidbody will see the new position in the next physics update, and it'll..mostly work

grim pecan
tender stag
#

item.rb.position = dropPosition.position;

#

like that?

swift crag
#

correct

eternal needle
#

😅 well time to check some of my code because i didnt know that was a thing either

tender stag
#

yeah lmao

#

i gotta redo most of my stuff now

swift crag
#

If you really want the object to move instantly, set both its position and tell the rigidbody to move, I guess

#

but the rigidbody will still wind up overwriting the position

#

setting Rigidbody.position just queues up a movement for the next physics update

tender stag
#

holy shit it works

#

thanks

tender stag
#

i think i need to

#

u can see it kind of teleport

#

cause im just doing item.rb.position = dropPosition.position;

#

would this be fine?

#

alright it works

odd mason
#

does anyone know what this means and if i can make it work trying to add pits to some free code im adapting to my game, pretty new to c# and been trying to research this for like 40 mins now still lost

#

cell refers to this for clarity

teal viper
teal viper
# odd mason

If you hover over Cell where it cause issue, you should see the full type signature.

#

Also, configure your!ide

eternal falconBOT
slender nymph
odd mason
#

thanks

opaque bough
#

so im pretty bad at coding, is there a way to make a code that says to set an object as a child of another object with the click of a key?

teal viper
opaque bough
#

do you think you could give me an example?

#

sorry i really suck

teal viper
#

Then you should go over the basics. Unity !learn beginner pathways is a good way to start.

eternal falconBOT
#

:teacher: Unity Learn ↗

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

opaque bough
#

i just never finished it

#

i tend to lean towards the more artist side of things

teal viper
#

But to answer your question, you can use the Input class to query input. And parenting is handled via the object's Transform component. The API of both of them you can find in the API docs.

opaque bough
#

alr, thank you

opaque bough
#

alright so that worked but is there a way to set the child to a certain position then when its picked up? because right now it just attaches to the parent from its current position, and i want it to be closer, like a flashlight would be

rocky canyon
#

you can set its localPosition relative to the parent

whole idol
#
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;

public class pipepositions : MonoBehaviour
{
    public float upperExtreme = 3.19f;
    public float lowerExtreme = -3.68f;
    public GameObject PipePair; 
    private float timer = 0.0f;
    private int spawnInterval = 2;


    // Start is called before the first frame update
    void Start()
    {

    }
    void Update()
    {

        Vector2 moveLeft = transform.position;
        
        timer += Time.deltaTime;
        Debug.Log(timer);
        if (timer >= spawnInterval)
        {
            SpawnItem();
            timer -= spawnInterval;
            
        }
    }
    void SpawnItem()
    {
        Instantiate(PipePair, new Vector3(1.8f, -5, -0.2f), transform.rotation);


    }

}

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

public class LeftMove : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(Vector2.left* Time.deltaTime * 10);
    }
}
#

Ok so I have these scripts, making a crappy_bird game ( I literally call it crappy bird )

#

problem is I have these pipes but they're not moving to the left

#

I have this one right here outside of the camera

#

and It is cloning them

#

but the clones literally get spawned into the middle of the screen like this

#

Also this script you see called pipe position is in the Pipe Holder Object because otherwise it will create exponential duplicates through the instantiate method

amber spruce
#

hey so in my script that deals with saving and loading https://hatebin.com/afndomhsfy something in their is causing it to not load right and it just infinitly loops and doesnt load the scene can anyone help me please

rough nest
#

Having an issue that I just can't wrap my head around. So, I have this rigidbody controller, and moving around works perfectly, except for when I start looking towards the ground. The game seems to lag a lot, and unity just doesn't seem to know what direction I'm looking in? Give me a second to send the code here, I'm sending this from my phone

whole idol
rough nest
rough nest
#

looking at the floor also lags the game out for whatever reason

rocky canyon
amber spruce
rough nest
#

ok uh, funny thing

#

i found out what was wrong

rocky canyon
#

i wonder how often ur Save() method is being called..

rough nest
#

setting either one of these to anything different causes it to lag, badly

#

just the input

rocky canyon
#

the only thing I can think of is maybe ur player is triggering the collision over and over? idk i'd debug the OnTriggerEnter2D better to see whats happening to make suer it wasn't

amber spruce
dense walrus
#

So Im coding rn, and I got an error which said something about protection level not being available. So I set the private thing to public and the error went away, but now in unity when i try to playtest it says theres an error about the same thing and when I go to fix it, visual studio says theres no error. What do I do

eternal falconBOT
summer stump
#
  1. you need to show the exact errors
teal viper
summer stump
#
  1. the error will show the script name and line numbers, show that code
dense walrus
#

the error exactly: "Assets\Scripts\Player\PlayerInteract.cs(36,33): error CS0122: 'InputManager.onFoot' is inaccessible due to its protection level"

amber spruce
# amber spruce it gets called only once when you enter a save point

i did find when loading it from the main menu even though it works fine i get this error it doesnt seem to affect anything
Cannot load scene: Invalid scene name (empty string) and invalid build index -1
UnityEngine.SceneManagement.SceneManager:LoadScene (string)
GameHandler:Load () (at Assets/GameHandler.cs:62)
GameHandler:Start () (at Assets/GameHandler.cs:19)

dense walrus
rocky canyon
summer stump
dense walrus
#

i have no idea what that means

rocky canyon
#

but if the Save function doesn't itself cause a Load function to go off.. im not sure what is the issue.. im just overlooking it i guess

summer stump
dense walrus
#

which bot

rocky canyon
#

this bot

summer stump
dense walrus
#

ok

amber spruce
rocky canyon
#

ya, thats why im confused.. cuz thats not the case

amber spruce
#

oh wait hold on i think i might know why

dense walrus
#

wait that bot is just a picture

rocky canyon
dense walrus
#

!ide

eternal falconBOT
dense walrus
#

oh i got it

rocky canyon
#

the one above it isn't

amber spruce
rocky canyon
#

make sure to follow those steps accurately..

amber spruce
#

although im not sure why it doesnt do it when its loaded from the main menu though

dense walrus
#

can i do this in safe mode

rocky canyon
#

people have a tendency to fly thru them.. and not get anywhere.. b/c if it doesn't work the first time.. the only step is to repeat it

rocky canyon
dense walrus
#

will my game corrupt if i exit safe mode

amber spruce
summer stump
rocky canyon
summer stump
#

Safe mode is just faster to open because it doesn't load everything

#

Easier to fix the errors quickly and reload the rest after

dense walrus
#

game didnt corrupt lets go

rocky canyon
#

learn to use Github / Version Control..
until then.. Start to use local backups when u get to a good checkpoint

dense walrus
#

i cant find visual studio in my files but i can open it from the unity editor

#

should i just (re?)download it

summer stump
#

No

#

Are you on windows?

dense walrus
#

ye

rocky canyon
amber spruce
dense walrus
#

ye thats what i clicked

#

couldnt do the second step

summer stump
#

Common7 is in program files, microsoft visual studio

#

Or program files x86. Can't remember

dense walrus
#

i searched in my pc and nothing showed up

summer stump
dense walrus
#

ill try again

#

i dont see it in either

#

i looked in program files and program files 86

rocky canyon
#

if u can get it open just go to

#

then click System Info >

#

itlll show u where its installed

summer stump
#

For Microsoft Visual Studio?
If you don't see it- ah, spawn was fast. Nice

dense walrus
#

ok thanks

rocky canyon
rocky canyon
dense walrus
#

mine is in C:\WINDOWS\system32

#

idk where thats at

whole idol
#
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;

public class pipepositions : MonoBehaviour
{
    public float upperExtreme = 3.19f;
    public float lowerExtreme = -3.68f;
    public GameObject PipePair; 
    private float spawnTimer = 0.0f;
    private int spawnInterval = 2;
    public void DestroyClone()
    {
        // Replace "cloneObject" with the actual reference to your clone GameObject
        
    }

    // Start is called before the first frame update
    void Start()
    {

    }
    void Update()
    {

        Vector2 moveLeft = transform.position;
        
        spawnTimer += Time.deltaTime;
        Debug.Log(spawnTimer);
        if (spawnTimer >= spawnInterval)
        {
            SpawnAndDestroyClone();
            spawnTimer -= spawnInterval;
            
        }
    }
    public void SpawnAndDestroyClone()
    {
        string cloneName = "Matrix_SuperPipe_600";
        Instantiate(PipePair, new Vector3(7.73f, -2.85f, 0), transform.rotation);
        PipePair.name = cloneName;

        StartCoroutine(DestroyAfterDelay(PipePair)); // Start coroutine for delayed destruction
    }
    private float destroyDelay = 10f;
    private float destroyTimer = 0.0f;
    IEnumerator DestroyAfterDelay(GameObject cloneToDestroy)
    {
        destroyTimer += Time.deltaTime;
        yield return new WaitForSeconds(destroyDelay); // Wait for specified delay
        if (destroyTimer >= destroyDelay)
        {
            Destroy(cloneToDestroy);
            destroyDelay -= spawnInterval;

        }

    }
}

#

What is wrong with my code not destroying clone objects after a while?

summer stump
whole idol
dense walrus
rocky canyon
dense walrus
#

my pc

#

i dont have skyNey

rocky canyon
#

This PC -> C: -> etc

#

thats the name of my computer..

#

urs will be different

dense walrus
#

oh

#

lol

rocky canyon
dense walrus
#

thanks

rocky canyon
#

heres a video i made.. i timestamped it at a place where u can isntall the Plugin from within the Visual Studio

#

that way u dont have to hunt down the Directory its stored.. altho u still will need to assign it inside Unity's Preferences

summer stump
whole idol
#

waitforseconds

#

like you said

#

i wanna make a variable like that

rocky canyon
#

its normally used in a Coroutine

summer stump
#

Already

#

JUST remove your if statement

#
    IEnumerator DestroyAfterDelay(GameObject cloneToDestroy)
    {
        yield return new WaitForSeconds(destroyDelay); // Wait for specified delay
            Destroy(cloneToDestroy);
            destroyDelay -= spawnInterval;

    }
}

rocky canyon
#
    void DestroyObjectDelayed()
    {
        // Kills the game object in 5 seconds after loading the object
        Destroy(gameObject, 5);
    }``` also fun fact, Destroy() has a parameter u can use to delay when it gets destroyed
#

good for use when its a more simple setup

whole idol
rocky canyon
#

i dont see u using the coroutine for anything other than destroying it after a delay.. so i guess u could use it for that

dense walrus
#

@rocky canyon@summer stump thank you so much for your patience. I just started game development last night and I know nothing. Im starting to pick stuff up but if it werent for you I would have never fixed my problem

whole idol
#
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;

public class pipepositions : MonoBehaviour
{
    public float upperExtreme = 3.19f;
    public float lowerExtreme = -3.68f;
    public GameObject PipePair; 
    private float spawnTimer = 0.0f;
    private int spawnInterval = 2;
    public void DestroyClone()
    {
        // Replace "cloneObject" with the actual reference to your clone GameObject
        
    }

    // Start is called before the first frame update
    void Start()
    {

    }
    void Update()
    {

        Vector2 moveLeft = transform.position;
        
        spawnTimer += Time.deltaTime;
        Debug.Log(spawnTimer);
        if (spawnTimer >= spawnInterval)
        {
            SpawnAndDestroyClone();
            spawnTimer -= spawnInterval;
            
        }
    }
    public void SpawnAndDestroyClone()
    {
        string cloneName = "Matrix_SuperPipe_600";
        Instantiate(PipePair, new Vector3(7.73f, -2.85f, 0), transform.rotation);
        PipePair.name = cloneName;

        StartCoroutine(DestroyAfterDelay(PipePair)); // Start coroutine for delayed destruction
    }
    IEnumerator DestroyAfterDelay(GameObject cloneToDestroy)
    {
        yield return new WaitForSeconds(5); // Wait for specified delay
        Destroy(cloneToDestroy, 5);

    }
}

why does my code stop spawning pipes after a while?

rocky canyon
dense walrus
#

ye Im learning about that stuff in my engineering class

rocky canyon
#

👀 well lets hope engineers do trial and error on small scale stuff first 🤣

dense walrus
#

yup

#

doing arduino

rocky canyon
#

hopefully they arent just throwing up bridges im driving over.. that they're using trial and error on

summer stump
dense walrus
#

at least from me

rocky canyon
#

ohh electrical engineering 😄

dense walrus
rocky canyon
#

yea im doing that as a hobby rn..

#

i thought coding was complicated..

dense walrus
#

i think everything is complicated

#

i just wanna eat and sleep

rocky canyon
#

lmao facts

summer stump
#

@whole idol Ah, you passed PipePair into your destroy method

#

You need to cached the object from the Instantiate call and destroy THAT

#

You should be getting errors when it stops spawning, right?

rocky canyon
#

this pipesJustSpawned = Instantiate(prefab...); Destroy(pipesJustSpawned);

#

wanna destroy the pipes u just created.. not the prefab ur creating them from

whole idol
#

ok so i made an entire new script cause it was getting too long and a headache to share and read so I made this and attached it to my new pipes and parent pipe object holders

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

public class DestroyerScript : MonoBehaviour
{
    public GameObject pipeToDestroy;
    // Start is called before the first frame update
    void Start()
    {
        
    }

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

    }
    public void SpawnAndDestroyClone()
    {
        string cloneName = "Matrix_SuperPipe_600";
        GameObject clone = Instantiate(pipeToDestroy, new Vector3(7.73f, -2.85f, 0), transform.rotation) as GameObject;  // Store the instantiated object
        clone.name = cloneName;

        StartCoroutine(DestroyAfterDelay(clone)); // Start coroutine with the clone reference
    }

    IEnumerator DestroyAfterDelay(GameObject cloneToDestroy)
    {
        yield return new WaitForSeconds(5); // Wait for specified delay
        Destroy(cloneToDestroy); // Destroy the clone after the delay
    }
}
summer stump
#

Alright. Does it have an issue?

whole idol
#

wow I just almost crashed my computer

#

I didn't expect any problems out of this but somehow instead of destroying objects this started creating exponentially millions of objects in merely a few seconds filling up my screen with pipes and clones

rocky canyon
#

lol

frosty river
#

For organizing a unity project, does it make sense to group the models and animations with the scripts. like putting everything in assets/zombie/ ?

rocky canyon
#

ur not developing if u dont almost crash ur computer from time to time

frosty river
#

or should I make an effort to separate the scripts from the models and such

rocky canyon
#

this is a common debate

frosty river
#

i've developed for a while, but new to game dev. does game dev favor the functional vs domain organization compared to what i've done before (web app dev)?

thorn holly
#

say I have variable A and variable B, both of the same type, myClass. If I assign variable A to an instance of myClass, then I assign variable B to variable A, then I reassign variableA to a difference instance of myClass, will variable B also now point to this different instance of myClass?

rocky canyon
#

is it Scripts, Prefabs, Models with a Truck folder in each one
or is it Truck folder with Scripts, Prefabs, and Models folder in each one

frosty river
#

in web dev you can organize either way, thought it might be a bit different organizationally with all the game assets.

whole idol
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DestroyerScript : MonoBehaviour
{
    public GameObject pipeToDestroy;
    // Start is called before the first frame update
    void Start()
    {
        
    }

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

    }
    public void SpawnAndDestroyClone()
    {
        string cloneName = "Matrix_SuperPipe_600";
        GameObject clone = Instantiate(pipeToDestroy, new Vector3(7.73f, -2.85f, 0), transform.rotation) as GameObject;  // Store the instantiated object
        clone.name = cloneName;

        StartCoroutine(DestroyAfterDelay(clone)); // Start coroutine with the clone reference
    }

    IEnumerator DestroyAfterDelay(GameObject cloneToDestroy)
    {
        yield return new WaitForSeconds(5); // Wait for specified delay
        Destroy(cloneToDestroy); // Destroy the clone after the delay
    }
}

ok so what I did is create a public GameObject pipeToDestroy; here and then I attached the GameObjects themselves onto their own DestroyerScript script. And this was supposed to force them to kill themselves not recreate themselves a billion times everywhere

rocky canyon
#

if i have something thats becoming a System.. i'll put its own Script folder within it..

#

if its not or something more simple.. it'll just put its script within a Root Script folder

frosty river
#

it's weird to have scripts/ but then have scripts elsewhere

rocky canyon
#

i name my folders as such..
Scripts

  • Utility
  • AI
  • UI
summer stump
#

No memes allowed here

whole idol
#

ok

rocky canyon
#

I tend to organize with a Root folder being the type of stuff

whole idol
#
    IEnumerator DestroyAfterDelay(GameObject cloneToDestroy)
    {
        yield return new WaitForSeconds(5); // Wait for specified delay
        Destroy(cloneToDestroy, 5); // Destroy the clone after the delay
    }
rocky canyon
#

Vehicles - Vehicle Scripts, Vehicle Models, etc

whole idol
#

I added it back in like this

#

ok so i realized why millions of objects were getting created

#

I instantiated on Update()

#

of my new "Destroyer" script

#
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;

public class pipepositions : MonoBehaviour
{
    public float upperExtreme = 3.19f;
    public float lowerExtreme = -3.68f;
    public GameObject PipePair;
    private float spawnTimer = 0.0f;
    private int spawnInterval = 2;

    public void DestroyClone() // This function is not used in the current implementation
    {
        // You could implement logic to find and destroy a specific clone here if needed
    }

    void Start()
    {

    }

    void Update()
    {
        Instantiate(PipePair, new Vector3(7.73f, -2.85f, 0), transform.rotation);  // Store the instantiated object

        Vector2 moveLeft = transform.position;

        spawnTimer += Time.deltaTime;
        Debug.Log(spawnTimer);
        if (spawnTimer >= spawnInterval)
        {
            spawnTimer -= spawnInterval;
            DestroyClone();

        }
    }
}

#

so now I added this back in again here on pipeposititions

#

and now the Destroyer.cs looks more like this

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyerScript : MonoBehaviour
{
    public GameObject pipeToDestroy;
    // Start is called before the first frame update
    void Start()
    {
    }
    // Update is called once per frame
    void Update()
    {
    }
    public void DestroyClone()
    {
 
        StartCoroutine(DestroyAfterDelay(pipeToDestroy)); // Start coroutine with the clone reference
    }
    IEnumerator DestroyAfterDelay(GameObject cloneToDestroy)
    {
        yield return new WaitForSeconds(5); // Wait for specified delay
        Destroy(cloneToDestroy, 5); // Destroy the clone after the delay
    }
}

summer stump
#

Wait, this second one is all weird

whole idol
#

yeah im not actually calling anything in on Update() yet

summer stump
#

Wait, you are calling destroy from both scripts?

whole idol
#

oops

summer stump
whole idol
#

i didn't mean to do that

summer stump
#

Destroy is not your issue, just to be clear. Instantiate is

whole idol
#
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
public class pipepositions : MonoBehaviour
{
    public float upperExtreme = 3.19f;
    public float lowerExtreme = -3.68f;
    public GameObject PipePair;
    private float spawnTimer = 0.0f;
    private int spawnInterval = 2;
    void Update()
    {
        Instantiate(PipePair, new Vector3(7.73f, -2.85f, 0), transform.rotation);  // Store the instantiated object
        Vector2 moveLeft = transform.position;
        spawnTimer += Time.deltaTime;
        Debug.Log(spawnTimer);
        if (spawnTimer >= spawnInterval)
        {
            spawnTimer -= spawnInterval;
        }
    }
}

summer stump
#

Nope again

#

Every single frame this will instantiate something, make a variable called moveleft, add to a timer, check the timer, then subtract the timer if check is true

#

That timer has no affect on ANYTHING though

#

Oh, you also have the debug run every frame, sorry, skipped over that

whole idol
summer stump
thorn holly
#

public Color myOwnColor = new Color(1, 0, 0, 1); can I not make custom colors like this? Cause if I try and assign somethings color myOwnColor, nothing happens, but if I assign it to something like Color.red, it turns red.

whole idol
#
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
public class pipepositions : MonoBehaviour
{
    public float upperExtreme = 3.19f;
    public float lowerExtreme = -3.68f;
    public GameObject PipePair;
    private float spawnTimer = 0.0f;
    private int spawnInterval = 2;
    void Update()
    {

        Vector2 moveLeft = transform.position;
        spawnTimer += Time.deltaTime;
        Debug.Log(spawnTimer);
        if (spawnTimer >= spawnInterval)
        {
            Instantiate(PipePair, new Vector3(7.73f, -2.85f, 0), transform.rotation);  // Store the instantiated object
            spawnTimer -= spawnInterval;
        }
    }
}


#

fixed

summer stump
#

That does not store the instantiated object, so the comment is wrong haha. But functionally, now there is a timer

rocky canyon
whole idol
#

now next goal is to get this bad boy fixed and make sure it works properly

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyerScript : MonoBehaviour
{
    public GameObject pipeToDestroy;
    // Start is called before the first frame update
    void Start()
    {
    }
    // Update is called once per frame
    void Update()
    {
        DestroyClone();
    }
    public void DestroyClone()
    {
 
        StartCoroutine(DestroyAfterDelay(pipeToDestroy)); // Start coroutine with the clone reference
    }
    IEnumerator DestroyAfterDelay(GameObject cloneToDestroy)
    {
        yield return new WaitForSeconds(5); // Wait for specified delay
        Destroy(cloneToDestroy, 5); // Destroy the clone after the delay
    }
}
thorn holly
rocky canyon
#

they are

#

thats why im asking

frosty river
#

Does it make sense to use Unity Version Control to avoid paying github lfs fees? My game is super simple but its 10 gigs folder

rocky canyon
#

u can ignore the Library folder

#

it should be much much smaller

frosty river
#

[Ll]ibrary/ is in my gitignore already

summer stump
rocky canyon
#

and its still 10 gig?

frosty river
#

proly not

#

locally its 10 gigs

#

lemme see if I can check repo size

rocky canyon
#

lol isn't LFS free?

thorn holly
#

🤦‍♂️

whole idol
#

that PipeGenerator script is kind of a trojar horse meaning it looks perfectly fine on a first look but if you continue to play that script it will not permamently generate new pipes, it kinda as if PipeGenerator gets tired after 5-6 Pipes and stops. But at least Destroyer works properly

frosty river
#

ok its size: 209.18 MiB

#

it uses up git lfs limits

rocky canyon
#

i think the limit is 100mb per file

#

209 should be easily put on github

frosty river
#

it's not a per file basis

summer stump
rocky canyon
#

ohh, there is also a soft limit of 100mb per file

whole idol
frosty river
#

yea

rocky canyon
#

ive never used Unity Collab tho

#

so i cant answer for sure

frosty river
#

im about to just pay for git lfs

#

60$/yr

rocky canyon
#

u have a team? it'd be worth it if u can split it up

frosty river
rocky canyon
# frosty river

ive only got 1 project that has issues on github.. and its because of all the audio. i chose to zip the audio files on my local drive and push the rest

#

that kinda saves me the trouble of finding an alternative

frosty river
#

yeah so this got me wondering

#

does it make sense to have like a google drive or somesuch as developers

rocky canyon
#

i use it

#

not to share / pull /push

#

but for my own resource

#

if u have just a hand ful of people using it.. i think google drive would be good for that

frosty river
#

i decided just to pay, dont want to learn a whole separate thing and 50gbs means I can do git with any future game project

rocky canyon
#

apparently it has backups and can revert to previous versions as well

whole idol
# summer stump What object is pipegenerator on?

one thing that is creating a big confusion i think iss that as code changes and scripts get new roles and need new descriptive names the class names dont get automatically changed as soon as you change the file name of the script so that is one thing creating confusion in my unity game project i think

rocky canyon
#

if u click the class naem and right click and rename

rocky canyon
#

it will also rename the file

summer stump
#

Renaming the CLASS as spawn said, will rename the file if done right. Renaming the FILE will never rename the class

rocky canyon
#

newer versions of unity don't require u to keep the class name and script name matching

#

but i do it anyway just for peace of mind

summer stump
# whole idol

If Pipepositions is the script spawning the pipes, then yeah, you have a destroy script on it....

#

If it isn't the one spawning pipes, then I'm not sure why you showed those screenshots

whole idol
rocky canyon
#

it renames the script filename yes

whole idol
#

or that both should be done simutaneously?

#

oh okay nice, i didnt know that

rocky canyon
whole idol
#

cool to know

rocky canyon
#

as long as u use the Rename right click menu

#

it'll rename it for u

summer stump
#

Misread, sorry

rocky canyon
#

something i wish i would have learned about a year earlier than i did

whole idol
#

does this call the moveLeft script?

#

I decided imma need to make a new Cloner script

#

cause PipeGenerator will be the one that will generate pipes inside of the upperExtreme and lowerExtreme

#

having a seperate Cloner script sounds more appropriate i think

rocky canyon
#

no that creates a local Vector2 named moveLeft and assigns it to the objects transform position

whole idol
#

do i need this Vector2 line?

rocky canyon
#

nope, i dont see where ur using it anywhere else..

#

just assigns it.. and does nothing else

#

if u hover it it'll actually tell u that its Unused

stuck sinew
#

i tried to create a 2d life bar but everything i try dont work

rocky canyon
#

just start by debugging the values / getting the math working.. and then move on to setting a slider or a sprite's fillAmount to reflect it

stuck sinew
#

alright thanks^^

summer stump
eternal falconBOT
#

:teacher: Unity Learn ↗

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

thorn tapir
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

summer stump
thorn tapir
summer stump
thorn tapir
#

😦

summer stump
# thorn tapir 😦

Try googling the phrase "unity learn" and see if it comes up. Curious if it's a localization thing?

#

No idea though. Sorry

thorn tapir
#

I opened it with unity hub, same results. Thats probably the case

whole idol
#

whats wrong with this?

eternal needle
# whole idol whats wrong with this?

you should do c# basics before unity. are you following a tutorial? i feel like ive seen this same sprite before. If so, go back and look at the code again.
Otherwise look at the error, you are trying to use a type and not an instance of an object

whole idol
#

for the pipes and the player bird

#

thats it

eternal needle
#

you really arent gonna get far just guessing at how stuff should be written. Do yourself a favor and do c# without unity first

whole idol
#

i did the unity tutorial

#

followed the car tutorial and the plane project and it was good

#

but after that they have a whole tutorial about " okay now just go ahead and make your own stuff "

#

this is on the junior programmer course

#

but didnt do the c# basics course because I already saw their full tutorial on youtube about c# unity

#

and followed so many tutorial hell hour long playlists that now i think its time to create stuff

whole idol
#

ok maybe there is some value in that c# without unity thing

#

I was surprised by the quality of SOME of their junior programmer videos ( but not all )

#

some where absolute dogshit

eternal needle
#

To compare this to something other than coding, right now you are experimenting with building a plane instead of putting lego bricks together

whole idol
#

but the plane and car tutorials were so amazign they actually told me pretty much most than any tutorials on youtube

whole idol
#

i tend to do that with other languages as well, its a bad habit

eternal needle
#

i see it was also linked above to u

spice ravine
#

my project crushes when I encounter a creature, I'll provide the part of the code with teh problem, here: ```cs

do
{
StartCoroutine(WaitForAction());
ActionActive = false;
CreatureHealth = chosenAnItem(CreatureHealth);
textField.text = "He bit you!\n" +
$"You lost {rand} Health!\n" +
"Click 'Next' to continue";
StartCoroutine(DelayAction(60f));
} while (CreatureHealth > 0 && player.Health > 0);

#

and I really don't know how to resolve it

#

in other parts of the script, it does wait

#

wait...

eternal needle
spice ravine
#

Yeah!! how would you regularly resolve this issue?

eternal needle
#

Look further into why your while loop is always true. player.Health isnt directly changed here, unless some method changes it (the coroutines or chosenAnItem)
So that means CreatureHealth is always more than 0

#

Those coroutines make me wonder what they're doing, because its entirely possible you are starting many of them

spice ravine
#

yeah, wait I am snipping some code...

#
int chosenAnItem(int CreatureHealth)
{
    if (chosenNumber == 1)
    {
        CreatureHealth -= rnd.Next(player.Weapon.DamageMin, player.Weapon.DamageMax);
    }
    else if (chosenNumber == 2)
    {
        Intermission();
    }
    else if (chosenNumber == 3)
    {
        textField.text = "Please choose an Item to use from above";
        ItemHandler();
        turnState = "UsingAnItem";

        // Check if an item was used
        if (UsedItem == "healingPotion")
        {
            player.Health += 20;
        }
        else if (UsedItem == "dynamite")
        {
            CreatureHealth = 0;
        }
        UsedItem = "";
    }
    else
    {
        StartCoroutine(DelayAction(1f));
    }

    return CreatureHealth;
}```
#

I wish there was just a wait(1) command...

#

I started learning unity yesturday

eternal needle
#

ok so what about the case where chosenNumber is 3, and used item is healingPotion?

#

or if chosenNumber is 2 i guess, look at what is returned. then look at the condition for the while loop

spice ravine
#

but it freezes... I can't see things retuned when unity won't react

eternal needle
#

you dont need to see it, you can think about it

#

Think about what happens if chosenNumber is anything but 1 or 3. Then think of the issue, the loop will go on forever if CreatureHealth > 0 & player.Health > 0

spice ravine
#

it doesn't work liek taht in the rest of the script, but I think I missed something gigantic...

#

wait

eternal needle
#

Also you can attach the VS debugger to play line by line, so your unity doesnt freeze entirely. Just need to put a breakpoint

eternal needle
#

this really is not complicated

spice ravine
#
public void Option3()
{
    if (turnState == "InMarket")
    {
        if (player.Gold >= 200)
        {
            player.Weapon = new Sword("Diamond Sword", 100, 130);
            player.Gold -= 200;
            UpdateUI();
            Intermission();
        }
        else
        {
            WarningText.text = "You do not have enough gold.";
            StartCoroutine(DelayAction(1f));
        }
    }
    else if (turnState == "InArmory")
    {
        if (player.Gold >= 80)
        {
            player.Weapon = new Sword("Diamond Sword", 100, 130);
            player.Gold -= 80;
            UpdateUI();
            Intermission();
        }
        else
        {
            WarningText.text = "You do not have enough gold.";
            StartCoroutine(DelayAction(1f));
        }
    }
    else if (turnState == "FightingCreature") // Added condition for fighting creature
    {
        chosenNumber = 3; // Set chosenNumber to 3 to trigger item usage
        Debug.Log("I have this SOOO much!!!!!!!!!! ayayayyay!");
    }
    else
    {
        WarningText.text = "You may not use this button right now.";
        StartCoroutine(DelayAction(1f));
    }
}

#

that you so much for the help so far, I really apreciate it

#

this function is triggered via a button

#

in game

eternal needle
#

I have no clue what the relation of these codes are, but wow thats a ton of string based stuff

spice ravine
#

do you want me to send the entire file? I feel like that might egsoust some people, and you

#

it seems kind of wrong to be honest...

#

(TEXT FILE)

eternal needle
eternal falconBOT
eternal needle
#

If you wont stop to think about that while loop condition, i cant really say much else

spice ravine
#

ok...

#

welp, Should I just stop working on this? I spent the past 18 hours working on this one problem nonstop...

#

I thought maby you could direct me to a better way to do it...

#

maby I was wrong, maby this was a bad project to begine with....

#

I made this project as a python project before hand, here is the file if anybody is interasted:

#

It's a project that I was very pashenate about...

#

it took me 26 hours...

#

I know I "need" to do what /!\code code tells me to do, but I feel like that's just a waste...

#

why do I end all my messages with ... 🤣 I just realized

swift elbow
summer stump
spice ravine
#

you can

#

you can just click the button beside expand

#

'view whole file'

summer stump
spice ravine
#

oh, that's a \thing with your settings

summer stump
#

Mobile app

spice ravine
summer stump
#

Which most of us use

#

And is why there are the rules about posting code properly

spice ravine
#

ohhhh!!!!!!!!! Thank you!

#

ok, now I understand

eternal falconBOT
spice ravine
#

I didn't know!, ok, amma start doing it

#

nice, thank you for providing me with that info, I was really confused

#

YESS!!!!! finally found the answer!!! yield return new WaitUntil(() => chosenNumber == 0);

silent dove
#

Uhh could I get a bit of help with something?
I've looked at different errors im getting online but I'm not sure how similar they are to my code because it doesn't seem to work with their solutions.
I have the enemies all as prefabs with the 'Enemy' tag, and so I'm trying to have it to be when all the Enemies are destroyed, then the scene replays itself, but as of right now I keep getting errors related to 'Cannot implicitly convert type UnityEngine.GameObject to UnityEngine.GameObject[], which I understand its because it isnt being assigned as an array? But, when I try to change the code to something that doesn't show an error, I still don't think it is seeing the array as null? I'm not sure.

swift elbow
#

you have to use FindGameObjectsWithTag

silent dove
#

yeah, i noticed that in one of the solutions, i should've mentioned but that's what i was trying when it would have no errors, but wouldn't do anything

swift elbow
silent dove
#

right that's why i added uhh the print part, to see if that was the issue, and i believe it is

#

basically, when i destroy all of the enemies, the enemyList array should be null, but the print and function being invoked aren't running

swift elbow
silent dove
#

is it not?

swift elbow
#

when there are no elements in an array, the array doesnt "become null"

#

you should iterate through a for loop to check if all elements are null

#

that should work

silent dove
#

i was looking at code recommended in a tutorial, but i'll look at doing that and see how it goes

#

I'm not entirely sure how to go about this, I have this for the iteration, I'm not sure if it does work or not for sure
But if it does work, I'm not sure how to call a way for it to say like, an if statement for if it is true?

static bay
#

Wait sorry let me get this straight.

#

You want to have it so when all the enemies die, the scene resets after 2 seconds?

silent dove
#

Yeah, that's the idea,

cosmic dagger
static bay
# silent dove Yeah, that's the idea,

The code above unfortunately isn't going to do it then. When you call FindGameObjectsWithTag, the array will contain all game objects with that tag in that moment. If you're destroying enemies when they die, then the entries in that array will progressively become null, but not the array itself.

cosmic dagger
#

it's an array, so it has a fixed size. it's length would never be zero (unless you initialize it that way) . . .

static bay
silent dove
silent dove
# static bay This function would work for checking that.

My issue is just that, in our class we haven't done like anything with bools, and I'm not sure how to go about making the if statement for if the bool is true, and if I did that I think it should be fine? Does the enemyList == null work in this case? I'm not sure if it's trying to see if the array is null or if it's contents are null, should I do enemyList.Length instead?

rich adder
static bay
silent dove
#

So, I guess I can try the list if that would work out easier? Or would I just need to use enemyList.Length or something like that?

rich adder
#

use a list, check the Count each time enemies removes itself

silent dove
#

Yeah I think I found something online that uses a list that would work.

#

I'll try that rq

rich adder
#

as long as enemies have reference to that list in like a manager type script

static bay
#

Navaron is suggesting the correct solution. It just might be tough given what you know.

static bay
#

🙃

#

How many GameObjects could they possibly have in the scene?

#

It's fiiiiine.

#

We're fiiiine.

swift elbow
static bay
# swift elbow not a lot of people know this, but unity actually does this on its own 😁 . Its ...

wanna support me ?? 😊😊 😇😇 💓

or just subscribe.. that would mean a lot too 😇😇😊😊💓💓🙏

device - vivo z1x /

             disclaimer -

I do not own any of the music. copy right their rightfully owner.

" copyright disclaimer under section 107 of the copyright act 1976, allowance is made for "fair use'' for purposes such as Criticism, comme...

▶ Play video
swift elbow
#

very very true

silent dove
#

Alright, so, using a a list instead, I would need to change it away from FindGameObjectsWithTag right?

rich adder
#

ideally yes

static bay
silent dove
#

Well, they had mentioned it, and I found something that had this code.
So, I thought that having a list might work? But right now I'm having an issue with List<GameObject> 'does not contain a definition for 'count''

rich adder
north kiln
eternal falconBOT
swift elbow
#

the same way you cant use "count" for arrays

rich adder
#

wdym you found a script?

silent dove
#

when looking for other people having similar issues, this one person said they found a solution using a list instead, and it seemed pretty similar to what i was needing to do

rich adder
#

just start from the basics tbh

north kiln
#

You need to configure your IDE before continuing with any coding, as not having error highlighting and proper autocomplete is a waste of your time

silent dove
static bay
#

Listen to vertx first, get your IDE set up so it can help you understand what's going wrong.

#

And then you can tackle the problem.

silent dove
#

I can look at it, but I don't really understand this stuff, that's the issue uhh

north kiln
#

it's literally just instructions you follow, that I linked

swift elbow
static bay
#

Disgusting quaternion lover BEGONE.

silent dove
teal viper
static bay
#

Visual Studio Code is an IDE.

#

Just follow the steps.

rocky canyon
#

the good stuff happens after Install part

teal viper
#

Or maybe that was a joke attempt about how VSCode is not a real ide...😅

teal viper
#

"I'm looking at VSCode but I don't see ide anywhere"

static bay
#

Massive disrepect

silent dove
#

so i just need the unity extension?

static bay
#

Incoming "But I have this Vim thing here"

north kiln
silent dove
#

okay i have that then and it showed i just had one of the counts in lowercase? and its saying no issues but i guess the code won't be working since it isn't made for it, since still no print or function invoked

static bay
#

do you see red underlines

silent dove
#

no

#

So I'm assuming its the loop itself not working in this case.

rich adder
#

looks configured

#

but what do you think that backwards loop supposed to do

static bay
#

What?

rich adder
rich adder
static bay
#

Why is it lowercase?

rich adder
#

omage to java idk

static bay
#

very odd

rich adder
#

same reason camel case properties 🤷‍♂️

static bay
rich adder
#

or maybe infection from having a javascript like language at some point..

static bay
static bay
silent dove
#

right, im back now uhh,,

#

right, so it more than likely means that what they were trying to do isnt similar at all, I'm not sure how to actually get all of the enemies, I'm assuming I need to use something with the finding everything tagged as enemy, but i'm not sure how to put this into a thing to add to the list either, for knowing if an enemy dies I would need to check if it's null I assume, and if the list's count is 0 then that would mean there are no more enemies

rich adder
silent dove
#

already spawned

rich adder
#

drag n drop them in the List

#

multi select

#

that should give you pretty much a list/count amount, from there just need to tell from enemy script to count/list script. " I died, remove me from list"

silent dove
#

alright, cool i didnt know you could do that, so the for loop probably shouldnt be reversed like that i assume?

static bay
silent dove
#

alright, how should i check it then?

rich adder
rich adder
static bay
rich adder
#

they already were using FindWithTag

#

its not much more complex, change the tag to script with List of enemies counter

static bay
#

and call remove during OnDestroy on the enemy?

rich adder
#

whatever Death method enemy has yeah they call Removal function

static bay
#

alright

rich adder
#

its much simpler than polling everyframe with loops and whatever they were mashing

#

creating an array every frame is atrocious

static bay
static bay
silent dove
#

the stuff for the enemy's death is in the laser's script, so basically when the laser collides with the gameobjects tagged as enemy, it destroys the enemy and the laser

rich adder
# static bay yes very bad

either way they would need reference to the array to do removal at index, figuring out which index enemy is etc..

static bay
rich adder
#

enemy needs a script if you don't have one for sure

silent dove
#

they have a movement script

static bay
#

Just give them a new one.

#

It's fine.

silent dove
#

alright

static bay
rich adder
#

as long as they understand why they are using this method 😅