#💻┃code-beginner

1 messages · Page 423 of 1

timber comet
#

because i need the y velocity to become a vector3, cause i cannot just put a float alone there (it's a Vector3 multiplication, plus adding)

short hazel
#

Yep so .NET 5 is an entirely different branch. Unity uses .NET Framework 4.8, which is close in terms of features but has less. Most of the things introduced in modern .NET are syntax shortcuts, so you probably won't hit many errors anyway

worthy tundra
flint abyss
timber comet
#

let me test it

worthy tundra
timber comet
worthy tundra
timber comet
worthy tundra
#

been a while since i wrote a movement code

short hazel
slender nymph
timber comet
#

Like this: Vector2 _LocalMovement = transform.TransformDirection(_movementKeys);?

worthy tundra
slender nymph
worthy tundra
waxen adder
timber comet
short hazel
timber comet
worthy tundra
tepid summit
#

wdym

worthy tundra
slender nymph
short hazel
timber comet
#

thanks it worked

worthy tundra
worthy tundra
burnt vapor
#

If there is some sort of timed system that must happen then maybe Coroutines are not the best idea. Instead you might want to stick to Update and track timestamps

#

This works but it can be messy

burnt vapor
#

When they take damage, set a timestamp for (for example) Timer.time + 5.0 to start healing 5 seconds into the future

#

You can have a long running Coroutine that checks every frame if the time passed, and if so it stops checking and starts healing every x seconds until the timestamp is in the future again

#

It's a lot easier than hassling with starting and ending Coroutines

worthy tundra
#

thanks but i think im gonna stick with what ive done

burnt vapor
#

Suit yourself

tepid summit
#

about my error earlier

flint abyss
#

Does anybody know a good tutorial to start scripting with unity 2d?

eternal falconBOT
#

:teacher: Unity Learn ↗

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

flint abyss
# wintry quarry !learn

I've already look into it, i want a video or a spreadsheet, not a course. on the site i also saw direct tasks that i didnt understand

slender nymph
#

if you're gonna be picky about the learning resources suggested, then you'll need to search for them yourself

flint abyss
slender nymph
worthy tundra
slender nymph
opaque moss
#
Your script should either check if it is null or you should not destroy the object.
UnityEngine.Object+MarshalledUnityObject.TryThrowEditorNullExceptionObject (UnityEngine.Object unityObj, System.String parameterName) (at <454b8adca03e44db8a0e3ace7093e9b8>:0)
UnityEngine.Bindings.ThrowHelper.ThrowNullReferenceException (System.Object obj) (at <454b8adca03e44db8a0e3ace7093e9b8>:0)
UnityEngine.Transform.get_position () (at <454b8adca03e44db8a0e3ace7093e9b8>:0)
CameraManager.Update () (at Assets/Scripts/CameraManager.cs:19)``` I had this error
slender nymph
#

what is line 19 of CameraManager.cs

burnt vapor
eternal falconBOT
burnt vapor
#

Your code was last called there before Unity threw the exception according to your stacktrace

opaque moss
#

I had this

burnt vapor
opaque moss
#

wait

#
using System.Collections.Generic;
using UnityEngine;

public class CameraManager : MonoBehaviour
{
   public Transform target;
   public float cameraSpeed;
   
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
       transform.position = Vector3.Slerp(transform.position, new Vector3(target.position.x, target.position.y, transform.position.z), cameraSpeed); 
    }
}
slender nymph
#

target has been destroyed but you are still trying to use it

opaque moss
#

how can I fix that

#

Transfor has been destroyed as well but idk actually how to solve those kinda things

slender nymph
#

check if the object has been destroyed or don't destroy it

slender nymph
#

the only object on that line that could have possibly been destroyed is target

opaque moss
#
{
    if (target != null)
    {
        transform.position = Vector3.Slerp(transform.position, new Vector3(target.position.x, target.position.y, transform.position.z), cameraSpeed);
    }
    else
    {
        Debug.LogWarning("Target nesnesi atanmadı veya yok edildi!");
    }
}``` ```void OnGroundCheck()
{
    if (groundCheckPosition != null)
    {
        isGrounded = Physics2D.OverlapCircle(groundCheckPosition.position, groundCheckRadius, groundCheckLayer);
        playerAnimator.SetBool("isGroundedAnim", isGrounded);
    }
    else
    {
        Debug.LogWarning("GroundCheckPosition nesnesi atanmadı veya yok edildi!");
    }
}
#

I implemented those code lines but when the game started, my player was not in the scene

verbal dome
#

I mean, did it print the warning in Update

opaque moss
#

yes

verbal dome
opaque moss
verbal dome
#

Well, how is your player placed in the scene?

slender nymph
#

doesn't look related to the code you've shared at all

verbal dome
#

Yep, separate issue

opaque moss
slender nymph
#

also don't crosspost. your issue regarding the destroyed object was already solved before you posted it to the other channel

opaque moss
verbal dome
#

Do you have code that spawns the player or where does it come from

#

You havent show any relevant info about the player disappearing problem

opaque moss
#

I'll send all of the scripts

#
using System.Collections.Generic;
using UnityEngine;

public class DestroyME : MonoBehaviour
{
    public int lifeTime;
    // Start is called before the first frame update
    void Start()
    {
        Destroy(gameObject, lifeTime);
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;


public class PlayerManager : MonoBehaviour
{
    public float health;
    public float bulletSpeed;
    bool dead = false;    
    Transform muzzle;
    public Transform bullet;
    public Transform floatingText; 
    public Slider slider;

    bool mouseIsNotOverUI;
    
    // Start is called before the first frame update
    void Start()
    {
        muzzle =  transform.GetChild(1);       
        slider.maxValue = health;
        slider.value = health;
    }

    // Update is called once per frame
    void Update()
    {
        mouseIsNotOverUI = EventSystem.current.currentSelectedGameObject == null;

        if(Input.GetMouseButtonDown(0) && mouseIsNotOverUI)
        {
            ShootBullet();
        }
    }
    public void GetDamage(float damage)
    {
        Instantiate(floatingText, transform.position, Quaternion.identity).GetComponent<TextMesh>().text = damage.ToString();

        if(health - damage >= 0) 
        {
            health-=damage;
        }
        else
        {
            health=0;
        }
        slider.value = health;
        AmIDead();
    }
    void AmIDead()
    {
        if(health<=0)
        {
            dead = true;
        }
    }

    void ShootBullet()
    {
        Transform tempBullet;
        tempBullet = Instantiate(bullet, muzzle.position, Quaternion.identity);
        tempBullet.GetComponent<Rigidbody2D>().AddForce(muzzle.forward * bulletSpeed);
        DataManager.Instance.ShotBullet++;
    }
}```
crude sphinx
#

Yeah left shift

cobalt atlas
#

Is there a way I could save a int within the game folder itself? I’ve noticed the most common save places are either in the Registry or appdata but can you do the root folder of the game by chance? I’m trying to save a int

verbal dome
eternal falconBOT
languid spire
spare basalt
#

hi everyone,can u help me pls?```public void exp1(string Path)
{
Path2 = "Application.persistentDataPath" + Path;

    DirectoryInfo di = new DirectoryInfo("Application.persistentDataPath" + Path); // Not working, only if Path= "" working
    DirectoryInfo di = new DirectoryInfo(Path2); // Not working
    DirectoryInfo di = new DirectoryInfo(System.IO.Path.Combine(Application.persistentDataPath, Path)); // Not working, only if Path= "" working
    DirectoryInfo di = new DirectoryInfo("Application.persistentDataPath" + "/directoryname"); // Working but i dont need this type
}```
#

how cani fix that?

#

string Path2 i know

languid spire
#

why are you passing Application.persistentDataPath as a string?

spare basalt
#

what should i do?

languid spire
#

take the quotes off

#

And, use Path.Combine to build path strings

spare basalt
#

DirectoryInfo(System.IO.Path.Combine(Application.persistentDataPath, Path));

#

i used

languid spire
#

does Path start with a / ?

spare basalt
#

yes

languid spire
#

remove it

spare basalt
#

ok i will try

#

ty

languid spire
#

Also, reading the docs might be a good idea

thick dune
#
    [SerializeField] private Button otherBtt;
    [SerializeField] private Button backBtt;
    
    [SerializeField] private RectTransform sound;
    [SerializeField] private RectTransform other;
    
    [SerializeField] private GameObject soundPanel;
    [SerializeField] private GameObject otherPanel;

    [SerializeField] private AudioSource audioSource;
    [SerializeField] private AudioClip button;
    private void OnEnable()
    {
        soundBtt.onClick.AddListener(Sound);
        otherBtt.onClick.AddListener(Other);
        backBtt.onClick.AddListener(Back);
    }

    private void OnDisable()
    {
        soundBtt.onClick.RemoveListener(Sound);
        otherBtt.onClick.RemoveListener(Other);
        backBtt.onClick.RemoveListener(Back);
    }

    void Sound()
    {
        sound.sizeDelta = new Vector2(700, 100);
        other.sizeDelta = new Vector2(400, 100);
        audioSource.PlayOneShot(button);
        otherPanel.SetActive(false);
        soundPanel.SetActive(true);
    }

    void Other()
    {
        sound.sizeDelta = new Vector2(400, 100);
        other.sizeDelta = new Vector2(700, 100);
        audioSource.PlayOneShot(button);
        otherPanel.SetActive(true);
        soundPanel.SetActive(false);
    }

    void Back()
    {
        audioSource.PlayOneShot(button);
        Screens.index = 1;
    } ```
the audiosource.playoneshot  is not working when I am calling it in normal voids but when I am calling it in Ienumerator it is working pretty fine....

Anybody knows the reason?
atomic holly
#

Hello,
In one of my function, I create buttons from a buttonprefab like this :

for (int i = 0; i < weaponsInShop.Length; i++)
{
    GameObject button = Instantiate(buttonWeaponToSellPrefab, buttonWeaponToSellParent);
    ItemWeaponButton buttonScript = button.GetComponent<ItemWeaponButton>();
    buttonScript.WeaponImage.sprite = weaponsInShop[i].itemImage;
    buttonScript.WeaponItem = weaponsInShop[i];
}

My ItemWeaponButton script is this :

public class ItemWeaponButton : MonoBehaviour
{
    public Image WeaponImage;
    public Weapon WeaponItem;
}

When I call my function, Unity send me this error : NullReferenceException: Object reference not set to an instance of an object
Why ?

strong wren
atomic holly
#

It can be from script or Unity ?

strong wren
#

There should be a stacktrace in the bottom section of console

atomic holly
# strong wren It should give you more information than you have provided.

It's the all error : NullReferenceException: Object reference not set to an instance of an object ShopWeaponManager.CreateWeaponsToSell (Weapon[] weapons) (at Assets/Code/Scripts/NPC/Shop/ShopWeaponManager.cs:57) ShopWeaponManager.OpenWeaponShop (Weapon[] weapons, System.String pnjName) (at Assets/Code/Scripts/NPC/Shop/ShopWeaponManager.cs:39) ShopWeaponTrigger.Update () (at Assets/Code/Scripts/NPC/Shop/ShopWeaponTrigger.cs:16)

strong wren
#

What's line 57 in ShopWeaponManager?

atomic holly
strong wren
#

Something on that line is null. You can attach a debugger to inspect each value as the code executes

atomic holly
#

Okay I found, I forgot to give the reference of the Image of the button :/

#

Thanks to you !

verbal dome
#

And make sure that you don't disable the object that has the AudioSource. That would stop the sound

manic void
#

i'm making an inventory system for a 3d unity project. right now i'm trying to add a drag and drop system to the items but it doesn't work.. I only have debug.logs right now and nothing shows up in the console

DragDrop - https://hst.sh/cufazifuva.cpp
ItemSlot - https://hst.sh/movubemodo.csharp

i've read forums talking about adding a StandaloneInputModule to the event system but because im using new InputSystem i need to use a InputSystemUIInputModule. I've added a canvas group to the item, made sure the canvas has a GraphicRaycaster. I also did an Event System debugger - https://hst.sh/musobofono.cpp and still nothing shows up in console. when i click on the item absolutely nothing happens

rigid ridge
#

Hello im still new to this and everytime i try to make movement it says "ArgumentException: Input Axis horizontal is not setup."

verbal dome
rigid ridge
verbal dome
#

You typed it wrong, it needs to be Horizontal.

rigid ridge
#

Oh alright thanks

stray thorn
#

does anyone know how i can make the orange object stay on top of the disc when it moves?

#

cuz its just staying in place when i move away

ivory bobcat
#

Child the object or use some kind of constraint

split dragon
#

Good night (I personally have a night). I have a question: what function or method is needed to select a color in c\hannel mixer? I tried to write it (no errors came out, but it didn't work). How to do it?

rare rivet
stray thorn
atomic holly
#

Hi,
I put my code on a github and put at the origin. But I don't see there is a conflict in my scene in Unity. So now, I have nothing in my scene and git say the error is here in my Scene.unity :

SceneRoots:
  m_ObjectHideFlags: 0
  m_Roots:
  - {fileID: 20009624128464991}
  - {fileID: 747104955}
  - {fileID: 5263420119110903920}
  - {fileID: 122769077}
  - {fileID: 629391847}
  - {fileID: 298221142}
  - {fileID: 985254350}
  - {fileID: 1664262106}
  - {fileID: 1859801690}
<<<<<<< Updated upstream
=======
  - {fileID: 1429456250}
  - {fileID: 2037507436}
>>>>>>> Stashed changes

What I need to do and how can I know what I need to change

rich adder
#

figure out what you want to do with the new changes (modify the .scene file )

eager spindle
#

git errors look like ```<<<<<<< Updated upstream

  • {fileID: 1429456250}
  • {fileID: 2037507436}

Stashed changes

atomic holly
#

I have the same error

atomic holly
rich adder
atomic holly
#

Show it where are conflits really ?

eternal needle
#

Those lines are just to indicate where the conflicts are

atomic holly
shell herald
#

im currently building a shop ui and i have buttons that only become interactable if the requirement (money ) is met. however now i have the problem that it is only local to each button, meaning, should the player have 3 items in his shop for 300 cash, and he has 310 in his inventory, he can still buy all 3 because they only check once.
anyone knows how i can "fix" that?

Button script https://pastebin.com/crgwk9qQ

eternal needle
desert temple
#

So. trying to do something here.

  • Creating a boolean value that'll flip between true/false depending on whether or not a certain, already integrated count is met. This will then trigger a win screen when the player hits a simple spot.
    Should I share what I have so far here?
eternal needle
desert temple
#

Oh, hmm. That didn't work how I imagined.

rich adder
eternal falconBOT
shell herald
eternal needle
crude sphinx
#

Idk if this is the same everywhere, but this is not how you spell reduce

stiff abyss
#

errors doesent come with wrong spelling

#

i dont used images

#

i used hatebin

#

my code is too long to send without nitro

summer shard
#

is spotAngle just outerSpotAngle?

        flashlightLight.innerSpotAngle = curMode.innerAngle;
        flashlightLight.spotAngle = curMode.outerAngle;
steep rose
#

seems like it

#

whats the problem with hatebin

stiff abyss
#

even bot says to use it

steep rose
#

and the mods

#

why is that a problem

#

ok 😂

summer stump
#

That is against what the mods want here. If it is longer than a few lines, it needs to go in a paste site.
Doesn't matter what you find annoying

worthy vault
steep rose
#

yo

worthy vault
#

i have question

steep rose
#

yup

worthy vault
summer stump
steep rose
#

speak up

worthy vault
#

im new in unity .
whete can i learn unity

i don't need unity website . becuese unity website don't have video

pls give me some video for i learn . and its good for beginner

steep rose
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

steep rose
#

well there are tons of yt videos for this kind of stuff, what would you like to make? if you dont want unity tutorials.

desert temple
steep rose
#

fps, third person shooter, etc

worthy vault
steep rose
#

first person shooter

worthy vault
eager spindle
#

theres brackeys, though the tutorials are now a little old

worthy vault
steep rose
#

search a genre of game you would like to make on youtube and find a tutorial

rich adder
steep rose
eternal falconBOT
steep rose
#

use hatebin

worthy vault
steep rose
#

or any of these sites

#

i make thirdperson/firstperson shooters

eager spindle
# worthy vault you say to me ?

ill be real its better to learn with a goal in mind, just learning unity for the sake of it will be slower than wanting to make a game that you like and researching on each aspect for it

worthy vault
eager spindle
#

so what would you like to do in unity, what game would you like to make?

steep rose
#

we need to know what you would like to make first

worthy vault
#

i ask person of unity member

#

where they learned

#

i use them

eager spindle
eternal falconBOT
#

:teacher: Unity Learn ↗

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

steep rose
#

well we need to know what genre you would like

eager spindle
worthy vault
eager spindle
#

yea

worthy vault
steep rose
#

i can give you a list of fps tutorials but it may not be what you like to make

worthy vault
worthy vault
#

thank you

#

if you can help me help thanks guys

eager spindle
#

c#

#

java

#

anything

steep rose
#

im just gonna give a rigidbody tutorial with movement, its very easy for beginners unlike character controller

eager spindle
#

i need to hurry up on my 300 slide C#, Raylib and Unity tutorial for beginners

steep rose
# worthy vault if you can help me help thanks guys

personally i would recomend either brackeys, or dave development, i followed these tutorials when i was starting
https://www.youtube.com/watch?v=f473C43s8nE&t=1s&ab_channel=Dave%2FGameDevelopment

FIRST PERSON MOVEMENT in 10 MINUTES - Unity Tutorial

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

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

▶ Play video
#
worthy vault
#

thanks for helping @steep rose @eager spindle

steep rose
#

👍

worthy vault
desert temple
eager spindle
#

you said you wanted something to trigger when the count is met

desert temple
#

There's collectibles you gather in the level.

eager spindle
#

oh I see it

#

do you already have a function for what you want to do when the count is met?

worthy vault
worthy vault
eager spindle
#

OnTriggerEnter increases your count

desert temple
eager spindle
#

before we continue do you understand where SetCountText is called from

desert temple
#

Uh, inside Start(), and OnTriggerEnter()?

eager spindle
#

im helping someone else

#

go learn c# first

eager spindle
worthy vault
eager spindle
#

also what's the problem here actually

eager spindle
#

as a programmer you need to be able to research on how to do stuff yourself

eager spindle
desert temple
eager spindle
desert temple
#

The winscreen displays, I'm just trying to change that from triggering from collecting all the points

#

To

#

Collect the collectibles
When player has moved back to the start, trigger the win message.
This is my actual assignment, with the winscreen being the feedback to the player.

worthy vault
# eager spindle already did

Learn to develop games using the Unity game engine in this complete course for beginners. This course will get you up and running with Unity. Free game assets included!

✏️ Course developed by Fahir from Awesome Tuts. Check out his channel: https://www.youtube.com/channel/UC5c-DuzPdH9iaWYdI0v0uzw

⭐️ Resources ⭐️
(To download assets you may have...

▶ Play video
desert temple
#

I've got the collection part done. I'm trying to handle the rest.

worthy vault
worthy vault
eager spindle
desert temple
#

Yes. There'll be collectibles spread throughout a maze, the player touches them, gets their score up to eight, and then they have to return back to get their winscreen.

steep rose
#

wait what is the problem again?

#

im late

worthy vault
#

me ?

steep rose
#

nope

eager spindle
steep rose
#

why doesnt he just check if he has 8 points and is in the trigger

eager spindle
steep rose
#

what was that

desert temple
#

Okay. So...make like a block or plane, that has isTrigger. But shouldn't it be in void update(), not void start()?

eager spindle
#

erm

#

youre adding another trigger, that's in ontriggerenter

desert temple
#

Oh. So it should like...

void SetCountText()
    {
        countText.text = "Count:" + count.ToString();
    }
    
    // This is where the pickup stuff goes.
    private void OnTriggerEnter(Collider other)
    {
        if(other.gameObject.CompareTag("Pickup"))
        {
            other.gameObject.SetActive(false);
            count = count + 1;

            SetCountText();
        }
        elif(count >= 8 && other.gameObject.CompareTag("GameFinish"))
        {
             winTextObject.SetActive(true);
        }
    }

No idea if I have the right idea here.

obsidian shoal
#

(this is just a test) why is it printing as soon as i start and space does nothing

#

yes its in update

polar acorn
#

See the green underline at the end?

languid spire
obsidian shoal
#

oh its gotta be at the }

eager spindle
#

what is print actually

#

also if statements dont need ;

polar acorn
obsidian shoal
#

ok i fixed it kinda but why is it just doing it one time

eager spindle
polar acorn
obsidian shoal
obsidian shoal
eager spindle
#

so when you press space key, it prints one time and never again?

polar acorn
obsidian shoal
#

yes and yes

eager spindle
#

it could be that this is on

#

Collapse

polar acorn
obsidian shoal
#

works

#

thanks

eager spindle
#

you can turn collapse off if you want, but having collapse on shows the number of times gets printed

#

yuh

obsidian shoal
#

how long of unity learn till yall think im ready for my own project?

steep rose
#

you can start now

#

if you want

steep rose
#

you will learn on the way, trust me

eternal needle
# obsidian shoal how long of unity learn till yall think im ready for my own project?

Without knowing exactly what your end goal is, no one can really answer this. And it's unlikely you know exactly what features you want rn.
If you arent familiar with c# basics, then this will take a lot longer if you just try to start making stuff on your own for many reasons. Things will break, you'll have to learn how to debug. As you get better you'll remake systems that no longer fit your needs

steep rose
#

or this 👆

eternal needle
# steep rose i did and i still asked for help

You should be a bit more careful offering advice like this, if you dont have that much experience. From what I've seen you seem like a beginner too.
It isnt about asking for help, if someone tries to start a major project too early they're likely just gonna waste a shitton of time

#

I have years of coding experience, yet still abandoned my first project I worked on for months because it was too much/too bad

desert temple
#

@eager spindle think I managed it with what I posted?

obsidian shoal
#

i was wanting to do a fps but thats way out of my league

#

i think im going to wait till i know sound and anims

rich adder
obsidian shoal
#

ig i should have said instantiate instead of prefabs

rich adder
#

still not a c# thing lol

obsidian shoal
rich adder
#

don't confuse Unity API for anything else but that

obsidian shoal
#

anyways i know enough c# to make something move

rich adder
#

C# is the language they chose to interact with their engine

rich adder
#

c# basics is thrown around very loosely, just pointing out the unity api / and the native c# knowledge is diff

obsidian shoal
#

tysm for your help

mint remnant
#

Up for a challenge @obsidian shoal , try to replicate John Conway's game of life in unity. Fairly simple, but will cause you to think about design and logical flow

obsidian shoal
mint remnant
#

well start by googling what it even is, hte wiki spells it out pretty simplistically

rich adder
#

depends what you're doing, a simple game projects work well

#

logic heavy games can be simple things battleship, connect 4, tic tac toe

#

they are simple but complex enough for logic practice

eternal needle
#

I do find it crazy people jump into game dev without knowing what a for loop is

rich adder
#

took me a good month to even remember how to write one without IDE

lost hamlet
#

Lmao

rich adder
#

that was like 4 years ago

#

anything is possible 😉

languid spire
lost hamlet
#

Depends

lost hamlet
#

On what you consider a normal app

supple garden
#

Does anyone know any tutorial where weapon is separately attached to character and have to sync both animations together to make it look like one? It also has to use transform property whatsoever.

rich adder
#

mainly because there are many different maths involved

#

unlike traditional software

lost hamlet
#

You can make some simple games using regular app development tools

rich adder
#

i still find Trig scary af

lost hamlet
#

Heck, i made tic tac toe with Svelte

#

Which is for WebApps/websites

rich adder
#

yeah that was my first react project, but once i found webfront end/backend with c# i ditched js
(yay web assembly!)

lost hamlet
#

I wish i could but I'm addicted to svelte

languid spire
rich adder
#

old school

lost hamlet
#

Funnily enough my first game was tic tac toe in python. Made on my phone. During a break when i was in an internship back in high school

rich adder
#

lucky. I got into development so late 😦

#

also we're steering into offtopic

lost hamlet
#

I've got people on my (GitHub) team that have been modding/programming since 12

#

I wish i did that too

#

But hey better late than never

#

Crazy how much i love programming

#

When working on my own stuff it's equivalent or more entertaining than gaming

rich adder
#

I used to use game maker , thought I'd never be programming, was too diffuclt lol
to be fair GML looks pythony, years later I'm in unity doing c# 😛

eternal needle
rich adder
#

anyone else puts a Gameobject property in the interface or there a better way to ever get the gameobject ? 🤔

public interface IDamageable
{
    GameObject Object { get; }
    void Damage(float amount);
}```
#

in the implemented class i do public GameObject Object => gameObject;

languid spire
#

what would be the point?

rich adder
#

If i ever need to GetComponent on a Interface

languid spire
#

but you can just use Component or MonoBehaviour

eternal needle
supple garden
rich adder
rich adder
ripe shard
eternal needle
ripe shard
rich adder
eternal needle
rich adder
steep rose
#

whats happening

rich adder
eternal needle
#

If you dont end up using it, it's an easy refactor. If you end up needing to add it, it's somewhat a pain when many things already deal damage

trail harbor
#

Quick question, which way are you guys doing melee damage detection? Just a basic raycast from player body to target or from the weapon itself or weapon collision detection?

rich adder
#

felt akward just having interaface with just 1 Damage method inside lol

rich adder
#

or an overlap sometimes

#

depending on the type of melee ( i find raycasts too thin)

eternal needle
trail harbor
rich adder
rich adder
trail harbor
#

Yes I said it wrong, boxcast was hitting everything the rounded shape seems better

eternal needle
# rich adder tru I might be overcomplicating it here lol

Also no need to remove it for something simpler if it works. Like in my game I only have a characters that can be damaged. For awhile I thought to myself "what if I wanna shoot a chair and it breaks" then I realized I wont even have chairs, and it doesnt even fit in my theme. Worst case I can also just make the chair a character. If league of legends can make walls out of a shitton of minions I can make a chair a character

trail harbor
#

ty for answer

rich adder
eternal needle
#

Many other things are too

ripe shard
# rich adder yeah ima keep it for this one, I already have 3 obstacle types would be a huge i...

One thing I’ve found useful in smaller projects (<100k LOC) is to aim for having as few types as possible, ie only for the necessary categories with minimal state. In case of damage I’d aim for modeling all damage types with one data struct, immutable serialized config on the component and a ‚type‘-field (an enum for example) that lets you switch between the different specific behaviors for the various entities that implement the general concept. This helps a lot with noticing gameplay modeling that’s overly complicated, because it encourages you to look for the unifying principles behind your gameplay. As a side effect it makes persistent state easier to implement and maintain across future changes. You’d implement most of this system in one class and split classes more along concerns like input/presentation/logic/etc. than entity-damage subtype.

sharp hornet
#

Hey so I tried to get a personal free license and it didn't appear on my licenses page

#

What should I do

young lava
#

Hi! So pretty much I've been working on optimizing my game recently. I've been trying to minimize my use of expensive operations such as .Find(""). But I was wondering, how much is an acceptable level of using .Find()? I know an exact number would be hard to do, but I've run into scenarios where I think it would be fine to leave it as it is (as I am not running into performance issues for now). An example would be the visual effects for an attack I have, I need to spawn in five visual objects and access a child transform of each of those visual effects. Would it be fine to use .Find when spawning in these visual effects to get the transforms that I require?

sharp hornet
#

Soz

eternal needle
ripe shard
# young lava Hi! So pretty much I've been working on optimizing my game recently. I've been t...

It’s acceptable during setup of a scene but it depends a lot on what you are doing. Typically you don’t ever need it but it’s a boon for keeping your editor workflow alive. Aim to use it very sparingly and only if you can explain exactly why the other approach (which always exists) is not desirable. As a beginner I’d advise you try to avoid it completely, because avoiding it teaches you a lot about how unity actually works.

young lava
#

Ahhh I see I see. Alright thank you! ^^

queen adder
strong wren
obsidian shoal
#

why is this not working?

#

to make a random number

#

for the x cord

raw token
#

That Random call will only occur once, when an instance of the class is constructed.

So it should work, and give you a random float for each component - but it will be same float forever after, since you never update it

rich adder
#

btw -10,10 will give you an int not a float, add f suffix if you want to return a float and make max inclusive

#

so max will be 9

obsidian shoal
#

what the heck?!?!

rich adder
#

jesus

#

no

#

you do not put Access modifiers inside methods

#

anyway, if its just that 1 float put the Random.Range directly in the new Vector3, no need for a float var unless you want readability ig

deep fog
#

are the how to make a video game and the how to make a 2d game tutorial series of brackeys still viable (not outdated)? I have no prior experience with coding/game development

rich adder
rich adder
deep fog
rich adder
#

if you only add 10 and not 10f unity reads it as Int which gives you a max of 9 instead of 10

rich adder
#

integers and max exclusive

obsidian shoal
rich adder
#

yes the Unity learn ones are good

#

they have 2D ones too afaik

deep fog
#

Thanks! I'll take a look!

rich adder
#

start with pathways then go from there

rich adder
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

obsidian shoal
#

ohh

#

thanks

flint ruin
#

!code

eternal falconBOT
obsidian shoal
#

also i work 3d

raw token
lunar crater
#

about challenges can someone give me game ideas or a challenge as well

#

or does anyone know how to use mlagents with cloud computing

desert temple
#

I've got most of this code working, but I'm trying to figure out how to get the text that says "You Win" to show up, since I think there's something wrong in the script itself.

    void SetCountText()
    {
        countText.text = "Count:" + count.ToString();
    }
    
    // This is where the pickup stuff goes.
    private void OnTriggerEnter(Collider other)
    {
        if(other.gameObject.CompareTag("Pickup"))
        {
            other.gameObject.SetActive(false);
            count = count + 1;

            SetCountText();
        }
        else if(count >= 8 && other.gameObject.CompareTag("GameFinish"))
        {
            winTextObject.SetActive(true);
        }
    }
}
#

With it being triggered by walking over a plane and hitting it, with the tag associated with it.

silk night
cinder crag
#

https://paste.ofcode.org/34nRdJ4s6vpLjqJAbRnaZF2 (EnemySpawner script)

so i made a wave system , it works perfect but the problem is , every wave is the exact same enemy which can get pretty boring but i want for lets says wave 4 to have a stronger and bigger enemy that spawns , i searched on yt and goggle but still nth so im a little bit stuck and im not sure how i can do that , if anyone can help that would be amazing and appreciated alot :D

deft grail
cinder crag
deft grail
desert temple
silk night
#

Put a Debug.Log("TEXT"); in the brackets where you activate the text and watch the console while playing

desert temple
silk night
#

in the curly brackets of the else if

cinder crag
# deft grail so the enemies are random? i thought you said they arent or am i understanding w...

sorry im probably not explaining correctly , so lets say the first wave starts , it will be a combination of EnemyPerson and BigEnemyPerson that spawn in the enemiesToSpawn list gets the enemies from enemies list where are the enemies that i want to spawn in the wave , it takes them and puts them in enemiesToSpawn in a randomized index and if the enemyPerson is first in that line it puts it into the spawnedEnemies list and spawns it and the next enemy etc , the wave system is nice but the problem is even if im like at wave 10 it will still be the same two types of enemies and i kinda dont want that , i want for every wave to be something new like wave 4 to introduce a new enemy that is faster or stronger etc

#

hope i explained better

deft grail
deft grail
cinder crag
deft grail
desert temple
silk night
#

I would assume you never touch a Gameobject that is tagged GameFinish

cinder crag
deft grail
deft grail
cinder crag
deft grail
cinder crag
deft grail
cinder crag
twilit dirge
#

when I change a sprite during runtime via code, after unloading and reloading the scene it reverts back to its original state

#

Is there some way to save this permanently?

frosty hound
#

Not without coding a save system

prime cobalt
#

My scene view cam got weirdly tilted is there any way to correct it? Kinda not a code thing but idk where to put this question and it is a beginner thing so...

frosty hound
#

#💻┃unity-talk is for general questions. Click on the transform gizmos at the top right.

cinder crag
teal viper
dapper kernel
#

Does anyone know why I might not be able to connect my Unity Cloud to my project?

cinder crag
teal viper
#

Or currentWave.GetEnemyPrefab()

cinder crag
teal viper
#

Well, you need to store the wave data somewhere.

cinder crag
teal viper
#

I'd have a separate class for the wave data:

public class WaveData
{
    [SerializeField] private GameObject enemyPrefab;
    public GameObject GetEnemyPrefab()
{
   return enemyPrefab;
}
}
#

Then have an array/list of these to define all my waves.

teal viper
#

You need to decide what approach you wanna go with and remove the unnecessary code + refactor.

cinder crag
#

so basically if i want to go with the enemy that is first in the list should spawn i should let it how it is or how the guy does it

dusk tusk
#

@teal viper Type or namespace definition, or end-of-file expected

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

public class PlayerController : MonoBehaviour
{
    public float speed;
    public float jump;
    public Rigidbody2D rb;
    public BoxCollider2D bc;

    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        bc = GetComponent<BoxCollider2D>();
    }

    void OnCollisionEnter2D(bc col)
    {
        private bool canJump = true
    }

    void OnCollisionExit2D(bc col)
    {
        private bool canJump = false
    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(new Vector2(speed * Time.deltaTime, 0));
        if (Input.GetKey(KeyCode.Space) && canJump == true) {
            rb.velocity = new Vector2(rb.velocity.x, jump);
        }
    }
}```
#

Also I guess it didn't really explain it, I'm trying to detect if a collider is colliding

raw token
# dusk tusk ```csharp using System.Collections; using System.Collections.Generic; using Unit...

"Access modifiers" like public/private change how other code can see a class's members (it's fields and methods). It doesn't make sense to use them in front of a local variable declaration (the variables you define and use only within a method's body) because they can never be externally accessed.

So like

    void OnCollisionEnter2D(bc col)
    {
        private bool canJump = true
    }

will throw an error, because you cannot use private there.

A few lines are also missing semicolons.

In void OnCollisionEnter2D(bc col) you're also saying that the type of the col variable is bc which will throw another error, as bc is not a type - it's a class field variable. Both OnCollisionEnter2D() and OnCollisionExit2D() receive an argument of type Collision2D - so that's what you should type col with

If your IDE is properly configured for Unity, it should be highlighting these issues

muted viper
#

oh nvm someone already explained it oops

dusk tusk
#

Alr Imma try both of ur guys's ideas

dusk tusk
mint remnant
#

On the bright side, you can put the entire program on a single line

dusk tusk
#

Tf is error CS0246?

desert temple
raw token
# dusk tusk Tf is error CS0246?

No one has the error codes memorized. But that particular one is likely complaining about void OnCollisionEnter2D(bc col) because it doesn't know what the bc type is (because it's not a type)

dusk tusk
#

No errors!

dusk tusk
#

Alr moment of truth

#

Does it work?

#

IT WORKS!!!!

#

LESSGO

dusk tusk
#

I THINK I AM OVERREACTING

#

WOOOOOOO

raw token
#

Ride the wave :)

Cheers! 🍻

dusk tusk
#

although these physics are janky, I'm gonna fix that

dusk tusk
#

How do you lock the camera's y position?

raw token
dusk tusk
#

Also btw I'm trying to make an impossible game ripoff

raw token
# dusk tusk Yea

I think in that situation (and assuming that you're not using Cinemamachine), I would take the camera out of the player's hierarchy, and instead create a little CameraController script with a Transform target; field that you can drag the player game object into in the inspector, and have the camera match target's x coordinate in... I think LateUpdate() IIRC?

Alternately, I believe there's a "Position Constraint" component you could slap on the camera and configure it to freeze the y position

dusk tusk
#

Oh nvm

#

I'm gonna try moving the camera at the same speed as the player, but just in a different script

teal viper
#

Also, C# is not python, I suggest going through the Microsoft C# manual language specifications category to learn how C# is different from other languages.

cosmic dagger
warm condor
#

Hey everyone, can someone explain to me why my animation is very jittery when moving. I made a quick search online and I have found out that you can fix this issue by setting the interpolate enum from non to interpolate. That is what I did and it has become a bit better, but the issue still persist... Are there any solutions here?
Here is a video that shows what I mean:

open harbor
#

!vs

eternal falconBOT
#
Visual Studio guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

Visual Studio (Installed via Unity Hub)
Visual Studio (Installed manually)

rich adder
open harbor
#

can someone help me why my visual studio code is not autocompleting i even looked at the tutorial bu still nothing

#

for example the OnCollis is wrote but no autocompleteion

#

but as you can see i see the folders in the left from unity assets

cinder mason
#

I am doing this to get all the directoryInfos in my games saves folder

IEnumerable<DirectoryInfo> dirInfos = new DirectoryInfo(Path.Combine(dataDirPath, "saves")).EnumerateDirectories();

dataDirPath is the persistentdatapath but this has a count of 0, but when i remove the path.combine and just include the dataDirPath it has a count of 1, (the 1 being the saves folder). There are 3 files in the saves folder.

open harbor
#

@cinder mason do u know how to fix it?

#

or anyone

rich adder
#

also don't tag people into your question

open harbor
#

oh ok sorry

rich adder
#

first fix your project error you got there

open harbor
#

so what shoud i do

#

yeah

#

do u want the whole error?

rich adder
#

screenshot it

cosmic dagger
open harbor
#

whole error

#

i got more do u want ot see whole?

#

whole error?

rich adder
open harbor
#

here is the error in the output

rich adder
#

you need to restart PC after installs

cosmic dagger
open harbor
#

ok so shoud i just go to the site linked?

eternal needle
open harbor
#

i dont really know

rich adder
open harbor
#

ok

rich adder
warm condor
open harbor
#

what version of the sdk shoud i donwload???

eternal needle
open harbor
#

):

eternal needle
rich adder
#

x64

warm condor
eternal needle
warm condor
#

no I have writen my own code for that, here ill show it to you:

    private Vector3 offset = new Vector3(0f, 0f, -10f);
    private Vector3 velocity = Vector3.zero;
    public float smoothTime;

    [SerializeField] private Transform target;
    void FixedUpdate(){
        Vector3 targetPosition = target.position + offset;
        transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);
    }```
eternal needle
cosmic dagger
eternal needle
#

LateUpdate with interpolate should be ok, though not really sure what people do without interpolate on

warm condor
cosmic dagger
#

there are some tricks. you can create an empty child GameObject to the player and use that as the target (with your camera follow code in LateUpdate). it shouldn't jitter since the child GameObject is not moving using a rigidbody . . .

warm condor
open harbor
open harbor
#

is here any suggestions / feedback channel i can out my work?

rich adder
open harbor
#

thanks!

muted narwhal
#
           if (slotPrefab == null)
            {
                Debug.LogError("slotPrefab is not assigned in InventoryUI.");
                return;
            }

            if (parent == null)
            {
                Debug.LogError("Parent transform is not assigned.");
                return;
            }

            var newSlot = Instantiate(slotPrefab, parent);

            if (newSlot == null)
            {
                Debug.LogError("Failed to instantiate slotPrefab.");
                return;
            }

            var slotUI = newSlot.GetComponent<SlotUI>();
            if (slotUI == null)
            {
                Debug.LogError("SlotUI component not found on slotPrefab.");
                return;
            }

            slotUI.SetSlot(slot);

            var button = newSlot.GetComponent<Button>();
            if (button == null)
            {
                Debug.LogError("Button component not found on slotPrefab.");
                return;
            }

            button.onClick.AddListener(() => OnSlotClicked(slot, newSlot));```
I have this method and it should copy a prefab and paste it into a specified parent. I can see copies of these prefabs appearing in the hierarchy, but they are invisible. If I personally add a prefab to the hierarchy on the stage, it will be visible. Are there any errors in this method? 
Prefab look like this
-# This is not the full code. If you need more information on this - please tell me.
cosmic dagger
#

also, the slotPrefab variable should be a SlotUI type. this avoids using GetComponent to grab a reference to it . . .

#

oh, i see. you get multiple components from newSlot (the prefab). you could have a script on the prefab with a reference tot he SlotUI and Button components. then the slotPrefab variable would be the type of the script, and you'd access the slot and button components with newSlot.SlotUI and newSlot.Button . . .

muted narwhal
#

Like this?

cosmic dagger
# muted narwhal Like this?

you'd create a separate script that references the SlotUI and Button components

// Place this on the SlotPrefab GameObject
public class Slot : MonoBehaviour
{
    [field: SerializeField] public SlotUI SlotUI { get; private set; } // Assign from the inspector
    

    [field: SerializeField] public Button Button { get; private set; } // Assign from the inspector
}```
then in your code, you can access the components straight from the instantiated object . . .
```cs
[SerializeField] private Slot slotPrefab; // Change the type to the Slot component

// somewhere in your code . . .

var newSlot = Instantiate(slotPrefab, parent); // Returns a reference to the Slot component
var slotUI = newSlot.SlotUI; // Access the SlotUI reference (property from the Slot component)
var button = newSlot.Button; // Access the button reference (property from the Slot component)```
muted narwhal
#

Oh, thank you!

cosmic dagger
#

test it and check for errors (written without an IDE) . . .

queen raft
#

Is this a good place to post my PlayerMotor script? I added a debug and the isGrounded keeps returning false when it should definitely be true

cosmic dagger
eternal falconBOT
queen raft
#

should be it

eternal falconBOT
queen raft
#

Is it working?

cinder mason
#

I am doing this to get all the directoryInfos in my games saves folder

IEnumerable<DirectoryInfo> dirInfos = new DirectoryInfo(Path.Combine(dataDirPath, "saves")).EnumerateDirectories();

dataDirPath is the persistentdatapath but this has a count of 0, but when i remove the path.combine and just include the dataDirPath it has a count of 1, (the 1 being the saves folder). There are 3 files in the saves folder, yet it doesnt return any directory infos?

rich adder
cinder mason
#

im looking for the json files in the saves folder

rich adder
#

cause DirectoryInfo returns well directories.

#

Just use FileInfo

IEnumerable<FileInfo> fileInfos = savesDir.EnumerateFiles();
foreach (var fileInfo in fileInfos)
{
    Debug.Log(fileInfo.Name);
}```there is also 
`FileSystemInfo` to get both since they derive from it
muted narwhal
#

This is Slot.cs file if you wonder, the other part is InventoryUI.cs

worthy vault
#

becuese he is learning C#

#

and C# is it same in 2D and 3D ?

worthy tundra
languid spire
worthy tundra
#

damn didnt know

#

that actually makes sense now that i think about it lol

languid spire
#

break; is a statement, it can never be executed if you return directly before it

worthy tundra
#

yeah i get it now

muted narwhal
#

I have this value.

#

How can I access it here?

languid spire
#

on the basis of that information, impossible to tell

muted narwhal
#

Alright; I have Grid Layout Group on my object

And I also have a script, that has Main Slot Rows variable, but it's on another object.
How can I get the value of Main Slot Rows and put it as Constraint Count value in Grid Layout Group?

languid spire
#

!collab, after July 18th

#

They've taken the bot down.
Job postings are Forum only, not here and the forum is down until July 18th

eager spindle
#

against tos, this will get suspended immediately

worthy vault
eager spindle
#

he learned c# and programming before starting unity

#

You should too

slender nymph
eager spindle
#

All the first game devs specialised in Computer Graphics in compsci, programming in C

#

There was no Unity

#

There was no Unreal

#

Only programming in C

#

This should be the attitude you have before working with game engines, understand that you won't always have access to them

languid spire
eager spindle
#

Learn programming before you start

eager spindle
languid spire
eager spindle
#

Ah

#

I need to try my hand at making games for those platforms eventually

worthy vault
#

you mean i have to learn C# first and after that i go to learn unity ?

eager spindle
#

yep you'd learn things faster than way

wheat wave
#

I went straight into unity after I got fed up with using Scratch to make games, I would not recommend that

languid spire
fierce geode
#

Are the names of the virtual axes, like the names in the Input Manager stored anywhere?

languid spire
eager spindle
#

when I first started out I didn't know what using was, what MonoBehaviour did, what's the difference between defining my variable in a class vs defining my variable in a function

#

it did not work out well for me

languid spire
topaz mortar
#

I have an Item class and then several item type classes: Weapon, Armor, Spell, Scroll, ...
Weapon & Armor need a variable isEquipped
My Item class handles dragging, since all items need to be draggable
But then depending on the isEquipped variable (which is not in Item, but in Weapon and Armor) I need to do something different with the item when dropped
Is there any way to get this IsEquipped variable that is not in Item without having to create another class like Equippable?

For example, when selling an item, which is again possible for all Items, I don't want an equipped item to be sellable
Another example, when dragging an item on an EquipmentContainer, it needs to be equipped, unless it is already equipped

#
        {
            // Get our item
            Item droppedItem = eventData.pointerDrag.GetComponent<Item>();

            // Don't do anything if item is already equipped
            if (droppedItem.isEquipped)
            {
                return;
            }```
languid spire
#

That sounds like isEquiped should be in an Interface which may or may not be inherited by your Item sub classes

topaz mortar
#

I know what interfaces are and how they work, kinda, but never used one
How would that solve my issue?

serene briar
#

Hi. So I have
Mathf.Pow(6.6743, -11);
to represent newton’s universal gravity constant. For some reason, that outputs “8.541544e-10”. As far as I can tell, that number is significantly higher. Why might this happen?

eternal needle
languid spire
serene briar
eternal needle
topaz mortar
languid spire
serene briar
topaz mortar
languid spire
topaz mortar
#

so it's the same as casting Item to Weapon or Armor?

languid spire
#

yes

eternal needle
#

but id honestly be surprised if you get accurate calculations with such a small number

broken cargo
#

I don't think floats are precise enough for e-11

topaz mortar
slender nymph
languid spire
serene briar
topaz mortar
#

!code

eternal falconBOT
eternal needle
#

not really meaning its not about it freaking out. its just about values that cant be represented

slender nymph
slender nymph
serene briar
#

So the number is the same but looks different because floats can’t show that number? But it is still the same?

safe radish
#

im working on a cell based fluid sim, currently cells on the same y keep causing stackoverflows because they keep giving their fillAmount back and forth to eachother. how do people normally solve that problem? i was thinking to either save the newly added neighbours on the cells themselves or making a list of already edited cells and clearing it every iteration

languid spire
topaz mortar
#

cool, my first real use case for an Interface!! 🙂

#

you'll make a real programmer out of me yet!

slender nymph
languid spire
eager spindle
#

not sure what your code looks like rn

serene briar
slender nymph
#

please go learn about floating point accuracy in computing

eager spindle
#

The end user does not need perfectly computed numbers

#

They are not scientists

eternal needle
slender nymph
safe radish
#

guess i could add a flag in there that resets every iteration

#

for context, if you know of the game. i'm pretty much trying to recreate the fluid mechanics of timberborn

serene briar
slender nymph
#

Mathf.Pow uses floats

serene briar
#

dang it

slender nymph
#

you're not really going to find anything in the unity engine that uses any more precise data types than float

eternal needle
#

Maybe describe your use case more. Im not a big physics person but what do you actually plan to do with these numbers? If this is a one time calculation, then i see no problem with storing these as doubles initially and then converting them to float for the actual unity usage.

serene briar
#

It’s a simulator essentially that needs that tiny number to calculate the force of one object on another

#

And so it’s not possible to use a double float in calculations?

languid spire
eternal needle
topaz mortar
#

I'm trying to set up an event system to equip my weapon
When I drag/drop my weapon on equipment it correctly sends the event to my Inventory
But how do I get the dropped weapon in my Inventory script?

pine furnace
#

void Crouch()
{
if(Input.GetKeyDown(KeyCode.C))
{
transform.localScale = new Vector3(height.x, height.y/2, height.z);
GameObject gun = transform.GetChild(
}
if(Input.GetKeyUp(KeyCode.C))
{
transform.localScale = new Vector3(height.x, height.y, height.z);
}
}

#

why is this crouching code clunky

willow scroll
topaz mortar
pine furnace
#

first image is without crouching

#

and the second is with crouch

pine furnace
# willow scroll It doesn't even compile

using System.Collections;
using System.Collections.Generic;
using UnityEditor.Build;
using UnityEditor.Rendering;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{

Rigidbody rb;
[Header("Movement settings")]
public float walk_speed;
public float gravity;
public float jumpHeight;

private Vector3 height;

bool isGrounded;

public Transform groundCheck;
public float groundRadius;
public LayerMask ground;

Vector3 velocity;

void Start()
{
    rb = GetComponent<Rigidbody>();
    height = transform.localScale;
}

void Update()
{
    Move();
    Crouch();
    Jump();
}

private void FixedUpdate()
{
    Move();
    Jump();
}

void Move()
{
    float x = Input.GetAxisRaw("Horizontal");
    float z = Input.GetAxisRaw("Vertical");

    Vector3 move = transform.right * x + transform.forward * z;
    move = move.normalized;

    rb.MovePosition(transform.position + move * walk_speed * Time.deltaTime);
}

void Crouch()
{
    if(Input.GetKeyDown(KeyCode.C))
    {
        transform.localScale = new Vector3(height.x, height.y/2, height.z);
        GameObject gun = transform.GetChild(
    }
    if(Input.GetKeyUp(KeyCode.C))
    {
        transform.localScale = new Vector3(height.x, height.y, height.z);
    }
}

void Jump()
{
    isGrounded = Physics.CheckSphere(groundCheck.position, groundRadius, ground);

    
}

}

#

this is the whole code if u want it

eternal falconBOT
willow scroll
#

Yes, this throws a syntax error:

GameObject gun = transform.GetChild(
topaz mortar
pine furnace
#

i forgot to take it out

#

ignore that

willow scroll
slender nymph
# topaz mortar

use Action<Weapon> instead of Action since the latter does not allow a parameter to be passed

topaz mortar
slender nymph
#

also why does this inherit from monobehaviour if the only members are both static and it doesn't use anything that needs the MonoBehaviour inheritance

topaz mortar
#

dunno, I just followed a YT tutorial that had me put it on an empty gameobject

slender nymph
#

well that's entirely pointless

eternal needle
#

Amazing

willow scroll
#

Perhaps, this is just a start and new methods, suitable for MonoBehaviour, are going to be added soon

willow scroll
topaz mortar
willow scroll
serene briar
pine furnace
#

is there a way to only change the scale of the parent

#

and keep the scale of the children normal

#

or i need to do a for and go through all the children and double the value?

willow scroll
pine furnace
#

why it doesn t find my child

#

by name

#

i fixed it

pine furnace
#

!code

eternal falconBOT
pine furnace
#

cs
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{

Rigidbody rb;
Transform[] children;
[Header("Movement settings")]
public float walk_speed;
public float gravity;
public float jumpHeight;

private Vector3 height;

bool isGrounded;

public Transform groundCheck;
public float groundRadius;
public LayerMask ground;

Vector3 velocity;

void Start()
{
    rb = GetComponent<Rigidbody>();
    height = transform.localScale;    

    children = new Transform[transform.childCount];
    for (int i = 0; i < transform.childCount; i++)
        children[i] = transform.GetChild(i);
    
}

void Update()
{
    Move();
    Crouch();
    Jump();
}

private void FixedUpdate()
{
    Move();
    Jump();
}

void Move()
{
    float x = Input.GetAxisRaw("Horizontal");
    float z = Input.GetAxisRaw("Vertical");

    Vector3 move = transform.right * x + transform.forward * z;
    move = move.normalized;
    
    rb.MovePosition(transform.position + move * walk_speed * Time.deltaTime);
}

void Crouch()
{
    if(Input.GetKeyDown(KeyCode.C))
    {
        transform.localScale = new Vector3(height.x, height.y/2, height.z);
        for (int i = 0; i < transform.childCount; i++)
            children[i].localScale = new Vector3(children[i].localScale.x, children[i].localScale.y * 2, children[i].localScale.z);
    }
    if(Input.GetKeyUp(KeyCode.C))
    {
        transform.localScale = new Vector3(height.x, height.y, height.z);
        for (int i = 0; i < transform.childCount; i++)
            children[i].localScale = new Vector3(children[i].localScale.x, children[i].localScale.y / 2, children[i].localScale.z);
    }
}

void Jump()
{
    isGrounded = Physics.CheckSphere(groundCheck.position, groundRadius, ground);

    
}
#

is this efficient

#

to scale back all the children

topaz mortar
#

What does this mean? "Default references will only be applied in edit mode."

slender nymph
#

it means exactly what it says. the object you drag in there will only be applied to instances of that object created via the editor. using AddComponent in code will not assign that field automatically

topaz mortar
#

yeah that's what I thought, not very clear though

fierce locust
#

Hello, I'd like to make a system to place blocks with unity, it doesn't work, the block doesn't move to the end of my player's raycast, I use a layer so that the raycast doesn't interfere with the player

public class Build : MonoBehaviour
{
    [SerializeField]
    public GameObject blockPrefabs;
    void Start()
    {
        this.blockPrefabs = Instantiate(this.blockPrefabs, new Vector3(0, 0, 0), Quaternion.identity);
        
    }

    // Update is called once per frame
    void Update()
    { 
        RaycastHit hit;
        if (Physics.Raycast(camera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0)), out hit, 10, LayerMask.GetMask("Player")))
        {
            this.blockPrefabs.transform.position = hit.point;
        }
    }
}
slender nymph
#

I use a layer so that the raycast doesn't interfere with the player
that's basically the opposite of what your layermask is being used for. it will only detect objects on the layer named Player

winter tinsel
#

timescale is 0 but game continues to spawn prefabs ?

barren vapor
winter tinsel
#

yea

#

im checking by a integer that counts up

#

untill a certain value

#

then gets reset

slender nymph
#

show code

barren vapor
winter tinsel
#

the integer counts up to 200 then gets reset

#

aswell as the object being instantiated

slender nymph
#

that code is not only framerate dependent (so faster on higher framerates) but has nothing to do with the timescale. except, of course, for that erroneous deltaTime multiplication in the velocity assignment

winter tinsel
#

how do i make it time depedant?

barren vapor
#

szooczt += Time.deltaTime;

slender nymph
#

make your szooczt a float instead of an int, and increment it by deltaTime. then instead of using that arbitrary 200 unit, compare it the number of seconds you want to pass between spawns

winter tinsel
#

so im guessing 1 is 1 second?

#

like by using time.deltatime

#

szooczt would increment by 1 second?

barren vapor
slender nymph
#

it is not

barren vapor
#

0.0167*

#

oh wait. It's time bound, so it depends on the time itself

half egret
#

That's if it's a solid framerate, deltaTime retrieves the time since the last frame to be more specific

barren vapor
#

I think

languid spire
#

share your !code

eternal falconBOT
toxic cloak
#

and i dont have cinemachine imported

languid spire
#

then why are you asking in a code channel?

toxic cloak
#

Yeah thanks for the great help

languid spire
#

ask in the correct channel and you might get some, over entitlement problem on your part

sullen zealot
#

hello how can i set a coroutine to null after its finished?

half egret
ivory bobcat
#

What components are you using on object that you're trying to move?

teal viper
ivory bobcat
#

If you're using a Character Controller, it ignores modifications to the Transform component

#

And what else?

polar acorn
#

Show a screenshot of the inspector of it

sullen zealot
half egret
sullen zealot
# polar acorn exactly like that in fact

like this?

private Coroutine myCoroutine;
IEnumerator MyCoroutine()
{
  //Code
  
  //Set coroutine to null
  myCoroutine = null;
}
private void Func()
{
  myCoroutine = StartCoroutine(MyCoroutine())
}
half egret
#

Yep

sullen zealot
#

one more thing

#

does stopping a coroutine whit the StopCoroutine(coroutine) makes it null?

sullen zealot
#

oh ok

polar acorn
#

Try disabling this script and then trying again.

Also, when you say it "has no effect", do you actually have non UI elements in the scene to actually see the camera moving?

toxic cloak
cosmic dagger
polar acorn
#

Show the inspector of that

toxic cloak
#

and tried with a sprite renderer too

polar acorn
#

that is meant to move with the camera

#

and not move

#

That is how you're determining the camera isn't moving

toxic cloak
polar acorn
void thicket
#

You are always subtracting same thing here?

polar acorn
#

yes

void thicket
#

direction is always zero

burnt vapor
#

I thought there was no code related to your problem? This is why context in your question is important

#

It's not mentioned to bully or annoy somebody, there are different channels for different problems

void thicket
#

Perhaps you wanted GetMouseButtonDown for the first if condition

#

Debug.Log what value you are getting

muted wadi
#

Could I get some tips on how to code a visual indicator for a lock on system? Something like the Huntress' bow aiming from Risk of Rain 2. I'm thinking the best way would be to set up a system that moves around the indicator through a UI canvas and changes its size and position based on the distance the enemy is from the player and whether or not they're on the screen.

#

it seems to be the most effective way but there could always be something better

obsidian shoal
#

what variable type would i use to make
Input.mousePosition
into a variable

tawdry quest
#

badly presented question, look below for a better phrased version

languid spire
cosmic dagger
muted wadi
teal viper
fickle plume
#

!ban 959495299443863552 Nazi reference in pronouns

eternal falconBOT
#

dynoSuccess matvei31231238791 was banned.

tawdry quest
tawdry quest
#

but i want to work with the unity locale package ?

#

to translate to the correct language

teal viper
tawdry quest
#

what ?

teal viper
#

I don't know how you're using the localization package, but it probably just provides you a string in the correct language. After that you can use the string formatting to add your stats/numbers

tawdry quest
#

im confused on how to even access the localized string via code, the only stuff i really find is to use an extra script to attach to your game object that then replaces the text on awake

#

i guess i could run a script on start then that grabs the number and appends it to that textbox

teal viper
#

Well, solve one problem at a time. String formatting is one problem. Using the localization package correctly is another. Research them in order.

tawdry quest
#

i dont care about string formatting never asked for that

teal viper
#

Didn't you ask how to put numbers in the middle of your text?

tawdry quest
#

i want to load the correct localized string and then append the number

teal viper
#

And that's exactly what string formatting is for

tawdry quest
#

the problem is that currently the only way i know of using localization is that extra script to attach to your game object that then replaces the text on awake

teal viper
#

The appending numbers part

teal viper
tawdry quest
#

correct

#

how

teal viper
#

How what?

tawdry quest
#

let me rephrase my question, maybe the problem is how i asked it

#

gimme a sec

uncut dune
#

can I access the material of a particle subemmitter with a script and change properties in it for each particle?

tawdry quest
#

Question:
How can i load a string from the Localisation Feature of Unity via Code ?
I only found something tedious where i have to do something {value} to a smart string, but that sounds overly complex.
I would like to use something like this, but i couldnt find anything

text = Locale.LocalisedString(tablename,key)
text = text + damagenumber
teal viper
tawdry quest
#

As i said i found Smart String which kinda resemble what i need, but it seems rather tedious then just grabbing the string and adding my number via code

teal viper
tawdry quest
#

but i can also see that the implemtation via Smart String isnt actually that hard

#

thanks tho

teal viper
#
Smart Strings are a powerful alternative to using String.Format

It seems like they just do some more stuff for you.

uncut dune
#

can I not get the rendering material of each particle to change its properties?

eager spindle
#

what's particles?

rich adder
rich adder
# uncut dune can I not get the rendering material of each particle to change its properties?

We don't support multiple materials within a single particle system. All particles will be rendered using the same material.
https://forum.unity.com/threads/multiple-materials-in-particle-system.1204639/#post-7698733

uncut dune
void thicket
#

That’s pretty much the point of particle system

uncut dune
#

it is a subemmiter but I can just change its own particle system

uncut dune
rich adder
#

In what way? Particles also have their own shader

uncut dune
#

and I wanted to access that material and change the properties of it in runtime

rich adder
#

You can use .sharedMaterial if you want , then modify whatever you want

uncut dune
rich adder
#

Yes

uncut dune
#

I just wanted my material to have like a "start anim"

#

so something happens when it appears but Time doesnt work for that since it starts counting since the start of the game

rich adder
#

Why not make w timer and just swap material instead of directly modding it in the shader

uncut dune
#

I thought setting a property would be less expensive

rich adder
#

Well no you're creating a new material when you modify it

uncut dune
#

I see, thanks

#

so what is the syntax to access it directly?

#

something like particleSystem.renderer.material?

rich adder
#

.material

#

Yea

uncut dune
#

thanks

winter tinsel
#

uh, i have a very weird unity... is it a bug or am i just doing something wrong?

#

basically

#

one of my buttons dont work

#

and i dont know why

#

it worked fine

#

i added another canvas to make a pause menu, but even when removing it still doesnt work???, the button doesnt let me click it

polar acorn
#

Do you have an event system in the scene

winter tinsel
#

wdym

polar acorn
#

I mean do you have an event system in the scene

winter tinsel
#

why would that effect wether a button is clickable

polar acorn
#

Because that is literally the component that makes buttons clickable

mint remnant
#

you might just try going to the history panel and clicking back to before you added the canvas

winter tinsel
#

the event is if a certain bool is false make the canvas which has a child that is the button, visible

winter tinsel
polar acorn
#

I'm asking about an Event System

#

an object

#

is there one in the scene

winter tinsel
#

that handles events?

#

i mean not really?

polar acorn
winter tinsel
#

theres nothing that specifically uses Event and each indiviual gameobject has its own script

#

i dont get what you mean by event system

polar acorn
winter tinsel
#

oh dear

polar acorn
#

The object named Event System that has an Event System component on it

mint remnant
#

IE delegates

winter tinsel
#

gameobject named eventsystem

#

that has an eventsystem gameobject?

#

i mean component*

polar acorn
#

Whenever you first create any UI element in a scene, it will also create an Event System. That component is what makes UI work

#

don't remove it

winter tinsel
#

i havent touched anything

polar acorn
#

Notably, it doesn't get auto-created if you instantiate a UI element from a prefab

#

So, check your scene. Do you have an Event System in it

winter tinsel
#

i dont know what im looking for

#

nvm

polar acorn
winter tinsel
#

im blind

#

its there

#

eventsystem is there

#

but i havent used it?

polar acorn
#

It literally just needs to exist

#

that's it

winter tinsel
#

well in that case ys

#

its there

polar acorn
#

But it does have useful debugging features, if you look at the window on the bottom of the inspector of it while you're running the game, it will tell you what your cursor is hovering

#

Hover over the button that isn't working and see what it says you're hovering over

winter tinsel
#

ok

#

ok first of all

#

i hovered over it and it said text, and the button didnt work, but it worked before, so okay idk maybe something changed so i made the textbox smaller and now it tells me i hover over either the text or the button and when i click the button it STILL doesnt work??

polar acorn
winter tinsel
#

okay

#

button still doesnt work

polar acorn
#

Does the Event System now show that the button is the thing you're hovering over

winter tinsel
#

yes

polar acorn
#

Does the button have any sort of animations or response to hovering over it?

winter tinsel
#

no

#

if i try to click it nothing happens,

#

not even the weird tilt the other buttons have

polar acorn
#

Can you show the inspector of the button, and the event system when you're hovering it?

winter tinsel
#

that makes it slightly darker yk

winter tinsel
#

heres this just so you can rule out that it has no script

polar acorn
winter tinsel
#

wait a min

#

i just saw something in the inspector

#

in eventsystem

#

it says im hovering over the button but its not eligble for click?

zenith crown
#

Why does this not work?

polar acorn
#

It's a Character

zenith crown
#

oh

#

well what should i do then?

polar acorn
polar acorn
winter tinsel
#

let me

#

send a pic

zenith crown
#

Make the Vector3 into movement direction

polar acorn
winter tinsel