#💻┃code-beginner

1 messages · Page 551 of 1

rich adder
#

ah well its never too late to do it properly with !learn or the other resources pinned in this channel

eternal falconBOT
#

:teacher: Unity Learn ↗

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

rich adder
#

they are more specific / tailored to learning c# and Unity + c# api

junior ivy
#

I don't like courses. 80% of this would be a time waste for me. I'm doing purely a code approach with algorithms.
I'm almost completely not dealing with scene objects and it's properties (bare minimum configuration, I'm not creating a game ;p)

eager spindle
#

Yep this works really well

rich adder
heavy knoll
eager spindle
#

Which part are you trying to figure out now?

heavy knoll
#

just with how to do the sound playing when the object takes damage and gets destroyed

#

i think i figured out something though?

#

would this be a ok solution? AudioSource.PlayClipAtPoint(damageSFX, transform.position);

#

and the variable is public AudioClip damageSFX;

#

which is set in the inspector for each object

eager spindle
#

I'm just gonna say in advance that this PlayClipAtPoint spawns a GameObject with an audio source. It returns that GameObject too

heavy knoll
#

is there a way to change the volume/pitch of a playclipatpoint?

rich adder
#

its very limited

eager spindle
#

Oop nvm it doesn't return the gameobject

heavy knoll
#

ooh

eager spindle
#

You should probably add an audio source to your object

rich adder
#

creates a temporary audiosource

#

also if you do it often is pretty garbagey

#

much better you make a singleton

eager spindle
#

other people make an object pool of audio sources and a manager that lets you play the audio anytime

#

even lets you select the mixer(for when you want to adjust the volume slider)

rich adder
#

^ or a pool if you need localized 3d sounds instead of singleton sound manager script

eager spindle
#

I feel gaslit, I always thought PlayClipAtPoint returned the gameobject it created

rich adder
#

PlayClipAtPoint is a quick dirty solution, as soon as sound is done it destroys

#

hence the potential to make so much garbage

heavy knoll
#

ya i dont need localized 3d sounds just a normal sound that gets played

rich adder
#

SoundManager.Instance.PlaySound(yourSound) or enum whatever

eager spindle
#

you'll think about the problem when you encounter it in future 😃 aka when you have hundreds of sounds playing at the same time

#

pooling your audio objects will save you a lot of compute

rich adder
#

pooling is only needed if you need to spawn them as local 3D sounds emitting from their position

#

otherwise a Singleton suffice

eager spindle
#

or 2d and let it play

rich adder
#

but if you got multiple sounds at same time which one does your soundmanager singleton prioritize playing local 3d

verbal dome
rich adder
#

I tried singleton for 3D sounds, had to use Instantiated pooled sound objects

eager spindle
rich adder
#

idk what you mean "Global"

eager spindle
#

global sounds are 2d sounds

#

local sounds are 3d sounds

rich adder
#

I mean 3D sound . Singleton is kinda useless there

#

easier to spawn a SoundObject (sure use pooling)

eager spindle
#

You can PlayLocal(Vector3 position, enum sound) which teleports the object there

heavy knoll
#

How would i setup singletons for my sounds that i want to be played when my different objects take damage or get destroyed?

rich adder
teal viper
#

I only need one singleton. Not singletons

junior ivy
# verbal dome What are you creating then if i may ask?

huge terrain generation based on a heightmap or possibly a binary file because images could be heavy very fast when increasing the size
the terrain will be split into chunks and they will have LoD changed based on a distance to the camera

I know there is a plugin for it but I will have to have 100% code control over it to customize it further

verbal dome
verbal dome
#

Unity is great for stuff like this IMO

junior ivy
#

One thing is sure. Godot is not 😄

verbal dome
#

What is the use case? Do you export the terrain and use it somewhere else?

rich adder
verbal dome
#

@junior ivy Also have you looked at compute shaders for the terrain generation?

#

Or shaders in general

#

Or do you do it on the CPU

scenic crystal
#

please please please help me

junior ivy
#

yeah, that might be used as a level generator and reader
I'm having fun mostly, nothing specific

rich adder
scenic crystal
#

i have attempted to debug for legit 30 mins

#

i am so lost

rich adder
#

first of all thats not how you write an IF statement, we don't use {} for the condition

scenic crystal
#

so what do you use?

rich adder
scenic crystal
#

i always thought it was {}

junior ivy
scenic crystal
#

ohhhh

rich adder
teal viper
#

Should go over C# basics

#

It sounds like you didn't learn about C# at all

rich adder
#

check out the pathways on !learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

scenic crystal
rich adder
#

esp junior programming

teal viper
scenic crystal
#

yeah i legit just started

#

its hard

rich adder
#

your IDE is already configured, you're 60% ahead of people who come here for help

scenic crystal
#

my ide is visual studio right?

rich adder
#

indeed

#

the red squiggles means its working pointing you to the syntax errors

scenic crystal
#

(
if{ Input.GetKeyDown(KeyCode.Escape); }
{

 }

)

rich adder
#

no lol

scenic crystal
scenic crystal
rich adder
#

don't just guess. look at the basic if statment

scenic crystal
#

how

rich adder
#
scenic crystal
rich adder
#

also your comment in the code is misleading void is NOT a method

#

void is a Return type for the method

#

methods can also return objects, like int bool another script. etc.

junior ivy
#

I don't think game dev is the best way to learn programming 💀

rich adder
verbal dome
#

For me it was the only motivation to learn programming

#

Probably not the easiest route though, depends on the person i guess

rich adder
#

ofc its fun to see stuff move around on screen

#

inspiring

scenic crystal
#

i got it

rich adder
#

learning on Console/Terminal might not be as stimulating

scenic crystal
#

the one on the bottom ?

rich adder
scenic crystal
#

//void is a function

rich adder
junior ivy
#

I started programming with scraping google SERP with IP changer and hacking, better than a moving things in the screen tho :>D

scenic crystal
#

void Update()
{
if(Input.GetKeyDown(KeyCode.Escape) )
{

 }

}

#

wait whoops

rich adder
verbal dome
#

I started with Klik & Play which was a game making program that used a sort of "event sheet"
It helped me understand the logic without having to learn code

#

Similiar to gamemaker or multimedia fusion

rich adder
#

goddam im old... I remember that engine

#

i had it on my win98 machine lol

verbal dome
#

Same :D

rich adder
#

the examples were so funky lol

verbal dome
#

Oh god I vaguely remember there was some clown stuff or something horrifying with weird ass sounds and graphics

rich adder
#

haha yeah I think it was a whole sprite pack with those

#

omg nostalgia hitting hard

heavy knoll
#

And then i make an empty game object called SoundManager and have the 2 audio sources on that?

rich adder
rich adder
heavy knoll
#

for now im just reutilizing my footstep and dash sound effects but i eventually want unique rock cracking sounds or wood cracking sounds specific to each object

rich adder
#

that comes down to how you eventually identify type of sounds based on your item

verbal dome
#

For stuff like footsteps (or hit sounds), I'd have a component on each object that stores its "material type"

#

It could be an enum or a scriptableobject reference

#

And you'd use that to get the correct sound

#

I didnt really follow your convo tho so idk what the issue is

rich adder
#

yeah pretty good approach too. I think they want to play a sound when they drop a resource/break it

verbal dome
#

I use SO's

acoustic sequoia
#

I have a question about my input action. for some reason it's not working. logging everything doesn't give me any logs. nothing is firing. it's on the select button on my controller. i have my start button mapped and working, and i did the exact same set up and it's not working for select.

how can i debug this?

rich adder
# verbal dome

just curious, do you run a switch to identify or is it like stored on SO the sound

#

I'm still trying to break free from enums because of giant switches

verbal dome
#

The component on each object has a direct reference to the SO

#

And the SO has a direct reference to a sound

#

(FMOD event in this case)

rich adder
#

ahh ok audioclip stored on so, makes sense

heavy knoll
#

how do i get the SoundManager exist in the current context in my ResourceNode script

rich adder
verbal dome
heavy knoll
#

cause rn its giving me an error when i put those lines in

rich adder
#

being a singleton you can access it without a reference

verbal dome
#

But those enums aren't going to be very large, maybe 10 items each, so it isnt that bad

rich adder
#

yeah I saw the codebase for GTA3 AI and had a switch of about 10 for states, i suddently didn't feel so bad for using about the same amount heh

verbal dome
#

Switch often gets compiled into a dictionary or some other lookup table, as far as i know

#

As long as the switch is large enough

rich adder
#

good to know 10ish is not so bad since that usually my max. but yeah at that point its just easier to probably use a Dictionary

heavy knoll
heavy knoll
charred spoke
#

I suggest you read the link again

heavy knoll
charred spoke
#

You don’t need to but it is highly recommended in order to have a better dev experience in the future

rich adder
heavy knoll
#

and is that PlaySound method correctly added?

rich adder
#

look ok

charred spoke
#

I would still add the Dont destroy on load part

#

I do know why you are avoiding just implementing it like in the link provided

#

What is there is the standard go-to singleton implementation for Unity

heavy knoll
heavy knoll
#

how do i get it to work with this scripts calling?

verbal dome
#

AudioSource is a type. You can't call a non-static method directly on a type. You need a reference to an audiosource and call it onthat

rich adder
heavy knoll
heavy knoll
#

or should i change the AudioSource to a AudioClip type also?

rich adder
#

AudioSource is the Radio, AudioClip is the song

heavy knoll
#

why does it show this though when its talking about the implementations?

rich adder
#

looks fine to me

#

audioSource is the variable for the AudioSource component

#

eg
[SerializeField] AudioSource audioSource

heavy knoll
#

im so confused

#

if im making an AudioSource somewhere else and just using that

verbal dome
#

AudioSource is the type
audioSource is the instance of that type

heavy knoll
#

and not just using the AudioClip isn't that defeating the purpose of what im trying to do?

verbal dome
#

What exactly are you trying to do

#

Maybe you want to create an AudioSource instance that your sound manager uses to play sounds?

heavy knoll
#

just have sounds that can be changed based on which object type it is in the inspector

#

so if i have glass i can use a glass hit and glass break sound

verbal dome
#

Btw you have Destroy(this); in the singleton's Awake

#

It's better to do Destroy(gameObject) otherwise it just destroys the component and leaves an empty gameobject

heavy knoll
#

i also want to be able to change the pitch and volume of each sound

#

so i can randomize the pitch when i hit something

verbal dome
#

Unity's audio API seems pretty weak. Why can't you pass the pitch as parameter to the method 🤦‍♂️

#

You need to create an audio source anyway

#

And if you want different pitch for each sound, each one needs its own audio source

#

As far as i know

heavy knoll
#

where would i create the audio source on so i dont have to have an audio source component on each breakable object in my world?

#

just on my SoundManager and then somehow activate that from my script

#

depending on which one is referenced in the inspector of my ResourceNode script

verbal dome
#

Ideally your soundmanager would manage a pool of audio sources

heavy knoll
#

ok

verbal dome
#

But for now, you could just do this when you want to play a sound:
-Instantiate a gameobject (var go = new GameObject())
-Add an audio source to it with AddComponent
-Set the audio source's clip, pitch, etc. values you want.
-Play the audio source
-Use Destroy(audioClip.length) or something similair to destroy the audiosource's gameobject after time

heavy knoll
#

am i still able to do that, while being able to refernce which sound is being played from the inspector? Because i want each object to be able to have different sounds

verbal dome
#

Yes, you can just expand your current PlaySound method

#

Pass in the audioclip as a parameter, and optionally pitch and volume floats if you want

#

Then let the PlaySound method handle the rest

heavy knoll
verbal dome
#

As I said, you can do it in the PlaySound method

heavy knoll
#

so i just leave everything the same way i have it right now with the singleton and audioclips referenced on my other script and just add that in the PlaySound() method?

verbal dome
#

If you need the audio be positional (3D, panned based on position) then you need to set the audio gameobject's position and probably some settings on the audiosource too

verbal dome
heavy knoll
#

and then passing that audio clip in the play sound method like this?

verbal dome
#

Yes, stop stressing about that 😄

heavy knoll
#

public void PlaySound(AudioClip clip)
{

}

#

oki

heavy knoll
verbal dome
#

You search "unity addcomponent" on google and pick the first result which should be the documentation page for AddComponent

#

Then you read it and look at the examples to figure out how to use it

#

Try it!

#

I deliberately left out the code for that so that you learn to look things up

#

It's very important in game development

heavy knoll
#

is this correct so far
public void PlaySound(AudioClip clip)
{
var go = new GameObject();
go.AddComponent<AudioSource>();
}

verbal dome
#

Almost - you want to get the reference to the audiosource you added

heavy knoll
#

like i get what i see when i look it up

verbal dome
#

AddComponent returns the newly added component, do you understand what that means?

heavy knoll
#

but just cant seem to figure out how to use it in my current context

real grail
verbal dome
#

The examples on the doc page also show how to get the reference of the added component

heavy knoll
#

is this correct
public void PlaySound(AudioClip clip)
{
var go = new GameObject();
AudioSource audioSource = go.AddComponent<AudioSource>();
}

rich adder
# heavy knoll and not just using the AudioClip isn't that defeating the purpose of what im try...

the idea was grabbing the audioclip from the Object itself, the soundmaneger can do the rest

public class SoundManager : MonoBehaviour{
    public static SoundManager Instance { get; private set; }
    [SerializeField] AudioSource audioSource;
    private void Awake(){
        if (Instance != null)
        {
            Destroy(gameObject);
            return;
        }
        DontDestroyOnLoad(gameObject);
        Instance = this;
    }
    public void PlaySound(AudioClip clip, float pitch = 1, float volume = 1){
        audioSource.pitch = pitch;
        audioSource.volume = volume;
        audioSource.clip = clip;
        audioSource.Play();
        //or audioSource.PlayOneShot(clip)
    }
}```
verbal dome
verbal dome
#

You can find links to those in this channel's pins

heavy knoll
#

I know a bit of the basics, i just get confused when trying to apply it to different things

#

like im pretty sure that the line is just Making an AudioSource Variable naming it audioSource and than setting it to the AudioSource Component that was just added to the new gameobject that was made. hopefully that's correct lol

heavy knoll
#

that's what im mainly confused about

rich adder
#

but its a monobehaviour so you can link components in the inspector

#

you can also use multiple audiosources for different purposes

#

eg
[SerializeField] AudioSource sfxAudioSource;
[SerializeField] AudioSource musicAudioSource;
etc.

heavy knoll
#

so i just make an empty audioSource component on the SoundManager game object? and that gets filled with the audioclip which is selected by the other script?

rich adder
#

there is no set way to do it, its all about trial and error with what works best for you

real grail
rich adder
rich adder
#

if its a global sound / 2D no reason to use multiple AudioSources all over the place

heavy knoll
#

What is the DontDestroyOnLoad(gameObject); part you added doing?

rich adder
verbal dome
heavy knoll
#

ok cool

rich adder
#
public void PlaySound(AudioClip clip, float pitch = 1, float volume = 1){
    audioSource.pitch = pitch;
    audioSource.volume = volume;
    audioSource.clip = clip;
    audioSource.Play();
    //or audioSource.PlayOneShot(clip)
}
//other script

void Method(){
    SoundManager.Instance.PlaySound(clip, Random.Range(0.4f, 1f));
}```
verbal dome
#

Yeah but wouldnt that cancel previous sounds

rich adder
#

iirc if you do PlayOneShot it should play okay each one without interrupt

verbal dome
#

And changing audioSource.pitch doesn't affect the previously playing sound's pitch?

rich adder
#

it shouldn't if already played the one shot with those settings no? I did not 100 % test it though lol

#

my sounds were to short to notice

verbal dome
#

Idk at all, havent used these in years

rich adder
#

op can tryitandsee

verbal dome
#

I guess you could start with navarone's example and see how it goes

heavy knoll
#

so its better to use PlayOneShot if i dont want to cut off the last sound with the new sound and have them overlap?

rich adder
#

yea

heavy knoll
#

i remove the audioSource.clip = clip; and audioSource.Play(); and replace that with the PlayOneShot right?

rich adder
#

ya

heavy knoll
#

ok cool

#

im ngl i cant really tell either if the pitch of the last sound is getting overridden by the new sounds randomized pitch either lol

#

i mean it sounds fine the way it is i think lol

rich adder
#

the only way you can know for sure is playing a really long sound the first time at specific pitch then play another right after with another pitch

heavy knoll
#

ok

rich adder
#

but iirc it should just have whatever setting it was at the moment of invoke

charred spoke
rich adder
#

does it? isn't that PlayClipAtPoint
why does it need to create another AudioSource from audioSource ref

heavy knoll
#

i could always test with an ambient track i added ig

verbal dome
#

I know that PlayClipAtPoint does create a new one, not sure if PlayOneShot does

#

Maybe it does

rich adder
heavy knoll
#

ooh yup it does override the sound lol

rich adder
# verbal dome Maybe it does

would seem odd if it did but it can make sense if its agnostic to the current AudioSource to be able to overlap sounds

verbal dome
#

It's just insane to me that each clip needs its own audio source

heavy knoll
#

it sounds so funny with the ambient track

rich adder
heavy knoll
#

i played the ambient track

#

then played the rock hit sound

#

and it changed the ambient track to the pitch of the rock hit

rich adder
#

bummer

#

so its still in the audiosource while plays the clip

#

now i'm curious how this AudioSource is able to play multiple sounds at once without interrupt on ... i guess a new audiosource can make sense..but wow that would be resource heavy no?

verbal dome
#

So you do need to create a new audio source if you need a different pitch

rich adder
#

yea noticeable if the sound is going too long

#

you can go with Instantiating them too but imo you should pool them but idk if your exp level can handle pooling rn lol

#

worry about it later if perfomance is really an issue

heavy knoll
#

is it normal to not see anything in the AudioResource spot? while a sound it playing

#

i thought i saw which one was selected before but now it doesn't show anything in the audiosource

rich adder
heavy knoll
#

ohhh your right

#

ya

#

that makes sense

rich adder
#

everything I knew about 1 shot is now shattered lol

heavy knoll
#

xd rip

charred spoke
rich adder
#

ahhh ok makes sense

#

wows thinking it had some type of shit behind the C++ code

#

thought it was some type of queue or async

heavy knoll
#

do you think it's better to just have the new sound override the last sound by doing the other method instead of overriding the pitch with the oneShot?

rich adder
#

I think if the sound is short enough you probably wont notice the last sound changed pitch to new pitch but thats wonky and not good for long sounds.

#

btw you can also just have multiple audiosources and split where you play specific sounds types

charred spoke
#

Buuut I know think that changing the settings of the source doing the one shots changes all playing one shots

rich adder
#

yea that makes sense now. I never noticed cause my sounds were to short

charred spoke
#

And that is the second reason we do not use it

rich adder
#

Haven't used methods like that in a while. I use 3D sounds so I'm stuck with pooled objects

verbal dome
#

Does unity have any new audio API in the works?

verbal dome
#

Or available

rich adder
#

isn't unity audio just abstracted Fmod ?

verbal dome
#

I remember reading them reworking the audio so that they aren't dependent on FMOD anymore or something

heavy knoll
#

well thx so much for the help guys, i think i got everything the way i want it to be for now, i appreciate all the help a ton!

verbal dome
#

(Unity uses ancient FMOD under the hood)

rich adder
#

maybe they add more advanced fmod features..

#

or just use Wwise

verbal dome
#

DSP graph

#

Seems dead though

rich adder
#

gonna be in preview forever UnityChanLOL

#

job system compatible 👀

charred spoke
modern oxide
#

Two questions:

1: How do I spawn a prefab on my mouse position? I have it spawning just cant get it to go to my mouse

using UnityEngine;

public class MouseSystem : MonoBehaviour
{

    [SerializeField] private LayerMask MouseLayer;

    private void Update()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        Physics.Raycast(ray, out RaycastHit raycastHit, float.MaxValue, MouseLayer);
        transform.position = raycastHit.point;
    }

    
}

2: Is there a way to get and spawn prefabs without them being in the scene?

floral estuary
# modern oxide Two questions: 1: How do I spawn a prefab on my mouse position? I have it spawn...
  1. Your code looks like it should work, is there another collider it's hitting maybe? IS it moving at all? Have you printed the value of the raycastHit.point?

  2. Can you define what you mean by "in the scene"? Do you mean without them being in the hierarchy? If so, you can do something like

public GameObject myPrefab which will give you a field to drop into, and then later var myNewlySpawnedObject = Instantiate(myPrefab)

rich adder
#

if you only want it at the mouse position use ScreenToWorld instead

floral estuary
rich adder
#

btw are you using a prospective or ortho camera ?

modern oxide
# floral estuary 1) Your code looks like it should work, is there another collider it's hitting m...

mb I didn't elaborate one the 1st question. That is for my mouse pointer, that works, I was wondering how I could add to it so it could actually work with spawning the thing I want where I want. Here's my spawning portion in my other script

  if (mouseSystem != null && mouseSystem.activeSelf && mouseSystemScript != null && mouseSystemScript.enabled && Input.GetKeyDown(KeyCode.Mouse0))
  {
      Debug.Log("Landing");
      Instantiate(Rocket, new Vector3(0, 0, 0), Quaternion.identity);
  }
#

the other script is to big for me to send through discord

rich adder
#

instantiate takes a position, instead of vector3.zero you pass the position you want

floral estuary
#

well you're spawning it at new Vector3(0, 0, 0)

#

in your update before you were setting transform.position to the mouse position. Here get it the same way but replace that new vector with it

modern oxide
#

uh. I think I know how to do that

floral estuary
#

You have everything you need at this point, you just gotta put it together now ^_^

modern oxide
#

So, would I pass the transform from MouseSystem to Landing System? and if so how?

rich adder
#

make a reference

modern oxide
median anchor
modern oxide
#

ok I kinda got it. however im not sure how to resolve this

 void Start()
 {
     mouseRef = GetComponent<MouseSystem>().mouse;
 }
median anchor
#

It looks like you are missing a component, it's not attached to the object you are trying to get it from

modern oxide
#

the script im trying to pull the data from

using UnityEngine;

public class MouseSystem : MonoBehaviour
{

    [SerializeField] private LayerMask MouseLayer;
    public Transform mouse;

    public void Update()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        Physics.Raycast(ray, out RaycastHit raycastHit, float.MaxValue, MouseLayer);
        mouse.position = raycastHit.point;
    }

    
}

#

whoops hold on

#

and this is the gameobject its attached too

median anchor
#

GetComponent tries to get the component from the object the script is attached to. So since you are trying to use GetComponent in a script called LandingSystem, that's the object it will look for

#

You can use a reference, like: [SerializeField] private GameObject myMouseObject; and then use mouseRef = myMouseObject.GetComponent<MouseSystem>().mouse; in that LandingSystem script

#

You should probably look into how referencing other scripts and objects in Unity work, it solves the vast majority of issues beginners have

modern oxide
#

so this is what i've got, ther error has gone, but it just doesn't work.

private Transform mouseRef;
[SerializeField] private GameObject MouseSystem;


void Start()
{
    mouseRef = MouseSystem.GetComponent<MouseSystem>().mouse;
}
median anchor
#

Did you drag the object to the slot in the inspector? (by the way, you can reference the script directly to avoid GetComponents, so [SerializeField] private MouseSystem myMouseSystemScript would work fine too

#

Well, if it's not throwing an error the problem might be somewhere else in the logic then, I can't take a look at it now, but if no one helps you I'll be back in a couple of hours

verbal dome
#

If it even hits anything, that is. It could be null

#

Also make sure that you aren't mixing 2D and 3D physics, they can't interact.
Use Physics2D with Collider2D, and Physics with Collider (3D).

verbal dome
#

It is?

#

Seems to be working now?

median anchor
#

@modern oxide You are still spawning at the zero coordinates, aren't you? Instantiate(Rocket, new Vector3(0, 0, 0), Quaternion.identity); that is your issue

modern oxide
# verbal dome It is?

No my problem is that its not spawning at the mouse, I know its tracking fine due too the green dot

modern oxide
verbal dome
#

Are you sure you saved

#

If yes, show me what components the rocket has

modern oxide
#

the rocket is simple

verbal dome
#

I'm guessing your animator is modifying its position

modern oxide
#

ughhhhAAAAAAAAAAAAAAAAAAAAA

#

5 hours

#

Now just gotta figure out how to make them land and actually stand upright and not clip

magic panther
#

Here's the main function: https://hastebin.com/share/faziqewusi.csharp
Does anyone know an alternative to Application.dataPath? It works no problem when I run my project in Unity, but in the Build it seems to not do it's job.
I utilize the function in the link all over my project to access xml config files and image registries, like background layers. Speaking of, here's the two main functions that seem most broken (as in any calls to them in the build result in an error and the asset not returning): https://hastebin.com/share/izepacajil.csharp
This might just be a problem with the two functions. The issue blocks any further works on the project, it's pretty bad.

junior ivy
#

I have a weird problem. This code causes a huge white border in my game

using TMPro;
using UnityEngine;

public class DebugInfo : MonoBehaviour
{
    void Start()
    {
        GameObject g_Canvas = new GameObject("Canvas");
        Canvas c_Canvas = g_Canvas.AddComponent<Canvas>();
        c_Canvas.renderMode = RenderMode.ScreenSpaceOverlay;

        GameObject g_Text = new GameObject("TestText");
        g_Text.transform.SetParent(g_Canvas.transform);

        TextMeshProUGUI c_Text = g_Text.AddComponent<TextMeshProUGUI>();
        c_Text.text = "Hello World!";

        RectTransform rectTransform = g_Text.GetComponent<RectTransform>();
        rectTransform.sizeDelta = new Vector2(300, 50);
    }
}

If I comment the Start method, white border disappears.

magic panther
teal viper
teal viper
severe onyx
#

something Ive been wondering about for the longest time now, is there a better way to do this?

teal viper
severe onyx
#

set only an individual value of a color

teal viper
#

Ah, swizzle the color channels? You could just reassign them via temporary variables, but that would be more code than just constructing a new color. You could implement Swizzling like in hlsl via extension methods I guess.

severe onyx
#

I cant directly change r.color.a but it's the only field I wanna change

teal viper
#

you can set an individual value with:

color.g = gValue;
#

What is r in your code?

severe onyx
#

A SpriteRenderer

teal viper
#

Aah. Well, you can't assign it directly, because color is a value type property

teal viper
# severe onyx A SpriteRenderer

You could do it like this:

var c = r.color;
c.g = gValue;
r.color = c;

But obviously it would be more code than just constructing a new color.

severe onyx
#

yeah it's a pain

#

leads to long, unsightly lines

teal viper
#

Code is not supposed to be beautiful.
Just clear and readable.

nimble plinth
#

@fickle plume how do I make a model?

fickle plume
#

@nimble plinth Don't @ people not in conversation with you. This is a code channel. And is this a Unity related question even?

nimble plinth
#

Yea

#

It it's

#

Cuz it's 3d

#

Modeling

#

And I wanna 3d model

fickle plume
#

@nimble plinth If you want to model in Unity, read pinned messages in #🛠️┃probuilder for resources.

teal viper
magic panther
teal viper
# magic panther Here's the main function: https://hastebin.com/share/faziqewusi.csharp Does anyo...

The reason this does not work is because files in the build are packaged into a binary assets pack. Your XML file(if included in the build at all) would be in this packaged binary file, so you can't load it with a FileSteam like that. You could put it in Resources folder and load the same way you do load your other assets, but honestly, that's a pretty outdated way to load assets and is generally a bad practice.

#

And honestly, I can't see the appeal of using an xml for something like that anyway.

#

A simple scriptable object(or even a monobehaviour) with an array of tiles would be way easier to work with.

magic panther
#

or something like that, I haven't really worked with scriptable objects

teal viper
swift crag
#

Basically, none of the raw files you put into your Assets folder make it into the game

#

Unity interprets them as specific kinds of Unity assets and lets you access those

languid spire
#

unless they go into the Assets/StreamIngAssets folder and how you access them depends on your target platform

swift crag
#

indeed!

magic panther
#

How do I decide what should go in the StreamlngAssets folder?

#

Because I already use a Resources one

swift crag
#

StreamingAssets is used for files that must be directly copied into the build folder

#

one intended use is for movie files

magic panther
#

the xml files?

teal viper
#

If you want these files to be freely accessible and modifiable by players, then yes.

magic panther
#

And is there a way to do this without making them accessible and modifiable to players?

teal viper
#

It should. I've never used StreamingAssets myself, so can't say for sure.

teal viper
magic panther
#

I'll try the resources folder first. Thanks again for the help

swift crag
#

If I really needed to include an XML document, and I didn't explicitly need to have the file on-disk, I would reference a TextAsset

#

The Resources folder will also let you access a TextAsset. It's special because you can load assets by name.

#

(and thus every single thing in a Resources folder always gets included in a build)

magic panther
#

By the way, is there something wrong with xml files? Should I not use them in the full game once this prototype is finished?

#

I chose these because they seemed the most straightforward to use

teal viper
#

Nothing wrong with it. I just think you're doing more work with it compared to other methods.

#

At least in unity. If it was a homebrew engine, tailored for one specific game, it might be fine.

#

In unity we have Scriptable objects for storing arbitrary data.

swift crag
#

I keep most of my configuration data in ScriptableObject assets

#

I get to directly reference these assets where I need them

magic panther
swift crag
#

I mean I hope it does 🍀

teal viper
swift crag
magic panther
#

The scriptable objects are looking great from what you're saying. I'll use them for the full thing

teal viper
#

Some may be using an xml under the hood, but they would probably be serializing/deserializing them automatically into a scriptable object at editing time.

teal viper
#

I don't have concrete examples in unity, but I've worked on an unreal game that does that. But I believe it was mainly due to the fact that it was developed in a custom engine before moving to unreal.

weak talon
#

in unity editor game looks like first image
but when i build the project and open it, it looks like poo like second image
not sure why its doing this probably something lighting related but if anyone has a fix can you please help me

teal viper
#

They had all kind of weird authoring tools.

runic lance
#

there's one advantage to their XML/resources approach, because it's always loading only the necessary assets at the time
this would require more effort with scriptable objects probably

#

this is something that addressables solves nicely

teal viper
runic lance
#

this was an actual issue that I had in a bigger game 🙃

teal viper
tulip scroll
#

Can anyone recommend a complete tutorial on YouTube that teaches how to program in Unity?

teal viper
magic panther
#

In Unity everything works properly once again

teal viper
magic panther
#

Not like that. Moveing left and right works just fine, but instead of jumping, the player starts a jump, stops after like 5 frames and stays midair, able to move left and right

#

I'll record it once I figure out how to run a build in windowed mode

teal viper
#

Well, then it's the jumping logic that is the issue. You'd need to share the code.

magic panther
#
    private void Jump(float height) {
        velocity.y = Mathf.Sqrt(2 * playerVariants.gravity * height);

        ParticleSystem jumpParticlesInstance = SpawnSimpleParticle(jumpParticles1, Vec3ToVec2(bottomColliderPosition), true);

        ParticleSystem.ForceOverLifetimeModule forceOverLifetime = jumpParticlesInstance.forceOverLifetime;

        forceOverLifetime.enabled = true;

        forceOverLifetime.x = velocity.x / 5f;

        jumpBuffer.Clear();
    }
```It's just the top line.
Here's the full code, most of it is just variables at the beginning: https://hastebin.com/share/wubigijude.csharp
#

I think I'm creating more problems than there initially were

teal viper
eternal falconBOT
magic panther
#

the particle system is just for effects

#

nothing to do with physics

weak talon
teal viper
teal viper
weak talon
teal viper
weak talon
#

shouldi try putting all of them to something higher or what cause they are the same both editor and build quality

weak talon
teal viper
weak talon
teal viper
weak talon
teal viper
teal viper
#

So I'm not sure how your player is moved.

#

Or jumping for that matter

winged dune
#

So I have these few lines in a function of mine:

        // Load the UXML slot template for individual characters
        VisualTreeAsset slotTemplate = Resources.Load<VisualTreeAsset>("UI/CharacterSlot"); // Adjust file path/name as needed
        if (slotTemplate == null)
        {
            Debug.LogError("CharacterSlot template not found in Resources/UI folder.");
            return;
        }

        // Clone the template for the slot
        VisualElement characterSlot = slotTemplate.CloneTree();
        Debug.Log(characterSlot);

And the attached image is the hiarchy I'm working with. I don't understand why the debug message shows that the width of the cloned element becomes NaN instead of its set value.

verbal dome
#

I only see them getting called

#

Did you leave out the part that actually moves your character..?

magic panther
teal viper
#

Goddamit, I've no clue how you came up with an idea to name a method that actually moves your object Offset()notlikethis

#

I'm sorry, but I'll just have to pass on your question. That code is unreadable and almost undebuggable.

magic panther
#

Yeah

#

Started with sticking to walls, now the configs won't load properly and there's more stuff stemming from all that

#

might need to start over the project

teal viper
#

I'd recommend looking up some sample code from other people projects or tutorials(unity learn could be a good source for that) to get an idea of how similar features are implemented.
As well as maybe ask for a code review before your code is beyond redemption.

magic panther
#

where can I ask for a code review?

teal viper
#

Here. Though maybe keep it a bit specific instead of sharing your whole project code.

cosmic dagger
teal viper
#

You could for example, describe the overall logic/idea behind your code. And ask if it's okay. Followup questions might follow.

cosmic dagger
#

Honestly, I'm not sure what this script's purpose is? The name of the class and methods inside don't relate or tell me what it's supposed to do . . .

magic panther
trim moon
#

hey friends

#

anyone understands how does third person camera works?

cosmic dagger
trim moon
#

i have made everything how i would like but my camera just looks glitchy when i move it around

magic panther
#

I thought a Utils singleton, like my CameraManager (CameraManager.Instance.ShakeCamera and so on), but I feel a weird disgust towards the .Instance part. But that's just me

wintry quarry
#

If you have a code problem, feel free to explain it and share your code.

trim moon
cosmic dagger
magic panther
trim moon
#

so this is a script i have on main camera

#

it looks like it is not syncronized with player

minor radish
#

Can someone help me with this ? I'm following a tutorial and when I tape spawnPipe in start unity tell me that it's not asigned so what should I do

cosmic dagger
teal viper
winged dune
#

okay

cosmic dagger
minor radish
#

Here it is

trim moon
steep rose
#

you probably should configure your !ide

eternal falconBOT
arctic wren
#

Anyone know why the jumping feels higher each time I jump?

languid spire
eternal falconBOT
arctic wren
#

aight, I figured out the issue.

#

I wasn't resetting the vector

minor radish
solemn python
swift crag
#

You've already created a commit with the entire Library folder stuffed into it

#

Adding a .gitignore afterwards (or even adding it after staging your entire project) won't help. .gitignore only stops you from staging new files.

solemn python
swift crag
#

That means you put the .gitignore in the wrong place. Where did you place it?

#

It should be in the root of your project

solemn python
#

directly inside the project folder

swift crag
#

That filename is wrong

#

It must be exactly .gitignore

#

You have gitignore.txt

solemn python
#

oh

swift crag
#

The same goes for gitattributes.txt

#

it should be .gitattributes

solemn python
#

undoing the commit will allow me to use those ignores right?

#

ok i think it works now, only 65 changes

swift crag
#

I'm not sure what "Undo commit" does in Github Desktop

#

if it creates a commit to revert an older commit, then that will not help

#

tbh I'd just delete the .git folder and set it up again

solemn python
#

It worked i think, only 65 changes and now i can push

swift crag
#

the Desktop GUI doesn't let you do much

swift crag
#

If you've already pushed the commit to the remote repo, then just throwing out the commit is problematic (your history now doesn't match the server's history)

solemn python
#

git is annoying when it doesnt work xd

floral estuary
#

git always works lol

#

it just sometimes doesn't work the way you want XD

solemn python
#

I decided to create a game with friend (godot) and every time there was a conflict he would just press the force push button

#

xD

floral estuary
lapis veldt
#

Hello. I've made a caracter movement script and everything works fine, except the character cannot jump. I am using the "new" input system

void Update()
    {
        MovePlayer();
        SprintPlayer();
        if (IsGrounded())
        {
            JumpPlayer();
        }
    }
void JumpPlayer()
    {
        if (IsGrounded() && canJump)
        {
            canJump = false; // Prevent double jumps
            rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
            StartCoroutine(ResetJumpCooldown());
        }
    }
IEnumerator ResetJumpCooldown()
    {
        yield return new WaitForSeconds(0.2f); // Cooldown duration (adjust as needed)
        canJump = true; // Reset the ability to jump
        Debug.Log("Jump cooldown reset, can jump again!");
    }
    
    // Helper function to determine if the player is on the ground
    bool IsGrounded()
    {
        return Physics.CheckSphere(transform.position + Vector3.down * 0.5f, 0.1f); 
    }

this is what I am using for jump mechanic

swift crag
lapis veldt
floral estuary
#

but is the code running? you should use Debug.Log to see if that function is going off anywhere

#

At current, you're running JumpPlayer() every frame the player is grounded, it doesn't seem to be using the new input system at all, or any input system really, unless you're hooking it externally

flat sphinx
floral estuary
#

you should also make sure canJump is true when the script starts, otherwise there will never be anything to turn it true

swift crag
#

Then amend

lapis veldt
#

the method works without the condition

#

I have that condition because I want it to jump only once

swift crag
#

well..you'd want git rm --cached (:

#

git rm would remove the files from the working tree. bye-bye project

solemn python
#
using UnityEngine;
using Unity.Cinemachine;
using System;

public class FreeLookRightClick : MonoBehaviour
{
    public CinemachineInputAxisController axisController;
    Vector2 mousepos;
    void Update()
    {


        // Save and restore mouse postion when exiting look around

        if (Input.GetMouseButtonDown(1))
        {
            axisController.enabled = true;
            mousepos = Input.mousePosition;
            print(mousepos);
            Cursor.visible = false;
            Cursor.lockState = CursorLockMode.Locked;
        }

        if (Input.GetMouseButtonUp(1))
        {
            print("released");
            axisController.enabled = false;
            Cursor.lockState = CursorLockMode.None;
            Cursor.visible = true;
            Cursor.SetCursor(null, mousepos, CursorMode.Auto);
        }
    }
}

does any1 know how can i fix it so that when I release the right button and it unlocks the cursor, that it snaps back to where it was originally locked?

mint lion
wintry quarry
mint lion
#

do what?

wintry quarry
#

Do what

#

Install it, read the instructions, look up and read the documentation on Cursor Warping.

mint lion
#

if you want to do your own cursor then research 'software cursor' or 'custom cursor'

pseudo dirge
#

Hi, just want to ask some experienced guys for some advice. I have just started my journey in game development, I have basic programming concepts, but I am still not very familiar with the principles of oop and basic api unity. I start with small projects, but my friend suggested to create a merge game like marge mansion, can you tell me if I should take on this project, or continue to create games on a couple of gameplay mechanics to learn how to use unity and learn how to program?

eternal falconBOT
#

:teacher: Unity Learn ↗

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

solemn python
#

ty

white kite
#

Hello, I have a little problem, in my Unity game I'm trying to make a pause menu.
I managed to do it without any problem, but my only problem is that my turret can still shoots in the pause menu. I've already tried several things, and I managed to make it not move in pause menu, but the problem is that now it just can't shoot at all, so I'm desperate since I'm really not good at programming...

Here's the code of my player/turret :
https://hastebin.com/share/oveqekixah.java

And here's the code of my pause menu :
https://hastebin.com/share/uxaheyahah.csharp

solemn python
#

yeah i got it now

#

works

languid spire
white kite
mint lion
#

either set break points and see what's going on or add several Debug.Log() statements

languid spire
brisk oasis
#

Can someone help me plzzzzz

#

Can someone help me plzzzzz?

steep rose
#

sure

#

!ask

eternal falconBOT
brisk oasis
#

I'm making a top down online fighting game, but I want the weapon to rotate to the mouse of its owner

white kite
brisk oasis
#

How can I make it?

languid spire
white kite
languid spire
steep rose
#

I don't know how to use the new input system so that's why I linked the old input systems documentation (there is probably something similar in the new one).

brisk oasis
#

Thank you for your advice, I'll search how to get the position of the mouse and rotate the weapon

steep rose
#

The documentation I linked shows you how to get the mouses position using the old input system, so that should be a start.

rocky canyon
#

make sure that u convert the mouse position to world-space

steep rose
#

yup I totally forgot

still elm
#

I used a dontdestroyonLoad for my highScoreTable in my game which normally is being shown on the main menu to display the scores of player. I implemented the dontdestroy so I could access the addHighScoreEntry method, which I have added as a compnent to a gameobject with text and templete for entries. ( I followed a yt vid for the highscore table). However, when using the dontdestroyonload, the highscore table is visable in the game scene and I can add entries to it since it is loaded. Is there a way I can hide the scoretable when the game scene is runnning or should I use another way to access methods of the scoretable gameobject?

#

thanks in advance for anything that help 😄

swift crag
#

deactivate the game object if you don't want it to be rendered

still elm
#

Can I still accesse the methods in it?

swift crag
#

Sure

#

Disabling a behaviour just means Unity won't send some messages to it, like Update

still elm
#

Would you suggest a separate script like a sceneManger or how would I implement it?

swift crag
#

(and deactivating a game object disables all of the behaviours on it)

swift crag
#

The tracker always exists. The display only sometimes exists.

magic panther
#

Anything wrong with applying Singleton to interactable objects? Like, I need a special cursor for my game, and obviously it's preferred if there's just one, so would there be something wrong with adding a static Instance to the Crosshair class? Interactable as in it plays a big part in the game

swift crag
#

The only consideration for making something a singleton is whether exactly one instance (no more, no less) exists at all times

#

I'm not sure why you'd want to access a crosshair statically, though

magic panther
#

How else could I do that? Finding it by tag name each time I need it feels wrong

swift crag
#

I'm just wondering why you need access to it.

#

Do different objects need to change its color when you hover over them?

mighty compass
#

Hey guys I want to add ragdoll physics to my game, I’m sortof wanting the character to perform an action such as swinging a sword, but they can be knocked around during the animation by enemies, or if they run too fast into an object, where should I start

magic panther
#

it's a mouse only game

mighty compass
#

And I was thinking of making damage based off the velocity of the weapon when it collides with enemy object

#

I also want my character ragdoll to be able to trip if they run too fast into a curb or something hahaha

near wadi
#

@pulsar birch i think you may also have to configure your !ide based on that limited screenshot from the other room

eternal falconBOT
prime goblet
#

also @pulsar birch why don't you declare variable "p" as Vector2?

magic panther
near wadi
#

i was wondering the same ^^

pulsar birch
#

dont mind the terrible art

prime goblet
#

without any other code i dont know what your issue is

pulsar birch
#

hold on

prime goblet
#

your code snippet only shows you trying to cast float as an int

pulsar birch
minor reef
pulsar birch
prime goblet
#

lemme look at the rest

minor reef
#

I meant sunny

prime goblet
burnt vapor
prime goblet
#

do not direct people

burnt vapor
prime goblet
#

you could try implementing a spacing variable and making sure that the distance between pipes is that spacing

#

if thats ur issue

burnt vapor
#

A screenshot doesn't say anything

#

What is there to fix?

prime goblet
magic panther
minor reef
burnt vapor
minor reef
#

How do I make the ui look like the bottom right photo

pulsar birch
burnt vapor
minor reef
#

but like

#

still

prime goblet
magic panther
prime goblet
eternal falconBOT
near wadi
pulsar birch
pulsar birch
burnt vapor
# minor reef this is coding

What are you talking about? You are asking how to make Visual Studio look like Jetbrains Rider? This has nothing to do with actual coding

prime goblet
alpine fjord
pulsar birch
#

and i also need a scale of what the Y can be equal to to make sure it doesnt completelt disappear offscreen

prime goblet
eternal falconBOT
prime goblet
#

look here

minor reef
#

thx

burnt vapor
# minor reef mb

If this is a question on how to set up your editor, then follow the links. Idk what you mean with making it look like the bottom right window

prime goblet
#

they wanted their ide to show code like the bottom right window

burnt vapor
#

But please feel free to clarify if this is an actual coding question

burnt vapor
burnt vapor
# pulsar birch

It would help if you properly shared the code using a paste site 👇 . The last screenshot is cut off

eternal falconBOT
minor reef
pulsar birch
minor reef
#

no external tools

burnt vapor
pulsar birch
burnt vapor
#

Especially installing the workload, then setting the external editor.

burnt vapor
# pulsar birch here

If this is about the Y spacing, then note I don't see the Y position being modified at all

#

Just the pipes moving left

pulsar birch
#

hold on

pulsar birch
#

heres the script that continuously spawns them

prime goblet
burnt vapor
pulsar birch
prime goblet
alpine fjord
prime goblet
burnt vapor
pulsar birch
#

where do i put the line of code though?

prime goblet
prime goblet
burnt vapor
#

Use that for randomization

#

What ends up happening is that you set it to a random Y value based on the value passed in the Random check, and this is basically added to the Transform's Vector value through multiplication

pulsar birch
burnt vapor
#

Essentially a bunch of compact code, you can also write a variable before instantiating which might be more readable

#

So if that's confusing, maybe do this instead

burnt vapor
#

The random range indicates the offset of the pipes, try it

prime goblet
#

use the tabs

minor reef
#

im dumb

prime goblet
#

make sure you have the visual studio plugin installed

#

i think that's default

minor reef
#

still no work

burnt vapor
#

You're better off installing Visual Studio manually rather than through Unity. It's a lot less work

pulsar birch
minor reef
#

I mean'

prime goblet
minor reef
#

okay

#

be back soon

pulsar birch
burnt vapor
prime goblet
#

Instantiate(param1, param2, param3)

burnt vapor
#

You pass arguments into method parameters

pulsar birch
#

so like this?

burnt vapor
#

No, now you just multiply the result of Instantiate

#

You update the second parameter, not the return value

prime goblet
#

you have to put those vector math inside the position parameter

#

Instantiate(pipe, transform.position * Vector2.Up * Random.Range(0f, 5f), transform.rotation)

burnt vapor
#

If this is confusion, perhaps it might be a good idea to do c# tutorials before undertaking actual Unity. It's not a good idea to take on a Unity project without any C# experience

pulsar birch
prime goblet
#

!learn perhaps? (i didn't mean that sarcastically i was doing the command for the link below)

eternal falconBOT
#

:teacher: Unity Learn ↗

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

pulsar birch
burnt vapor
#

Programming is a big thing, you should not do both the Unity framework and the C# language

#

Especially because Unity is massively different when it comes to how C# works

prime goblet
#

it's very beginner friendly

burnt vapor
#

I would advice you check the pinned posts for tutorials

#

Vertx listed a good intro to c#

prime goblet
#

ignore "what's new"

mighty compass
#
            objectPropertiesRef.buildingType = "Wall";```
#

Attempting to access a script component on an object that I am creating during runtime, and change one of the script components properties.

#

Not entirely sure how to do that on unity

north kiln
#

Why are you using Component on the left? Use the actual type you care about

molten robin
#

How would I go about using Mathf.Lerp in this situation? I want the distance to interpolate smoothly

        float calculatedDistance = Mathf.Clamp(camDistance + Mouse.current.scroll.y.ReadValue() * -1f * Time.deltaTime, 4f, 15f);
        camDistance = Mathf.Lerp(camDistance, calculatedDistance, camDistanceSpeed * Time.deltaTime);
north kiln
molten robin
#

Oh you're right, that makes no sense

magic panther
north kiln
#

as the function is self-contained

#

No need for a scriptable object either

magic panther
#

Just a Script file with these functions set as static?

swift crag
#

Yes. A static method is not associated with a specific object instance (just like any other static member)

modern oxide
#

How do I get my asset that I spawn in game to snap to the ground instead of clipping half way through it?

swift crag
#

If the model's origin is in the wrong place, I'd suggest parenting it to an empty object

#

Adjust its position so that it lines up with the gorund

#

Also make sure the rotation and scale look right when the parent has those set to default values

#

(no rotation, 1 scale)

modern oxide
#

got it thanks!

proper needle
#

how do i call a button

#

i forgot what the command was

swift crag
#

that's a bit vague..."call a button"?

#

do you have a Unity UI button that you want to click via a script?

proper needle
swift crag
#

hm, I thought there was a nice Click() method!

#

The less enjoyable alternative is just calling OnSubmit directly

#

It needs a BaseEventData. It doesn't require any actual information, so you could just pass it a new one

#
BaseEventData data = new(EventSystem.current);
button.OnSubmit(data);
#

Manually calling OnSubmit is equivalent to hitting "enter" with it selected

#

grumble grumble! it's private!

#

You could also call OnPointerClick, but that wants more complex event data (that includes which mouse button was used)

proper needle
#

we made a button variable i think

swift crag
#

are you sure you aren't trying to respond to a button being clicked, though?

proper needle
#

then we made like an on button press void or smth

swift crag
#

i.e. run a method when the button is clicked

proper needle
swift crag
#

I thought you were looking for a way to trigger a button press from a script

#

In that case, you just need to add a listener to the onClick event

proper needle
swift crag
#

Any method that takes no arguments and returns void will fit in there

#

button.AddListener(SomeMethod);

proper needle
sterile radish
#

hello, im making a doodle jump clone and i want to know how im supposed to spawn platforms that have springs on them + other different types fo platforms? right now i'm only spawning one type of platform which is the very basic one that does nothing

heres a ref of what im looking for for clarity. right now in my game, im only spawning the basic paltform types (the green ones)

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

nova kite
#

The Unity tutorial straight up told me to use ChatGPT🤣

#

Looks pretty good tho

#

If I wanted to read about each function in this code where would I do that? Is there an official Unity documentation?

alpine fjord
#

!docs

eternal falconBOT
nova kite
#

How do I find a specific function there? For example transform.rotate

zenith cypress
#

There is a search bar

nova kite
#

It found all of this😵‍💫

#

Is it important to know everything about a certain function?

west radish
#

Important, no. But it never hurts to familiarise yourself with them to see what something is able to do

nova kite
#

And it’s just a matter of remembering?

west radish
#

I wouldn't think of it as an exercise to make sure you remember everything you read

#

You might stumble across something that you realise could work to help you do something in your game

nova kite
#

Hmm, how do you find what you need in the documentation? I searched “jump” for example and it doesn’t seem to show the results I’m looking for

west radish
#

That'll be done with a rigidbody that gives physics to an object

nova kite
#

Yes but I meant just as an example, to see if I could find answers in the documentation

#

It only gave me things for 2D

quartz wedge
# nova kite It only gave me things for 2D

Programming API's/documentation is important be able to read but It's not going to tell you how to implement something (there are guides and tutorials for that) but what the documentation does do is provide you with a list of methods (for Unity in this case) and as a developer, you can look up these methods and see how they work and what parameters/overloads they take. For example, if you're making a jump mechanic and you want to use the "AddForce()" method that the Rigidbody provides, the documentation will show you how to use it

west radish
#

I find it's about breaking down a problem in a way that could help you find something in the docs. It's hard to explain.

Take jumping. Taking it down to the simplest form, that's like a bunch of force has suddenly pushed you into the air. Searching jump doesn't give anything, but the more technical "force" will. And AddForce sounds like what jumping is if you didn't describe it with the word jump

#

And you want to use addforce, so you can see what allows you to do that, and now you have the knowledge of what rigidbody would be used for

nova kite
#

Ohh I see, so basically you can’t directly learn from the documentation it’s just like a collection of functions

#

I wouldn’t think of it as a force so that’s tricky, like if you asked me what jumping would mean to me in the most basic form I’d say that it’s the y value changing

#

So how do you initially know what words to look for? You just search the problem you try to solve on google?

west radish
nova kite
#

That’s true, I always hear that coding is about breaking a problem into steps and first making a logic map of solving the problem

#

I’ll try and work on that

quartz wedge
nova kite
#

The Unity guide broke the code into steps pretty well

steep rose
#

documentation is not supposed to be used as google where you search "jump" and it will tell you how to do such thing, it's only purpose it to inform you on its API and components/tools that you can use

nova kite
#

I see, so you need to specifically know the tool’s name and the documentation is to explain how to use that tool

steep rose
#

you don't need to know the tools name specifically, you can search for all of the tools it provides in it and search for something you can use.

#

yes it should tell you how to use that tool, or what it does at least

nova kite
#

I see that makes sense then, that’s why I couldn’t learn from documentation and gave up before haha I used it wrong

quartz wedge
# nova kite I see, so you need to specifically know the tool’s name and the documentation is...

Documentation is essentially just a list of methods/functions that Unity (in this example) have created. Unity has exposed a collection of methods that you can use in order to create your own systems. An example would be if you wanted to make an interaction system for your game, you can use a Raycast. The Raycast is something that has been implemented and exposed by Unity, hence you can read how it works in their API/documentation

nova kite
#

I tried SFML and it was so difficult 🥲

steep rose
#

If you would like to know how something is done, for example a jump, you would look on google or youtube

nova kite
quartz wedge
steep rose
#

That's what documentation is really

nova kite
quartz wedge
#

It's describing how you as a programmer would interact with their API/engine

quartz wedge
steep rose
# nova kite Hopefully they specify for which Unity version it is😅

The API and Manual does show which version of unity you are currently browsing on, it is not really needed to tell you what version of unity you are on unless there would be some breaking changes to the component (usually it is just some deprecated stuff and or renamed things)

#

for instance, unity 6 renamed RB.velocity to RB.linearvelocity, both are the exact same function exept for the name change

nova kite
#

Well for example I noticed that “Mouse” is not an Object anymore when following a YouTube tutorial and trying to detect a mouse click

#

It was Input.Mouse something and it was marked as an error on my end

steep rose
#

Mouse? That is not an object afaik, you would do Input.GetMouseButtonDown(1) or Input.GetKeyDown(Keycode.Mouse1)

nova kite
#

Yup! That’s what worked for me afterwards, and then I just abandoned the video because following it was so confusing with the outdated changes🥲

quartz wedge
#

When working with the input system, I recommend working with their new input system (I guess standard now?) over their legacy input system, it is a bit different but It is a better system and It's also what Unity recommends

nova kite
#

Ohh that explains it, they made a new system for it

steep rose
#

I never learned it lol

steep rose
nova kite
#

Hmm maybe it was a mistake on my end then

quartz wedge
#

It's not deprecated, both work but when working with the legacy system you would usually do something like "Input.GetMouseButtonDown(0)"

#

You would also need to wrap that in some sort of conditional(if) statement

#

For example:

nova kite
#

Oh wait what I saw in the video was
“Mouse.current.leftButton.wasPressedThisFrame”

#

And then it didn’t detect what Mouse is

quartz wedge
#
if(Input.GetMouseButtonDown(0))
{
  //Left-click pressed
}
nova kite
#

Yup that’s what he did in the video but with the line that I wrote, and it didn’t work but the one you wrote did

slender nymph
nova kite
#

Ohh, you need to install something else for that

nova kite
slender nymph
#

if you aren't using Unity 6, yes. it is installed by default in unity 6

nova kite
#

Oh I am using Unity 6

slender nymph
#

then you either uninstalled the package, or your IDE is not configured so you didn't automatically add the using directive when attempting to use the Mouse class

nova kite
#

Funnily enough the guy in the video wasn’t using 6 lol

slender nymph
#

the input system has existed for years, it is not exclusive to unity 6

nova kite
#

Wait so which is the new one🤣

quartz wedge
frosty hound
#

It's the "newest" one, but it's hardly new.

#

At this point it's the standard, and the Input.GetKeyDown method of input is the old one.

nova kite
#

Ohh hold on is that the
using UnityEngine.InputSystem;

#

Because that also gave me an error

slender nymph
# nova kite Wait so which is the new one🤣

the input system. the one the video was probably teaching you about. it's just "new" in that it is more recent than the legacy Input class. but it's still like 6 years old at this point

nova kite
#

Huh, so maybe mine wasn’t installed automatically

frosty hound
#

Check your package manager to see if it's installed

slender nymph
# nova kite Huh, so maybe mine wasn’t installed automatically

unless you are using a project that was created in a version before the first Unity 6 LTS (though there were several preview versions that had it installed too, i just dont' know the specific patch number that did it) then it was installed automatically.

nova kite
#

These are all the ones I have

#

Looks like I do have the new one

slender nymph
quartz wedge
#

You could also go to your preferences > Player and see what input system is ticked, you have an option of "new, legacy or both". I'm not sure if Unity 6 is different as I've not upgraded but I know there is an option in the preferences to choose which input system you use

steep rose
#

I believe it is on both by default

quartz wedge
#

Ah, that's fine then

slender nymph
#

and that setting also does not affect compilation

nova kite
#

Is there even any benefit from using the new one because visually I understand the old one better

quartz wedge
slender nymph
steep rose
#

but yes what box said

nova kite
#

I see, I’ll just stick to the old one for now since I’m just learning how everything works haha

steep rose
#

That's fine

quartz wedge
nova kite
#

I only understood half of this😅😅 I don’t have much context for many terms haha

steep rose
#

I have not even learned the new one yet and it's mainly to do with laziness but there are improvements with the new one over the old one

quartz wedge
#

It also is geared up for different input types (mouse, keyboard, gamepad, haptic devices, AR/VR devices) and it handles re-mapping of input, so It's definitely something worth learning but if you are completely new then it may make sense to stick with the legacy until you need something specific that the other input system has

nova kite
#

Ohh so it’s good for like multi platform

quartz wedge
#

Yes

nova kite
#

Like if you want to convert a game for multiple devices

#

I see

#

Thank you for the help and explanations guys🙏🏻🙏🏻

sterile radish
#

hello, im making a doodle jump clone and i want to know how im supposed to spawn platforms that have springs on them + other different types fo platforms? right now i'm only spawning one type of platform which is the very basic one that does nothing

heres a ref of what im looking for for clarity. right now in my game, im only spawning the basic paltform types (the green ones)

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

naive pawn
#

and probably takes into account score/height

sterile radish
#

wdym by different weights?

naive pawn
#

suppose you have a box with 2 blue balls and 8 red balls
if you pick one at random, you have a 2/10 chance to get blue, or 8/10 to get red
so you could say that blue has a weight of 2 (or 0.2) and red has a weight of 8 (or 0.8)

#

that affects how common or rare each type of platform is

#

you obviously wouldn't want equal amounts of every platform

#

step back from the code for now; code is how you do it, but first you'll have to decide what you want to do
start designing what types you want to have, how common you want each type to be, and how that changes depending on score

#

once you have a good idea (doesn't have to be a complete idea) of what you want, start coding it up, and if it's not complete or not to your liking, go back to tweaking the design

sterile radish
#

that's really good advice, thank you!

heavy knoll
#

Anyone know if its better to split up different aspects of my player into different scripts? Like if i wanted to add a player pickup should that be in its own script and then the player inventory be in another script and interact be in its own script? Also how should i go about doing raycasts for different things using the same key? I wanna have a pickup system that casts a raycast and picks up the item when i press E, and also use E for an interact raycast that will see if i interacted with any interactable objects like crafting benching and light switches? Can that all be done from just one singular raycast?

cosmic dagger
#

basically, to create specific objects in your game, you want to build them by adding components to the GameObject. those components are individual behaviour that make up what the object is and does . . .

#

it's a component-based approach using composition . . .

teal viper
teal viper
heavy knoll
#

and same thing with my crafting benches and stuff? like a script on the crafting bench with its functionality and then a function for Opening or closing the crafting bench which is called from the raycast also?

teal viper
cosmic dagger
# heavy knoll Anyone know if its better to split up different aspects of my player into differ...

ideally, an item (GameObject) that is interactable would have a script that implements an IInteractable interface. you'd have a separate script handle the raycast that checks for the interface. if an object is found, you call the Interact or Use (whatever method) you choose to call it

each script with the IInteractable interface must implement that method, and will have its own code . . .

teal viper
cosmic dagger
#

the Interact method implemented on a light switch script will have code to flip the switch (turning it off or on) . . .

#

the Interact method implemented on a crafting table will initiate crafting mode and pop-up the crafting menu and possibly open the player inventory, etc . . .

heavy knoll
#

Ok cool so i guess its pretty much the same thing as Unreal's blueprint interface system, i used that a little bit and it seems pretty similar.
So to make sure i got this right, I'd just have like a script on my player that is called PlayerInteract or something, and that will have a method on it to shoot a raycast when i press a key. And in the raycast it will check if it hits an object with the IInteractable interface and if it does it will call the Interact or Use method on the gameObject that was hit?

teal viper
cosmic dagger
teal viper
#

In a more modular game where you'd want to enable disable core functionality like interaction and such, it might make sense to separate it into a separate script.

heavy knoll
#

Ok, well thanks for the help guys! ill be back again if i get stuck on something with it, but i should be good to just lookup stuff about interfaces within unity now to see exactly how to do it

teal viper
heavy knoll
#

felt like i just wasn't really learning the core concepts well not learning with an actual coding language and it felt like a waste of time lol

sour cape
#

trying to play a video in unity but the quality looks much worse than the source file, anyone know how to make it perfect?

wispy coral
#

do yall know if theres a good course for procedurally generated stuff in unity?

charred spoke
#

The internet is filled with tutorials on procedurally generating stuff

teal viper
sour cape
#

yeh sorry, its just the videoplayer component, i thought someone might know off hand if its capable of playing good quality video at high frame rate(1920x1080 mp4)

bold pebble
#

Whats a good youtuber to learn c sharp off?

teal viper
swift elbow
bold pebble
#

Ok thanks.

sour cape
teal viper
#

At the very least take a screenshot of your video player component

#

Where does it output the video to?

#

Take a screenshot of the video clip asset inspector as well.

burnt vapor
#

Then just randomly pick one with a weight system

#

As for detecting what platform you land on, check collision when landing on them and use pattern matching to pick the type of platform you land on. For this I suggest you either use a tag, or you create an interface that specifies a property to be implemented representing the identity.

#

Next, another interface that represents the action to visualize when jumping on them. For example, the spring expands. The reason you also want to use an interface is because pattern matching is very easy and it works with GetComponent.

#

Lastly, the breakable platforms should be a trigger instead, so falling is not interrupted.

misty timber
#

Hi guys i am an absolute Beginner and faced to an issue i don't get. I opend a new 2d projekt to test a bit around i created an canvas , as a child i created an image. I moved an png file for the Backgroud . And yesterday it worked fine i saw the image in game and scene view . Today i played around with some buttons and hooks and then i lost my background only on scenview. I can see the borders and a black diagonal line . I csn move the image and i see that it moves in game view. Icreated a complete new 2d projekt and have still the same issue. I asked chat gpt for troubleshoot my problem but all tasks are correct. Any thoughts?

feral verge
#

so i having problem with movement, but all works except it's little bit slippery who knows why is that:

burnt vapor
#

Please use proper !code formatting when posting here

eternal falconBOT
feral verge
tiny vault
#

Im about to go insane. I've wrote a script that displays an interact Icon when you're near a Interactable object, specifically doors, however it's only at some of the doors it will correctly displaye " Press E to interact " once you're close, even though they have the exact same settings and components( at least i think so). Any ideas ?

keen dew
#

You'll have to show the script

tiny vault
#

Sure, but doesn't the fact that it's the exact same scripts that are attatched, and only one is working means that it's not a script or code issue `? sorry if it's a stupid question, but im new to game developing

keen dew
#

There is something different in those two cases and seeing what the script does would give hints at what to check next. It's impossible to guess what might be wrong just by looking at two identical screenshots

tiny vault
#

Makes sense. here is the script that each Door is inheriting from, and ther door script

keen dew
#

Does pressing E still work even if it doesn't show the text?

tiny vault
#

Yeah. E will still make you interact, the icon just doesn't show

keen dew
#

Oh I see, it's because this script is on multiple doors and each of them refer to the same text object

#

So each of them run on each frame and only the last one that runs gets applied in the end

#

I'm trying to think of the best way to handle it

tiny vault
#

okay thank you so much!!

keen dew
#

Maybe not the best way but this would fix it. Make a new script on the interact icon object that has this:

private bool itemInRange = false;

public void ShowText()
{
    itemInRange = true;
}

void LateUpdate()
{
    gameObject.setActive(itemInRange);
    itemInRange = false;
}

and then in the door script call ShowText when in range:

if(IsInsideInteractArea())
{
    interactIcon.ShowText();
}

(change the type of interactIcon to the new script)

#

That way the door scripts don't cancel each other out

dense anchor
#

I'm trying to make a dash ability but character is won't dashing.

{
    [SerializeField] private Rigidbody2D _rb;
    [SerializeField] private InputActionReference _dash; 

    [SerializeField] private Movement _moveScript;

    [SerializeField] private float _dashspeed;
    [SerializeField] private float _dashduration;
    [SerializeField] private float _dashcooldown;
    [SerializeField] public bool _isDashing = false;
    [SerializeField] private bool _canDash = true;


    void OnEnable()
    {
        _dash.action.started += DashAb;
    }

    public void DashAb(InputAction.CallbackContext context) {
        if (context.performed && _canDash) {
            StartCoroutine(DashCoroutine());

        }
    }

    private IEnumerator DashCoroutine() {
        _canDash = false;
        _isDashing = true;
        float _dashDir = _moveScript._movedirection.x;

        _rb.linearVelocity = new Vector2(_dashDir * _dashspeed, _rb.linearVelocityY);

        yield return new WaitForSeconds(_dashduration);

        _rb.linearVelocity = new Vector2(0f, _rb.linearVelocityY);
        _isDashing = false;

        yield return new WaitForSeconds(_dashcooldown);

        _canDash = true;
    }

}```