#๐Ÿ’ปโ”ƒcode-beginner

1 messages ยท Page 291 of 1

hexed terrace
#

this is not what was said to do.

fathom frigate
#

One message removed from a suspended account.

hexed terrace
#

that's also the same video as before

fathom frigate
#

One message removed from a suspended account.

hexed terrace
#

and press play before starting your recording.. we don't need to see the 5 seconds of play mode laoding ;p

rocky canyon
fathom frigate
#

One message removed from a suspended account.

#

One message removed from a suspended account.

fathom frigate
rocky canyon
#

Pause -> Play -> Start Recording -> Unpause (secret sauce)

hexed terrace
#

no need for the pause in this case

rocky canyon
#

lol, its my preferred method.. b/c ShareX takes ages to Initialize sometimes

hexed terrace
#

Just depends if the issue happens on load or not

rocky canyon
#

soo.. shun, are u following a tutorial.. or just making this as u go?

fathom frigate
rocky canyon
#

lol ๐Ÿ˜ฌ

fathom frigate
#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

rocky canyon
#

Vectors

hexed terrace
fathom frigate
#

One message removed from a suspended account.

#

One message removed from a suspended account.

languid spire
rocky canyon
#

here you are basically rotating the the camera on its X and Y axis

prime cobalt
#

How can I check if an object is currently in a camera's field of view?

rich adder
#

also dont multiply by time.deltaTime

rich adder
rocky canyon
#

in my variation i Only rotate the camera on the Y axis.. and then i rotate my CC object on its X axis

#

this seperates teh two rotations and makes it simple for my CC to just move the direction its facing

fathom frigate
prime cobalt
languid spire
rocky canyon
#

fun is objective ๐Ÿ˜ˆ (it def gets fun),
at the beginning not soo much fun (until it is)

heavy temple
#

can someone help me please. I am using Visual Studio 2022
I am trying to type the word private
but it wont let me.

#

what do i need to do

rocky canyon
#

type it inside the class

languid spire
rocky canyon
#

and not outside the } ending bracket of the class

heavy temple
fathom frigate
ivory bobcat
rocky canyon
heavy temple
#

im following this guys video but he opens visual studio code and his base code is differnt from mine.

rocky canyon
heavy temple
# rocky canyon

ok yeah when he opens code his bracket is right there always

north kiln
#

And fix your errors before continuing

#

It isn't going to help if you try to write code when your code is broken

heavy temple
north kiln
heavy temple
#

please stop talking if your not going to help

north kiln
#

Start with the other error before trying to add to your code

wintry quarry
#

He's helping you

heavy temple
# rocky canyon

when he opens visual studio code his code ends here at the bracket you highlighted

#

i got a bunch of other shit in my code

#

my code doesnt even have that bracket

wintry quarry
#

You're putting the "other shit" in the wrong place

rocky canyon
#

you have to add and remove brackets as u need them

rich adder
hexed terrace
#

would be a great idea for you to go and learn what a class is, a method, their signatures ..etc, the basics, so these mistakes aren't made anymore and you can fix them yourself

ivory bobcat
#

You should not put other shit below that closing brace

heavy temple
#

this is what i mean

languid spire
north kiln
#

Nor the character immediately after that

heavy temple
#

there is no plan. I want to know my scripts start with 9 extra lines of code

hexed terrace
# heavy temple this is what i mean

They've either edited their default script template, or deleted it in the video and you missed/ ignored it.

It doesn't take any coding knowledge to work out how to get your class in the same state as theres -> delete the extra code

heavy temple
#

i am copying this guys script exactly

fathom frigate
#

One message removed from a suspended account.

heavy temple
#

and i cant even type the word private

rocky canyon
languid spire
rocky canyon
#

if u delete all the junk in the middle.. its the same format

#

one { and another }

hexed terrace
north kiln
ivory bobcat
#

Make sure you're aware of what Steve has pointed out (the extra {})

heavy temple
rocky canyon
#

the tutorial doesn't have this line

heavy temple
#

because my fucking code template is different...

hexed terrace
#

so.... fucking delete the extra code ๐Ÿ˜„

north kiln
#

There are other errors in the file. You will not be able to consistently type private until you fix them.

rocky canyon
#

its teh exact same.. delete the stuff in the middle!

hexed terrace
#

your template is the default template that everyone has

rocky canyon
#

and then its the exact same as the screenshot u sent..

tender stag
#

lets say i had a game object with a collider

#

and it had a script

heavy temple
#

terrible help

hexed terrace
#

you have a game object with a collider

tender stag
#

and then i did GetComponentInParent

heavy temple
#

but i get what your saying

tender stag
rocky canyon
#

these two scripts are the exact same

tender stag
#

or only in the parent od that collider

ivory bobcat
polar acorn
# heavy temple i am copying this guys script exactly
I did it exactly like the tutorial so why does theirs work and mine doesn't" counter:
Number of times it wasn't exactly like the tutorial: 153
Number of times it was exactly like the tutorial: 5
Number of times the code literally did not exist: 1
2022-07-19 to 2024-4-05
heavy temple
#

holy fuck you people are terrible

#

sorry not even is not as smart as you

rocky canyon
#

and ur fucking blind

#

ur code is not the same.. open ur fucking eyes

heavy temple
#

lol im sorry i didnt write the word trying in my sentence

#

im am TRYING to copy his code

rocky canyon
#

yea, and the error is U DIDNT

#

we can't help u with reading

hexed terrace
#

calm

heavy temple
#

ill go back to learning and you guys can go back to whatever the fuck your doing

#

thanks for helping

tender stag
hexed terrace
#

the docs I linked to tell you

tender stag
#

yeah but its quicker to ask

tender stag
rich adder
north kiln
hexed terrace
tender stag
#

its kind of hard while trying not to get hit by a car

rocky canyon
rocky canyon
tender stag
#

i want to know before i get home

#

lmao

#

so i dont have to waste time

#

if i was on my pc fair enough

#

iโ€™d look through the docs first

hexed terrace
#

I mean, you're typing in and reading Discord.. you could have just googled it and read the docs

rich adder
#

download the whole unity API into your phone thinksmart

tender stag
hexed terrace
#

it's a short sentence in the docs ๐Ÿ˜„

north kiln
#

Not sure you can really use offline docs on a phone, but maybe there's some sort of reader for stuff like that

rich adder
#

yeah I use it often

north kiln
#

On a phone?

rich adder
#

its like a pocket unity bible

#

yea

tender stag
#

smart

north kiln
#

Huh, does the site just work straight from files or something

rich adder
#

they are just html files

tender stag
#

im guessing its like a pdf

tender stag
north kiln
#

Yes, I'm just surpised phones can navigate that properly from their weird-ass file systems

#

But not entirely unexpected. Good to know

heavy temple
rocky canyon
tender stag
#

theyโ€™ve been helping here longer than u were alive

heavy temple
timber tide
#

ya need to learn general code and scripting before touching unity

tender stag
#

im pretty sure they are right

north kiln
#

dude uses "virtue signaled", fucking red flag if I've seen one

timber tide
#

unity isn't easy to just jump into with little coding knowledge

rocky canyon
#

and if u didn't notice Vertx is a Moderator.

#

funny to tell the moderator to stop talking

#

in his own discord

heavy temple
#

lol

hexed terrace
whole idol
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static scr_Models;

public class scr_CharacterController : MonoBehaviour
{
    private DefaultInput defaultInput;
    public Vector2 input_Movement;
    public Vector2 input_View;
    private Vector3 newCameraRotation;
    [Header("References")]
    public Transform cameraHolder;
    [Header("Settings")]
    public PlayerSettingsModel playerSettings;
    private void Awake()
    {
        defaultInput = new DefaultInput();
        defaultInput.Character.Movement.performed += e => input_Movement = e.ReadValue<Vector2>();
        defaultInput.Character.View.performed += e => input_View = e.ReadValue<Vector2>();
        defaultInput.Enable();

        newCameraRotation = cameraHolder.localRotation.eulerAngles;
    }
    private void Update()
    {
        CalculateMovement();
        Calculate_View();
    }
    private void Calculate_View()
    {
        newCameraRotation.x += playerSettings.ViewYSensitivity * input_View.y * Time.deltaTime;
        cameraHolder.localRotation = Quaternion.Euler(newCameraRotation);
    }
    private void CalculateMovement()
    {

    }
}

heavy temple
#

all youve told me is this is not the place to come for information

#

ill see you guys later

rocky canyon
north kiln
rich adder
north kiln
eternal falconBOT
hexed terrace
summer stump
rocky canyon
north kiln
#

They left, and there was peace in the land

whole idol
hexed terrace
#

but for how long

north kiln
rich adder
whole idol
north kiln
#

Can you check again?

whole idol
rich adder
#

jesus

north kiln
#

Then try restarting Unity

whole idol
#

based

rocky canyon
#

its the go-to when nothing makes sense ๐Ÿ˜„

whole idol
rich adder
#

cause the bottom errors dont make sense
cs0708

north kiln
#

It all stems from the one error that has now been resolved.

rich adder
#

ah ok myb

whole idol
#

I have entered safe nerd mode cause apparently the issue hasn't been resolved, or it's not related to Unity being buggy

north kiln
#

Is the first error still there? If it's gone then you can start trusting the other errors

whole idol
north kiln
#

It looks like your scr_Models script file tries to redeclare scr_CharacterController

polar acorn
# whole idol

Start from the top. You have two scr_CharacterController classes

rich adder
#

did they show scr_Models script?

whole idol
# rich adder did they show scr_Models script?
using System;
using System.Collections.Generic;
using UnityEngine;

public static class scr_CharacterController
{
    #region - Player -
    [Serializable]

    public class PlayerSettingsModel
    {
        [Header("View Settings")]
        public float ViewXSensitivity;
        public float ViewYSensitivity;



        public bool ViewXInverted;
        public bool ViewYInverted;
    }
    #endregion
}

rich adder
#

well there u go

rich adder
#

same name of class

north kiln
#

Well there's your problem, why does scr_CharacterController exist in scr_Models

whole idol
#

Oh I just noticed that

rich adder
#

filenames and class dont match, sweet

tender stag
rich adder
#

was about to say cause it wasnt declared as static in other file

polar acorn
#
  1. Class name you're already using
  2. Static class that has non-static things in it
  3. Class inside of a static class
#

This is just very wrong

rich adder
tender stag
#

nah

#

iphone

#

thats why

rich adder
#

prob. I have custom app for reading html properly so links work

#

iphone doesnt let u mess with files easily

north kiln
#

Haven't checked but that should compile, the general issue is just the class name collision

#

Presumably the actual character controller is a non static MonoBehaviour and all the other errors are trying to resolve some imaginary partial class amalgam of these two

short hazel
#

Also why the scr_ prefix? If you want to categorize classes by their purpose, use namespaces

hexed terrace
#

what does scr even mean? Script? -> pointless

It's just gonna be a pain later on when you have 20+ scripts all starting with the prefix

rich adder
#

for me It buggs me when people even do SomethingBase for base classes notlikethis

hexed terrace
#

๐Ÿ™‚

north kiln
#

ECS development is suffixtown

hexed terrace
polar acorn
whole idol
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static scr_Models;

public class scr_CharacterController : MonoBehaviour
{
    private DefaultInput defaultInput;
    public Vector2 input_Movement;
    public Vector2 input_View;
    private Vector3 newCameraRotation;
    [Header("References")]
    public Transform cameraHolder;
    [Header("Settings")]
    public PlayerSettingsModel playerSettings;
    public float viewClampYMin = -70;
    public float viewClampYMax = 80;

    private void Awake()
    {
        defaultInput = new DefaultInput();
        defaultInput.Character.Movement.performed += e => input_Movement = e.ReadValue<Vector2>();
        defaultInput.Character.View.performed += e => input_View = e.ReadValue<Vector2>();
        defaultInput.Enable();

        newCameraRotation = cameraHolder.localRotation.eulerAngles;
    }
    private void Update()
    {
        CalculateMovement();
        Calculate_View();
    }
    private void Calculate_View()
    {
        newCameraRotation.x += playerSettings.ViewYSensitivity * input_View.y * Time.deltaTime;
        newCameraRotation.x = Mathf.Clamp(newCameraRotation.x, viewClampYMin, viewClampYMax);
        cameraHolder.localRotation = Quaternion.Euler(newCameraRotation);
    }
    private void CalculateMovement()
    {

    }
}

UnassignedReferenceException: The variable cameraHolder of scr_CharacterController has not been assigned. You probably need to assign the cameraHolder variable of the scr_CharacterController script in the inspector. UnityEngine.Transform.get_localRotation () (at <17484a9af6b944dea5cd9be4dbb0da2c>:0) scr_CharacterController.Awake () (at Assets/Scripts/Character/scr_CharacterController.cs:23)

#

I did assign it

polar acorn
whole idol
#

It's right here

north kiln
#

Then there's probably another instance in the scene

polar acorn
short hazel
whole idol
polar acorn
rocky canyon
#

:sus: soo.. fixed then? lol

whole idol
#

thanks ๐Ÿค

hexed terrace
#

Much like the Emperor, somehow returning

rocky canyon
#

ive got some worker errors like that.

#

unity version change was the solution ๐Ÿ˜…

dreamy urchin
#
public GameObject slime;
private GameObject player;
private Transform playerPos;

public int slimeToSpawn;
private Vector3 position;
float TimeT = 0;
bool spawned = false;

public int minX;
public int maxX;
public int minY;
public int maxY;

public string buttonName;


private void Start()
{
    player = GameObject.Find("MC"); 
    playerPos = player.GetComponent<Transform>();
}

private void Update()
{
    if (!GameObject.Find(buttonName))
    {
        TimeT += Time.deltaTime;
        if (slimeToSpawn > 0 && !spawned)
        {
            position = new Vector3(GetX(), GetY(), 0);
            SpawnSlime();
            slimeToSpawn--;
            spawned = true;
        }

        if (TimeT > 1)
        {
            TimeT = 0;
            spawned = false;
        }
    }
}

private void SpawnSlime()
{
    Instantiate(slime, position, Quaternion.identity);
}

private float GetX()
{
    float x = 0;
    do
    {
        if (Random.Range(0, 2) == 0) x = Random.Range(minX, maxX);
        else x = Random.Range(minX, maxX) + 0.5f;
    } while (playerPos.position.x - x < 2 && playerPos.position.x - x > -2);

    return x;
}

private float GetY()
{
    float y = 0;
    do
    {
        if (Random.Range(0, 2) == 0) return Random.Range(minY, maxY);
        else return Random.Range(minY, maxY) + 0.5f;
    } while (playerPos.position.x - y < 2 && playerPos.position.x - y > -2);
}

I made that code to instantiate a gameobject every second at a different location and it has to spawn away from the player, I made a prefab for the slimespawner, the first object of the prefab works, the second one spawns 3 slime at a time for five time, so he decrements slimeToSpawn once but spawns 3 objects

#

These are the 2 different objects

carmine sierra
#

!code

eternal falconBOT
carmine sierra
#

https://paste.ofcode.org/3aBxksJzQ9jZ5MFyxCEaykM
My code destroys a game object but apparently this same script tries to access the destroyed gameobject again (but the last time it is mentioned is when it is destroyed), what could be the issue? The error stems from the breakwoodwherenecessary() function

prime cobalt
#

Is there a way to check if a ui element is being masked?

hexed terrace
delicate venture
#

am i doing something wrong? (i mean cleary i am)
the audio manager is in another scene and im trying to call him out from another scene

hexed terrace
#

audioManager = FindObjectOfType<AudioManager>()

Or make AudioManager a singleton

#

Awake is ran once, so maybe Awake on this is ran before the audio manager exists

#

but you haven't actually said what the problem is

rich adder
#

you need a singleton for that

carmine sierra
hexed terrace
#

do forr in vs then tab

#

and it's a keyphrase that you can google to learn more about it

carmine sierra
hexed terrace
#

no, replace it

#

a reverse loop starts at the end, and works towards the beginning, this allows you to remove items from a list as you go

#

doing a forward loop causes issues if you remove items

carmine sierra
#

so aswell as destroy .remove()?

hexed terrace
#

destroy gameobject
remove index

carmine sierra
#

ohh okay

#

how comes that doesn't work when counting up (if i need to remove the list index value myself)

hexed terrace
#

because you change the count

delicate venture
hexed terrace
#

first time round loop, index 0.. -> destroy object, delete index
element 1 is now element 0, second time round loop is now checking index 1, so what's now in 0 has been skipped

rich adder
dreamy urchin
#

https://gdl.space/yowuyewuxi.cpp

I made that code to instantiate a gameobject every second at a different location and it has to spawn away from the player, I made a prefab for the slimespawner, the first object of the prefab works, the second one spawns 3 slime at a time for five time, so he decrements slimeToSpawn once but spawns 3 objects
These are the 2 different objects

hexed terrace
#

the first object of the prefab works, the second one spawns 3

this isn't clear. Do you mean SlimeSpawner works fine, but SlimeSpawner (1) doesn't?

carmine sierra
#

if it were reverse you could miss some

hexed terrace
#

starting at max, say, 9.. then removing 9.. the other elements don't change position

delicate venture
rich adder
carmine sierra
#

THANK YOU @hexed terrace it works

dreamy urchin
hexed terrace
delicate venture
dreamy urchin
hexed terrace
#

didn't understand what?

I've no idea what your issue could be

dreamy urchin
#

oh, alr ty anyway

delicate venture
hexed terrace
dreamy urchin
hexed terrace
#

You need to try different things to troubleshoot the issue.

The second spawner has the issue, so remove the other from the equasion and then work out the next move

native seal
#

Is there a interface similar to IPointerEnterHandler that will get called every frame while an element is hovered?

rich adder
#

or something

#

ah no

#

you need two bools and use Update probably

native seal
#

or do i just do some bool for on enter/exit and upd

#

yea

#

ok

floral roost
#

How do I stop friction on the side of things, because whenever I jump to the side of something, it can just stick like this

rich adder
#

i suppose you can try the no-friction material thing

#

but its a crapshoot half the time

floral roost
#

if i were to do the no friction wouldnt i just slide everywhere on top of the platform

rich adder
#

not if you got drag

queen adder
#

Hi guys i accidently deleted something from my assets that i didnt know what it did, now background is purple. Anyone have any idea? it was a "material"

frosty hound
#

It was the material that was on the background. Select it and put another material on it.

#

Also not a coding question

queen adder
#

ok where would i put this question. Sorry.

#

and thank you

native seal
#

anyone with experience using scenereference know how I can reference a scene using an onclick unity event? ie I want to select one here

#

the function that takes in a scene doesn't appear

rich adder
#

Scene isn't serialized type

wintry quarry
#

string is your best shot

#

or int (build index)

native seal
#

so no real point using scenereference then

#

since you could just load it by index anyway

burnt wing
#

does anyone know how to make a clickable button in game (fps, so no cursor)?

#

i'm making a grapple game

rich adder
#

or you mean physical world button

burnt wing
#

no like a textmeshpro button

burnt wing
rich adder
#

make it a mesh no ?

gray spire
#

Ima be honest using VS code is kinda pissing me off because im creating a game and every time i open a new C# script it redownloads itself when i had just installed it.

rich adder
#

you can use world canvas with button but you have to modify the Input module to work with fps view (locked cursor)

burnt wing
#

aight

gray spire
#

VS Code

rich adder
#

from where?

#

i never seen on any pc an app downloading itself lol

#

unles like a virus ig

gray spire
#

ike every time i open it, I see the set up window for Microsoft VS Code

#

and it puts me through the set up

rich adder
#

or watever

gray spire
#

thats not an option

#

it just keepts telling me to install VS code.

rich adder
gray spire
#

this one

rich adder
#

I have no idea why it would keep showing that unless you clicked the intaller yourself ๐Ÿคทโ€โ™‚๏ธ

gray spire
#

Nope, I have a desktop shortcut for it and for some reason it doenst seem to detect that I have it installed

#

It doesnt even open my script after "downloading" it

prime cobalt
#

How do I find which UI element is closest to the center of the screen?

young fossil
#

What is the difference between a C# (automatic) property and a public variable?

rich adder
#

for starter one is a field and ones a property

#

property is like a method that runs every time you change it or access the variable

swift elbow
young fossil
rich adder
#

not much diff i suppose

young fossil
#

Right now, not much difference seems like no difference

prime cobalt
rich adder
#

get' and set are very powerful to use

young fossil
#

Been doing C++ and came back to C#. Not used to stuff doing loads for you with a couple of keywords like this

rich adder
#

What if I want an event to happen every time I set a value ?

wintry nest
#

anybody know how i can do something like this to make it work? GameObject objectCanvas = GameObject.Find("Object") || GameObject.Find("Other Object");

rich adder
#

gameobject.find one of the wrose methods to use

young fossil
rich adder
wintry nest
rich adder
#

You should not be using strings to find objects

#

that is brittle and error prone

#

plus very slow

wintry nest
#

oh do object references?

young fossil
# wintry nest anybody know how i can do something like this to make it work? ```GameObject obj...

Sorry, not understanding what you mean. Missing vital info in your question.

As navarone said, avoid using GameObject.Find. It's bad because:

  1. A name is not a reliable value, it's just a string value that is not unique, meaning you can end up with dupilcates.
  2. An extension of 1. The method doesn't tell you there's duplicates if there are, it just returns the first one it finds. Terrible for debugging.
  3. I've heard that due to the fact it searches every gameobject it isn't performant
rich adder
wintry nest
#

kk, ty, ig ill just switch out of Find

young fossil
wintry nest
queen adder
#

i just started and am watching a tutorial on how to use unity and i made a cube jump but the cube is supposed to jump higher when i hold jump any ideas why it isn't

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

public class PlayerMovement : MonoBehaviour {

[SerializeField] private Rigidbody2D rb;
[SerializeField] private float jumpForce = 10f;
[SerializeField] private LayerMask groundLayer;
[SerializeField] private Transform feetPos;
[SerializeField] private float groundDistance = 0.25f;
[SerializeField] private float jumpTime = 0.3f;

private bool isGrounded = false;
private bool isJumping = false;
private float jumpTimer;

private void Update() {
    isGrounded = Physics2D.OverlapCircle(feetPos.position, groundDistance, groundLayer);

    if (isGrounded && Input.GetButtonDown("Jump")) {
        isJumping = true;
        rb.velocity = Vector2.up * jumpForce;
    }

    if (isJumping && Input.GetButtonDown("Jump")) {

       if (jumpTimer < jumpTime)
        {
            rb.velocity = Vector2.up * jumpForce;

            jumpTimer += Time.deltaTime;
        }   else {
            isJumping = false;
        }

    }
    if (Input.GetButtonUp("Jump")) { 

        isJumping = false;
        jumpTimer = 0;
    }
}

}

young fossil
eternal falconBOT
young fossil
queen adder
swift elbow
rich adder
rich adder
rich adder
#

reading code like that in the discord chat is a pain

#

esp on mobile

queen adder
#

ok i will im sorry

young fossil
#

Thanks navarone

queen adder
summer stump
#

You click a link

#

You copy your code into the website

#

You click save

#

You copy the changed url

#

You paste that url here

queen adder
#

like that?

summer stump
#

Yep

queen adder
queen adder
summer stump
#

The second if was likely supposed to be GetButton not GetButtonDown

#

If it WAS supposed to be GetButtonDown, then the tutorial is wrong

queen adder
#

It works perfectly thank you so much !

summer stump
young fossil
#

Another quick question about C# properties. Is it good practice to declare them and not leave them to default values? Even if it's an automatic property.

rich adder
#

you mean assigning value on initializer ?

young fossil
#

So for example

public int CarAge = 10;

I could just write ```cs
public int CarAge;

swift elbow
#

thats an error

rich adder
#

yes

#

you dont have to assign values

#

especially to value types

#

they all have defaults

young fossil
#

Isn't that bad practice?

wicked stratus
#

say i have a dictionary/list of a custom class- is there a way to instantiate a gameobject with that component, not just a clone of it? and can multiple gameobjects have that same compenent? (again, not just a clone, but a reference to the single component in the master dict/list)

rich adder
young fossil
#

Problem with automatic ones, it sort of forces you to use a default value

#

I am using it with bools

native seal
#

im blanking on c#, does setting an array = to another do a deep or shallow copy

rich adder
#

its the same object

#

sharing the same address of same house

native seal
#

so array.copy is needed

rich adder
#

it works

#

you can also use linq

#

but prob overkill lol

native seal
#

but if the array contains value types it will copy fine correct

#

enums, ints, etc

rich adder
#

it should

#

you can also use .Clone

young fossil
#

All makes sense. Thanks

rich adder
#

unless it was like a const

young fossil
#

What I meant is I can write

    public bool GameIsPaused
    { get; set; } = true;
``` assigning it true on declaration to avoid ambiguity of defaults
rich adder
#

yeah ig. if you don't then its false no biggie

kindred nest
rich adder
#

good/bad practices considering

wicked stratus
#

and i need to do it programmatically (? is that a word?) not via dragging

#

would i just do something like:

#
  obj.addcomponent<componentthatneedstobeadded>() = reftomastercomponent;
kindred nest
#

oh I think i see what you mean, there is a much simpler solution then

wicked stratus
#

basically if i instantiate multiple objects with a component set to the master component, if one changes, will they all change

#

i am not great at phrasing questions

north kiln
#

Just pass one pre-existing instance to the newly instanced object

wicked stratus
#

and if thjat one changes it will change all of them, yea?

north kiln
#

There is only one

kindred nest
#

say you have a component <Enemy> and you want each enemy to hold a reference to <EnemiesMaster> or whatever, but you create them at run-time, so whenever you instantiate an <Enemy> you can A. pass it the reference then B. create a prefab where you can have a serialized field (assuming that the master is placed in the scene and probably should)

wicked stratus
#

let me explain my problem with the context, i think that may help

north kiln
#

You don't need to copy the component to every instance, you just need every instance to reference the single original component

wicked stratus
#

I have a bunch of samples that the player needs to analyze, and each sample is unique. you can have many of these samples at once, i.e. you can have 4 sample#1s, but the sample itself contains data on whether it's been analyzed or not, and if they have analyzed sample#1 then it should reflect in each of the sample copies as well

kindred nest
wicked stratus
#

i want each of these sample copies to have the same sample object, not copies

#

the sample object that is held in a dictionary

#

so like if there's a code on the instantiated object that's like

#
public void initializesample(sample ourSample){ //oursample would be sent in like so: initializesample(masterSampleDict[sampleneeded])
  sample = oursample;
}
#

would this accomplish that

north kiln
#

Yes

wicked stratus
#

ok, thank you

#

i'm trying to get better with phrasing ๐Ÿ˜ญ

#

I think some languages handle references differently and I always forget which ones do what

kindred nest
#

Just give it a guess first, see if it is a reference or not, i often just try-and-error, you can have some hilarious bugs on the way, just play with it and see what happens! Best way to learn for me, maybe not the most "optimal" but what the hell, make it fun

wicked stratus
#

thanks, haha, I'll work on that more too

karmic kindle
#

Hey, I'm trying to create a second path in my class, but I can't work out how to reference the other path in my movement script - is it possible without changing the whole code?


    public bool pathOne, pathTwo;
    public static Transform[] points;

    // Calculating the length of the path
    public static float totalLength = 0;
    public int calculatePath = 0;

    void Start ()
    {
        if(pathTwo)
        {
            points = new Transform[transform.childCount];
            for (int i = 0; i < points.Length; i++)
            {
                points[i] = transform.GetChild(i);
            }
        }
        else
        {
            points = new Transform[transform.childCount];
            for (int i = 0; i < points.Length; i++)
            {
                points[i] = transform.GetChild(i);
            }
        }
        PathLength();
    }```
#

How it's being referenced ```void GetNextWaypoint()
{
if (wavepointIndex >= Waypoints.points.Length - 1)
{
EndPath();
return;
}

    //furthestOnPath += 10f;
    ++wavepointIndex;
    target = Waypoints.points[wavepointIndex];
    runBack = false;
}```
timber tide
#

Then make yourself a List of Waypoints and reference by index, or just declare two WayPoints:
public Waypoints Waypoints1;
public Waypoints Waypoints2;

karmic kindle
karmic kindle
timber tide
golden obsidian
#

anyone know, why it wont allow me to drag the UI elements to my Script Fields? It just shows a back circle with a slash through it, but ive tried both with Text and Textmesh pro, for the text field, and now its not allowing me to do any buttons or input fields either?

timber tide
#

those are default reference fields which is usually for debugging. You should be inserting it directly into the object on the scene itself

teal viper
#

And you can't reference scene objects from outside the scene

timber tide
#

yeah, if it lives in your assets, it must be part of some instance like a prefab

golden obsidian
#

oh thank you i forgot to make a game object for the script so that makes sense

karmic kindle
timber tide
#

If you want to add all paths to a single WayPoints class then you need an array of points for each path such that:
public Transform[] pathPoints1;
public Transform[] pathPoints2;

#

Then for your method you can make a secondary such that:

void GetNextWaypointFromPath1()
void GetNextWaypointFrompath2()
#

Or if you make a List/Array of path points then you can make a method such that

void GetNextWaypointFromPath(Transform[] points)
#

You also need some indicator for what path you want to use, but I wouldn't suggest using a bool since that only restricts you to two different values

karmic kindle
#

Thank you very much for that. I'm trying to be flexible for a tower defense game, I was hoping that I could set a "startpoint" and then the enemy would follow the path that is made up of those child items. I'm being a total beginner by using bools to just set pathOne/Two/Three, as/when needed... In hope that I don't have to edit all of my prefabs

#

I'm controlling the spawnpoint when I want to use a different point like this, so I am trying to set a bool which could tell the enemy the path as well foreach (EnemyBlueprint enemy in wave.enemyWave) { if(enemy.enemySpawn != null) { spawnPoint = enemy.enemySpawn; } else { spawnPoint = defaultSpawnPoint; }

bright zodiac
rich adder
karmic kindle
timber tide
# karmic kindle When testing, if I set the pathTwo bool & remove the other reference, the enemie...

A single WayPoint class is useful if you have a single instance such that it's the manager of these waypoints that all enemies reference. So, each enemy would only need to ask the manager for the path they are assigned to. The multiple different waypoint instances of the class that contains a single path each is useful if you do want to have a single array of waypoints per enemy, such that each enemy would be assigned an instance with a specific (or unique) path to follow.

I'd usually prefer the first solution, and just have all enemies grab from the manager as that's a lot less arrays of points you need to be instantiating.

whole idol
#

My player seems to be glued in place. It's like trying to convince a cat to take a bath. Is there anything wrong with the code?

#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static scr_Models;

public class scr_CharacterController : MonoBehaviour
{
    private CharacterController characterController;
    private DefaultInput defaultInput;
    public Vector2 input_Movement;
    public Vector2 input_View;
    private Vector3 newCameraRotation;
    private Vector3 newCharacterRotation;
    [Header("References")]
    public Transform cameraHolder;
    [Header("Settings")]
    public PlayerSettingsModel playerSettings;
    public float viewClampYMin = -70;
    public float viewClampYMax = 80;

    private void Awake()
    {
        defaultInput = new DefaultInput();
        defaultInput.Character.Movement.performed += e => input_Movement = e.ReadValue<Vector2>();
        defaultInput.Character.View.performed += e => input_View = e.ReadValue<Vector2>();
        defaultInput.Enable();

        newCameraRotation = cameraHolder.localRotation.eulerAngles;
        newCharacterRotation = transform.localRotation.eulerAngles;
        characterController = GetComponent<CharacterController>();
    }


#
    private void Update()
    {
        CalculateMovement();
        Calculate_View();
    }
    private void Calculate_View()
    {
        newCharacterRotation.y += playerSettings.ViewXSensitivity * (playerSettings.ViewXInverted ? -input_View.x : input_View.x) * Time.deltaTime;
        transform.localRotation = Quaternion.Euler(newCharacterRotation);

        newCameraRotation.x += playerSettings.ViewYSensitivity * (playerSettings.ViewYInverted? input_View.y: -input_View.y) * Time.deltaTime;
        newCameraRotation.x = Mathf.Clamp(newCameraRotation.x, viewClampYMin, viewClampYMax);
        cameraHolder.localRotation = Quaternion.Euler(newCameraRotation);
    }
    private void CalculateMovement()
    {
        var verticalSpeed = playerSettings.WalkingForwardSpeed*input_Movement.y*Time.deltaTime;
        var horizontalSpeed = playerSettings.WalkingStrafeSpeed*input_Movement.x * Time.deltaTime;

        var newMovementSpeed = new Vector3(horizontalSpeed, 0, verticalSpeed );

        newMovementSpeed = transform.TransformDirection(newMovementSpeed);



        characterController.Move(newMovementSpeed);

    }
}
timber tide
#

Consider pasting your code to a pastesite

karmic kindle
timber tide
#

Sure, arrays work

rapid mountain
#

remove that collider, and paste your code to a proper website for better reading

#

!code

eternal falconBOT
honest vault
#

why does the player do this as soon as i put animations it stopped working

teal viper
#

Not code related too.

honest vault
signal tide
#

Hey I'm trying to make a multiplayer game with the help of a tutorial using photon..
Everything works fine if there is only one player present in the room but as soon as there are two players in the room.. controls just get swapped.
I control the other player's character and vice versa.
Can anyone help

rich adder
signal tide
hasty spire
slender nymph
#

you overwrite velocity every frame

hasty spire
slender nymph
#

yes. just like you are preventing Move from being called for the duration of your Dash, you need to do the same for the duration of your recoil if you want it to work correctly

hasty spire
#

dosent seem to work

slender nymph
#

you didn't bother providing any details about what isn't working about what you tried

hasty spire
slender nymph
#

and why do you think that is?

hasty spire
#

there are no references to my void Recoil()

#

wait no

#

thats not it

#

is it?

slender nymph
#

well that's obviously part of it. but you also need to rethink the order of operations

hasty spire
slender nymph
#

read through your logic and figure out when/where you change certain variables and under what conditions you change them

hasty spire
#

ok wait, isnt it as simple as adding Recoil(); to update

#

let me try that

#

tried it it seems to be working

#

im stupid

desert citrus
#

@slender nymph hey im sorry for tagging im not sure if im supposed to but i checked about object being centered and it looks right to me and also pivot point looks about right?

slender nymph
#

what object is that code rotating

desert citrus
#

the player.transform

#

i think if that is what you mean

slender nymph
#

you could show what object is assigned as playerTrans if you are unsure

#

but if it is rotating that root object, then make sure that the parent of the object shown in the video is also centered on its parent. and set your tool handle to Pivot instead of Center so you actually see the pivot point of your objects instead of the averaged "center"

desert citrus
#

aight i will try that thank you so much i will not spam you anymore haha ๐Ÿ™‚

rich egret
#

!code

eternal falconBOT
rich egret
#

The code: https://gdl.space/nazetihoda.cs

The Problem: The purpose of the script is that every time an object is added to the parentObject, it should save the name of the object in the list of prefabNames in the PlayerPrefs way, But the name is not added...

queen adder
#

Hey guys I have a question, how can I get an object position without caring about the parent it's in?
Like if I put an object as a child it transform changes but how can I ignore this feature if I'm getting an object position?

slender nymph
slender nymph
rich egret
slender nymph
#

why

rich egret
#

And I need the data to save forever

slender nymph
#

and why does that require you to save this data to playerprefs?
you can write it to a file in Application.persistentDataPath

queen adder
#

Well I want to get an object position and check if the player is clicking on its left or on its right.
The issue is that all the calculations are messed up since this object that I'm getting the position from is a child of another object so its transform position gets modified to the parent position and not to the world position anymore

slender nymph
#

it's transform.position property is the world space position

rich egret
#

Why are you so against it? ๐Ÿ˜‚

slender nymph
#

because you're trying to bloat users registry with useless data that should just be written to a file so that nobody has to go through and clear that shit out of their registry using sketchy tools or by looking manually

#

at least if you save it in AppData it can just be deleted from the file system easily

#

you're also going about saving this data in a very not good way. saving the string names of the gameobjects is silly. try looking into a tutorial for how to properly set up save data

rich egret
slender nymph
#

yeah that's not a good system

#

and it won't even work in a build considering that folder with all your prefabs won't exist in a build

rich egret
slender nymph
#

and it is incredibly flawed and should be scrapped so you can start over and do it right

#

you will have to completely redo this if you want it to work in a build, so attempting to get it working as just "a start" is not going to be beneficial since the entire system will need to be scrapped for something that works

rich egret
#

This is what I learned in YouTube tutorials

slender nymph
#

what tutorial

stuck palm
#

How can you make a browser open a link in code? Is that possible?

slender nymph
#

Application.OpenURL

stuck palm
#

Thank

#

You

sage mirage
#

Hey, guys! I have a small issue with my game here. So, when I am collecting the power ups and trigger the particles and I pause immediately and move to settings and then coming back my power ups particles and other particles are disappearing. I have my code to share with you if you can to provide some useful information in order to help me fix it please do it.

Go back to main game from settings method

{
    AudioManager.Instance.PlaySound(pressButtonSoundAudioSource, pressButtonSoundAudioClip);
    StartCoroutine(GoBackToGameButtonAfterDelay());
}

IEnumerator GoBackToGameButtonAfterDelay()
{
    yield return new WaitForSecondsRealtime(goBackDelay);
    RoundManager.Instance.currentState = GameState.Pause;
    optionsMenu.SetActive(false);
    SetObjectsActive(true, true, true, true, false, false, true);

    foreach (GameObject treeLog in treeLogsList)
    {
        if (treeLog != null)
        {
            treeLog.SetActive(true);
        }
    }
    foreach (GameObject gemParticle in gemParticleList)
    {
        if (gemParticle != null)
        {
            gemParticle.SetActive(true);
        }
    }
    foreach (GameObject powerUp in powerUpList)
    {
        if (powerUp != null)
        {
            powerUp.SetActive(true);
        }
    }
    foreach (GameObject powerBoostListParticle in playerPowerBoostListParticle)
    {
        if (powerBoostListParticle != null)
        {
            powerBoostListParticle.SetActive(true);
        }
    }
    foreach (GameObject powerBoostIncrease in playerPowerUpIncreaseScoreByTwoList)
    {
        if (powerBoostIncrease != null)
        {
            powerBoostIncrease.SetActive(true);
        }
    }
    foreach (GameObject powerBoostIncreaseListParticle in playerPowerUpIncreaseScoreByTwoListParticle)
    {
        if (powerBoostIncreaseListParticle != null)
        {
            powerBoostIncreaseListParticle.SetActive(true);
        }
    }
}```
real vapor
#

Quick question
It seems the default fill value of an imagine is 1f and trying to set it anything higher won't work, so is there a way to have it clamp to a higher value?

rare basin
#

you should consider changing it

#

to something more extensible and more friendly to work with

rare basin
#

fill image is clamped between 0 and 1

#

1 being the maximum fill amount

real vapor
rare basin
#

but 1 is the maximum

#

what you would expect to happen

#

above 1?

wintry quarry
rare basin
#

treat is kinda like visibility percentage

#

0 meaning 0% and 100 meaning 100%

#

there is no such thing as image visible at 200%

real vapor
#

I meant having it shown 100% using a value of 0-100 or anything else instead of 0 to 1.

wintry quarry
#

Just do value / max

#

Then you can do whatever you like

wintry quarry
#

E.g. percent / 100 if you want it 0-100

rare basin
#

percent / 100?

#

so for example 50%, 50/100=0.5, how it's 0-100 then?

real vapor
#

Okay got it.

deep quarry
#

Trying to make a Player movement, but I'm getting stuck on the mouse rotation.
This is my CameraMovement.cs script:

    void Update()
    {
        mouseX = sensitivity * Input.GetAxisRaw("Mouse X");

        orientation.transform.eulerAngles += new Vector3(0f, mouseX, 0f);
        transform.eulerAngles = orientation.eulerAngles;
        transform.position = orientation.position;
        Debug.Log($"{orientation.eulerAngles.y} | {mouseX}");
    }

and this is my PlayerMovement.cs script:

    void Update()
    {
        MyInput();
    }

    void FixedUpdate() 
    {
        Movement();
    }

    void MyInput()
    {
        vertical = Input.GetAxisRaw("Vertical");
        horizontal = Input.GetAxisRaw("Horizontal"); 

        moveDir = transform.forward * vertical + transform.right * horizontal;
    }

    void Movement()
    {
        rb.AddForce(moveDir.normalized * moveSpeed);
        transform.eulerAngles = orientation.eulerAngles;
    }

However, when I look around it continue rotate, even though I don't move the mouse. How do I fix this?

rare basin
#

becaues you never reset it to zero

#

when you stop looking around

#
mouseX = sensitivity * Input.GetAxisRaw("Mouse X");

orientation.transform.eulerAngles += new Vector3(0f, mouseX, 0f);
#

you have += here

#

meaning if you dont move

#

it just won't add anything

#

but there is still a value from old rotation

slender nymph
#

if there's no input then mouseX should be 0 which means that would just be adding Vector3.zero to the rotation

rare basin
#

yes but there is still old cached

#

orientation.transform.eulerAngles

#

it's never resetted

#

anytime there is input, it just adds

#

if you stop moving the mouse, it doesnt reset

#

it just doesnt add anything

slender nymph
#

why would they need to reset the current rotation back to 0

#

current rotation + 0 == current rotation

deep quarry
timber tide
#

so is that what your debug returns though

real vapor
#

Isn't this correct? Nothing happens when pressing space. I checked and using other variables from the script works.

   if (Input.GetKey(KeyCode.Space) && script.DashReady == true)
   {
       ratio = 0f;
       Debug.Log("RunBar");
   }
slender nymph
#

have you ensured this code is being called? and have you ensured that the bool you are checking is actually true?

real vapor
slender nymph
#

yes, don't use the inspector to verify the values of your variables when things are not working the way you expect. the inspector will only display the last value from the frame. so if something set it to false for a very short amount of time, it's possible you did not see it. use the debugger or print the values

real vapor
slender nymph
#

what? i don't even know where this code is being executed at so how should i know if that would fix it?

rich egret
#

The code: https://gdl.space/nazetihoda.cs

The Problem: The purpose of the script is that every time an object is added to the parentObject, it should save the name of the object in the list of prefabNames in the PlayerPrefs way, But the name is not added...

slender nymph
#

so you're still trying to fix the fundamentally flawed system that will not work at all in a build?

#

oh and what happens when an object's name gets (Clone) appended to it? you're not doing anything at all to handle that

#

but still, you should scrap this system and use one that won't bloat the registry on a user's computer and won't rely on game object names for logic

real vapor
rich egret
#

@slender nymph The truth bro, it works, I swear.

#

There was an error in the code this whole time

slender nymph
#

"it works" until you build the game because the folder you are relying on won't exist

rich egret
slender nymph
slender nymph
#

i don't even know the purpose of these, but i'd assume you probably want some event instead ๐Ÿคทโ€โ™‚๏ธ

astral basin
#

i have 4 audio sources' i want them to play one after the other ( when one ends the other one begins) and when it gets to audio 4 it goes back to 1 and replays them again kinda like autoplay on 4 audios, how do i do that

slender nymph
#

do you really need 4 separate audio sources for that?

#

depending on your unity version an AudioRandomContainer could be useful there. otherwise you could just use a coroutine, play a sound then wait until it is no longer playing then play the next one and so on like that

astral basin
slender nymph
#

you are excluding some context that would explain why you are receiving that error

astral basin
short hazel
#

Your function has the wrong return type

slender nymph
#

that's now how you set up a coroutine, don't use the generic IEnumerable

short hazel
#

It must be IEnumerator

astral basin
#

but then i get another error

astral basin
rare basin
#

also i suggest you change the function name

slender nymph
rare basin
#

isLooped suggest it's a bool return type

#

and it does a lot more

astral basin
rare basin
#

show the code

short hazel
#

And the error

astral basin
slender nymph
#

did you even read the link?

short hazel
#

Still wrong return type

#

IEnumerator and that's it, no generics

astral basin
#

one sec

quartz mural
slender nymph
# astral basin i didnt see it

also you still haven't said why you need multiple AudioSources for that instead of just a single audiosource and an array of clips

quartz mural
#

in this function the background is supposed to change

#

but for some reaosn it doesnt

#

it works for the wild pokmeon thoigh

astral basin
#

question

#

more audio sources instead of a clips array means bad performence?

#

cuz this scene takes a month to load

slender nymph
#

it's not about performance. it's just unnecessary unless you have a specific need for more than one audio source. but yes, it should reduce the time it takes for the scene to load because it will have fewer objects to load
(although 3 fewer objects won't impact it in a really noticeable way)

sage mirage
# rare basin quickly looking at that code, this is terrible architecture

Is it better?

{
    yield return new WaitForSecondsRealtime(delay);
    RoundManager.Instance.currentState = GameState.OnSettings;
    SetObjectsInactiveActive(false, false, false, false, true);

    DeactivateGameObjects(treeLogsList);
    DeactivateGameObjects(gemParticleList);
    DeactivateGameObjects(powerUpList);
    DeactivateGameObjects(playerPowerBoostListParticle);
    DeactivateGameObjects(playerPowerUpIncreaseScoreByTwoList);
    DeactivateGameObjects(playerPowerUpIncreaseScoreByTwoListParticle);
}

void DeactivateGameObjects(List<GameObject> objects)
{
    foreach (GameObject obj in objects)
    {
        if (obj != null)
        {
            obj.SetActive(false);
        }
    }
}```
astral basin
#

the error is fixed, but it was a void before so i could attach the script to a dropdown, now its a coroutine so i cant attach it in the inspector

slender nymph
#

create a method that just starts the coroutine

slender nymph
queen adder
#

i need help because my timer script is not working at all and i don't know what to do or how to fix it.
Problem: It wont count down or up.

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

public class Timer : MonoBehaviour
{
    [Header("Component")]
    public TextMeshProUGUI timerText;

    [Header("Timer Settings")]
    public float currentTime;
    public bool countDown;

    [Header("Limit Settings")]
    public bool hasLimit;
    public float timerLimit;

    [Header("Format Settings")]
    public bool hasFormat;
    public TimerFormats format;
    private Dictionary<TimerFormats, string> timeFormats = new Dictionary<TimerFormats, string>();


    // Start is called before the first frame update
    void Start()
    {
        timeFormats.Add(TimerFormats.Whole, "0");
        timeFormats.Add(TimerFormats.TenthDecimal, "0.0");
        timeFormats.Add(TimerFormats.HundrethsDecimal, "0.00");
    }

    // Update is called once per frame
    void Update()
    {
        currentTime = countDown ? currentTime -= Time.deltaTime : currentTime += Time.deltaTime;

        if (hasLimit && ((countDown && currentTime <= timerLimit) || (!countDown && currentTime >= timerLimit)));
        {
            currentTime = timerLimit;
            SetTimerText();
            timerText.color = Color.red;
            enabled = false;
        }
        SetTimerText();
    }
    private void SetTimerText()
    {
        timerText.text = hasFormat ? currentTime.ToString(timeFormats[format]) : currentTime.ToString();
    }
}

public enum TimerFormats
{
    Whole,
    TenthDecimal,
    HundrethsDecimal
}```
slender nymph
#

!code

eternal falconBOT
short hazel
quartz mural
#

it works for the wild pokemon encounters

#

but not for the trainers

slender nymph
#

and what exactly doesn't work? it doesn't set it to the one you expect, or is it not setting it to any sprite at all?

quartz mural
#

ill show u

#

so there r 2 scenes

#

grassy and cave

#

when i encounter wild pokemon in grassy

#

ill get the grassy background

#

when i do it in cave

#

ill get cave bakgrond

#

like this

slender nymph
quartz mural
#

however

#

when i do trainer battles

#

in grassy

#

i get grassy backgroudn

#

which is fine

#

but wehn i do a trainer battle in cave

#

thats wen it gies wrong

slender nymph
#

then either the you are not passing the correct enum, or the assigned sprite is wrong

quartz mural
#

i get grassy background

#

but it workd for wild pokemon

#

the background is set

#

via battle system

slender nymph
#

have you bothered inspecting the values instead of assuming everything is the way you expect?

quartz mural
#

values

slender nymph
#

yes the only two values that matter here, the enum passed to the StartTrainerBattle method and the sprite being assigned

queen adder
#

pokemon game?

quartz mural
slender nymph
#

that is not what i meant. print the value of the variables in use so you can see what they are if you do not know how to use the debugger to actually inspect them

ionic zephyr
#

why doesnt it have the tick box?

#

to enable it and disable it

slender nymph
#

because there is nothing in it that would be affected by being disabled

karmic kindle
#

Hey, I'm having trouble getting my head around how to create a new variable based upon how many elements are in my array, I'll create a thread to throw my code in ๐Ÿ––

ionic zephyr
slender nymph
#

i just told you why

ionic zephyr
slender nymph
#

there is nothing in your component that would be affected by being disabled, therefore unity does not render the checkbox to enable/disable it because that will do literally nothing at all

ionic zephyr
#

you mean parameters?

queen adder
slender nymph
#

of course, in more recent versions that has changed so the tick box is there no matter what. but nothing will happen when you enable or disable that component so why should unity render that tick box?

slender nymph
eternal falconBOT
ionic zephyr
slender nymph
#

yes, but that will still do nothing at all

ionic zephyr
#

oh, so, what should I do?

slender nymph
#

for what? nothing is wrong here unless you are expecting anything to happen when the object is disabled

queen adder
#

https://hastebin.com/share/qipasozula.java i cant find the thing that is inverting the movement cause it is such a long script and people are getting mad at me saying the idea of inverted movement is "shi"

slender nymph
#

this isn't related to the issue you are asking about, but do not multiply forces by deltaTime, nor should you multiply mouse input by deltaTime. dt is already factored into the AddForce call, you're just making your multipliers about 100 times higher than they need to be in order to compensate for that. and mouse input is already framerate independent so by multiplying by deltaTime you just end up with stuttery mouse controls

queen adder
#

so remove the lines that multiply by delta time?

#

or shorten them?

slender nymph
#

remove the deltaTime multiplications for your forces and for the mouse input

queen adder
#

ok tysm

slender nymph
#

and of course reduce the values of the other multipliers to compensate

queen adder
#

i just remembered something i have a old movement script i haven't used since 2020 and i feel like it might work.

#

nvm

karmic kindle
queen adder
#

im going to begin using unity learn since i dont know anything about unity. ima continue.

ionic zephyr
slender nymph
#

why do you need to disable it?

#

like genuinely, what purpose is that going to serve for code that is not going to be affected in any way by being disabled

ionic zephyr
#

Its has an OnCollision method

slender nymph
#

which is not affected by the component being disabled

ionic zephyr
#

I want to disable the component so that cant play

slender nymph
#

no. your code has no methods that would be affected by being disabled. that's what i've been telling you this whole time

ionic zephyr
#

ok, no need to remark that

rare basin
#

backgroundImage.sprite = battleBackgrounds[battleTrigger]

#

Dictionary<BattleTrigger, Sprite>

#

extensible and designer-friendly

#

cuz if you want to add more backgrounds with current implementation it will get messy

#

with all the if/else checks

astral basin
#

line 178 never runs, why??

wintry quarry
# astral basin line 178 never runs, why??

lots of reasons:

  • None of the code is ever running, including that line
  • the else isn't being entered
  • There's an exception before that line
  • The object running this coroutine was deactivated or destroyed before you got to that line. Coroutines don't run on deactivated or destroyed GameObjects
rare basin
#

also

#

why do you have local function @astral basin

astral basin
astral basin
#

idk

wintry quarry
#

if you have an exception you will likely see it as an error in the console

astral basin
astral basin
#

only the print(i)

#

and print(hui") which was for testing

wintry quarry
#

you sure errors are turned on in the console?

astral basin
#

yes

#

i get the unity remote error

#

at the top

#

every time i start

wintry quarry
#

then the problem will be that your object was deactivated or destroyed

wintry quarry
#

Oh one other possibility:
Time.timeScale is low or 0

wintry quarry
astral basin
wintry quarry
#

print("Time scale is " + Time.timeScale);

astral basin
#

on start?

wintry quarry
#

why do it in start?

#

Better to do it right when it's relevant

astral basin
#

alright

#

putting it in the loop

#

time scale is 1

wintry quarry
#

how long is the audio clip

#

print that too

astral basin
#

oh wait

#

before that

raw kindle
#

I want to rotate the vector (0, Y, 0) by (0,0,Z) how do I do it?

astral basin
#

clip is about 9 minutes, in the app i haev a skip forward button that sets the time to +5, could that be whats messing with it?

wintry quarry
wintry quarry
astral basin
wintry quarry
#

what's 0

astral basin
#

clip time

wintry quarry
#

print a label with the log

#

how do we know that's the clip length and not the i

astral basin
#

both of them are 0

rare basin
#

prove it

astral basin
#

ok

rare basin
#

that doesnt prove anything

astral basin
#

only 2 things printed are i and time

wintry quarry
#

that could be anything at the bottom there

astral basin
#

both are 0

#

ok

#

sec

rare basin
#

and show the code aswell

wintry quarry
#

Where and how are you running this loopDropdown function?

astral basin
rare basin
astral basin
wintry quarry
rare basin
#

it does

astral basin
wintry quarry
#

no it does not

rare basin
#

ow

#

the function, nvm

rare basin
wintry quarry
rare basin
#

you logged time property

astral basin
wintry quarry
#

wanted to know the clip length

astral basin
#

isnt that what i did

#

sec

wintry quarry
#

is it a prefab?

astral basin
#

oh

#

not a prefab

#

sec im getitng clip lengtj

wintry quarry
#

right so it's 9 minutes as you said. Are you actually waiting 9 minutes before determining that it doesn't run?

#

that's a long time to wait

astral basin
wintry quarry
#

Your coroutine doesn't know anything about that though.

#

your coroutine is waiting 9 minutes as you told it to do

astral basin
#

so how do i let it know

wintry quarry
#

a couple options

rare basin
#

calculate the time it is supposed to wait

wintry quarry
#

simplest is probably:

yield return new WaitWhile(() => songsource[i].isPlaying);```
astral basin
#

so just replace yield return new WaitForSeconds(songsource[i].clip.length); with that?

wintry quarry
#

another option is waiting in a loop and using your own timer which you can manipulate when pressing skip

astral basin
#

alrightt

astral basin
raw kindle
wintry quarry
astral basin
wintry quarry
#

explain in words

#

not in terms of angles and numbers

raw kindle
wintry quarry
#

the poisition x distance away would be transform.position + transform.up * distance;

#

you don't need to fuck with any angles

raw kindle
#

ok thanks

wintry quarry
#

you can also do transform.TransformPoint(new Vector3(0, distance, 0)) although that will also respect scale

meager steeple
#
 if (SpriteRenderer.flipX == true)
 {
     RB.velocity = new Vector2 ( -KBForce * NewCharacterMovement.speed , KBForce );
 }
 else
 {
     RB.velocity = new Vector2 ( KBForce * NewCharacterMovement.speed , KBForce );
 }```
for some reason this script is not adding a velocity in the x direction
astral basin
#

thank you for the help

wintry quarry
meager steeple
wintry quarry
#

how about:

  • Is this code actually running?
  • what are the values of these numbers? -KBForce * NewCharacterMovement.speed
#

you know just the basic facts of the situation

ionic zephyr
#

why is there a layer in which all objects are invisible

meager steeple
#

kbforce works because it adds a velocity in the y direction, and newcharactermovement.speed is referencing a non 0 float from another script

wintry quarry
#

Debug.Log is your next step

#

you need to question your assumptions at every step

meager steeple
#

Debug.Log(RB.velocity);

#

its apparently logging a horizontal velocity but its just not applied

wintry quarry
#

it's with some other code

#

probably some other code is overwriting this

#

this is why we use Debug.Log

#

we have now ruled this code out as the problem and we are free to look elsewhere

meager steeple
#

yeah i think its because the velocity is set equal somewhere else in a fixed update function, but i dont understand how it would work for the y direction but not the x direction

wintry quarry
#

probably because it's not changing the y in that other code

meager steeple
#

yes ok i got it

#

this will be a pain

#

argh

astral basin
#

if the script is in the middle of running a for loop and then i tell it to run a diferent for loop will they both run at the same time or will the first for loop finish first

wintry quarry
#

What does this even mean?

#

Show the code?

#

code runs top to bottom, in order

#

and only one line of code is running at a time

#

barring multithreading which you would be very aware of if you were doing it.

astral basin
#

wait that doesnt matter anymore 3 more problems just came up that wil probably fix what i tried to fix when i fix them

wintry quarry
#

sure but from academic curiosity I'm curious about waht you mean, and we may clear up some misconceptions you have about how code runs.

#

up to you

astral basin
#

i assumed it waits but it doesnt

#

but it also doesnt does

#

nevermind

#

im overcomplicating

wintry quarry
#

because under normal circumstances "pressing a button" is not something that can be done or detected in the middle of a loop

modest sluice
#

i have this class ```cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace GK
{
public class LSystemBranch : MonoBehaviour
{
public Transform plantPrefab;
public float minSegmentLength = 0.5f;
public float maxSegmentLength = 2f;
public float Length;
public List<Vector3> previousEndPoints = new List<Vector3>();
public List<Vector3> firstStartPoints = new List<Vector3>();
private int plantSegmentNumber;
public int totalNumberOfPlantSegments = 15;
public int numSides;
public Vector3 offsetrotation = new Vector3();

    void Start()
    {
        createBranch();
    }```

how do i create a LSystem branch object in another class and set some of the public variables before it runs?

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

namespace GK
{
    //add a branch
    public class Branch1 = LSystemBranch();
} ```
astral basin
#

forget about the issue

#

if u tell a script to do one thing and at the same time another while its busy

wintry quarry
astral basin
#

okay one sec

wintry quarry
#

basically while the loop is running nothing else can happen, UNLESS we're talking about coroutines

astral basin
#

something like this

#

while btn() is running u call btn2()

#

if a script only renders one line at a time

#

does it just jump andcome back

#

cuz it cant leave a for loop

#

oh the waitforseconds is supposed to be in a for loop***********

wintry quarry
# astral basin

The way WaitForSeconds works is every frame Unity checks to see if the time has passed. If it has, it continues running that code. If not, it comes back again next frame

#

eithe way the code is not running at the same time

#

it will be something like:

Frame Start
Unity checks the coroutines. If time elapsed, the coroutine runs fully until the next yield
Update runs on your scripts and the event system and potentially you run btn2()
Frame End
Next Frame```
#

there's no magic

astral basin
#

i dont undestand anthing u just wrote

wintry quarry
#

What part are you confused about

ivory bobcat
wintry quarry
#

Unity like most game engines runs on a frame by frame basis

astral basin
#

what happens practically

#

u press btn 2

#

it prints right away

wintry quarry
#

most likely in your script's Update function

astral basin
wintry quarry
#

no

#

if there's a yield in the middle of the loop, the loop can be paused

#

yield pauses the code and lets the rest of the engine run

astral basin
#

ohh

wintry quarry
#

that's all that yield does

astral basin
#

so waitforsecondslets the line reader to read all the other lines in the code

#

without making it stuck

wintry quarry
#

if there's no yield, then the entire game engine is frozen until your code is done running

#

this is true for all code you write anywhere in Unity

#

(excepting multithreading but that's another subject)

astral basin
#

but it proccesse the code so fast u dont notice right

karmic kindle
# astral basin i dont undestand anthing u just wrote

I could be wrong, so apologies if I am, but, ignore the code you have written for a minute.

Logically, Unity will read your script from top to bottom - but, since you have set up Coroutines, it will run them AS WELL as the "Update" section of your code, so "Update" will always run, but you can control Coroutines with delays so they might not always run on every frame.

wintry quarry
#

unless you screw up and write an infinite loop or other code that takes a very long time

#

then your game freezes or your framerate suffers

south sky
#

Yo guys, I have code that moves and instantiated object however when the object spawns on start, the code doesnt run. Anyone know what went wrong?

astral basin
#

ok i think i get it

wintry quarry
south sky
#

Cool hold on

#

Yooo nvm

wintry quarry
#

What script is this? What code isn't running?

south sky
#

I realised the problem

#

Its cool bro dw

errant wedge
#

is the tool bar suppose to be in the top left of the editor? Is there a way to reposition into the top left corner of scene view?

boreal dagger
#

Hi I just joined

#

I want to learn how to code in C#

#

Does anyone know any places I can learn?

astral basin
#

I have an autoplay system on my unity project that is selected by using a dropdown. if i set it to autoplay before i pressed the start playing music button, it enables all of the songs at once and when i press play it starts them all, however when i first press the play button and then press auto play it works just fine, i assume its becuase the auto play works by waiting for the song before to end before starting another one but none are playing since i havent started yet. i hope you get what i mean, i just havent been able to pinpoint the problem and find a solution https://codeshare.io/xLeb8R

errant wedge
burnt rampart
wintry quarry
errant wedge
wintry quarry
#

I can't even get the scene overlays out of the scene window IDK how you managed it lol

uncut shoal
#

How do I make the variables for 'ranged weapon' disappear if 'is ranged' is disabled?

wintry quarry
#

Or use an off the shelf one like NaughtyAttributes

errant wedge
#

I think I know what it is

errant wedge
#

what version is current for unity?

uncut shoal
#

I already have NaughtyAttributes

burnt rampart
#

so I'm looking through an open-source GuitarHero clone project and I see they have a bunch of classes defined in their "Player" script, and I'm curious why?

wintry quarry
uncut shoal
#

so like, [ShowIf("isRanged", true)]?

wintry quarry
#

just [ShowIf("isRanged")]

wintry quarry
burnt rampart
wintry quarry
#

YOu can serialize them separately

#

you can copy them around

#

etc

south sky
#

Yo guys, I want an object in my game to recognise the player and always knows it transform.position but I cant make a game object variable as the object will be instantiated so using prefabs wont work, is there anyway to do this?

wintry quarry
burnt rampart
errant wedge
#

@wintry quarry I think I was on an older verison of unity thanks for the help

wintry quarry
willow scroll
wintry quarry
uncut shoal
wintry quarry
uncut shoal
wintry quarry
#

did you save the code

uncut shoal
#

yes

wintry quarry
#

Do you have a custom editor for this script

uncut shoal
#

btw this is inside a class that doesn't inherit from monobehaviour, but I think this doesn't change anything because I was able to use attributes from naughtyattributes and unity before in class

wintry quarry