#💻┃code-beginner

1 messages · Page 73 of 1

solemn fractal
#

The prob here is that all the logic is inside the OnTriggerEnter2D and inside the cs if(other.CompareTag("Enemy")) meaning that, if I shoot a bullet, and it hit the first enemy it will enter this IF. When it goes to the other enemy it will also trigger this IF, as it is another enemy with Enemy tag. I cant see where to use an INT here because everytime it hits an enemy it will come to this IF. Maybe I am blind here, but how can I say ok hit first enemy and go inside the IF, but what about the second one? and if I am shooting so fast that by the time I hit the first enemy I am already hitting another enemy. it will all go to this IF and mess everything. I am not sure if I am being clear. Here is the code again: https://paste.ofcode.org/RQEAu7NddxKnCA6RDD6j7H

swift crag
#

might need to restart VS

rich adder
#

pretty its installed as a dependency with splines

swift crag
#

and/or regenerate project files

orchid trout
#

I see, Ill start by doing that 👀

swift crag
#

sometimes VSCode just completely throws up and forgets that UnityEngine exists

#

error salad ensues

orchid trout
#

Yeah it can be hard to tell whats actually in error in times like that

swift crag
#

VS might not have realized that Unity.Mathematics exists...fully, at least

rich adder
#

what version of VS are you using? looks old

orchid trout
#

What is the vallue of Adjusted Position being passed in? I am trying to get a value out of this, I don't know what to pass in

orchid trout
amber spruce
#

how do i do a wait so like in my code i want to wait like 2 seconds

swift crag
#

Are you trying to do that?

amber spruce
orchid trout
#
    {
        var distance = SplineUtility.GetNearestPoint(_splineContainer.Spline, adjustedPoint, out float3 xyz, out float t, 3, 2);
        Vector3 nearestPoint = new Vector3(xyz.x, xyz.y, xyz.z);
        Vector3 nearestPointResult = _splineContainer.transform.TransformPoint(nearestPoint);
    }
rich adder
eternal falconBOT
swift crag
orchid trout
#

What I am trying to do is trace a spline with freya's Shapes asset lines

swift crag
orchid trout
#

Yeah exactly

rich adder
#

ohh

swift crag
#

you'll want this

#

Shapes lets you draw Bezier curves. I wonder if you could just copy the spline points into a Bezier shape.

#

dunno if they use the exact same style of curve or not

rich adder
#

gotta love splines

orchid trout
amber spruce
orchid trout
#

I even posted on Freya's forum and they said Splines are not supported

rich adder
#

Gizmos.color = Color.green;
Gizmos.DrawSphere(nearestPointResult, 0.2f);

#

the pink one shows where it is in the Spline coordinates

#

GetNearestPoint is a life saver fr

orchid trout
#

I guess all of this is an XY problem , my REAL question is how do I make art that looks like this
And my Y sollution is to trace a spline with freya lines
so I might just be barking up the wrong tree

swift crag
amber spruce
swift crag
#

here's a file I was using to report a bug, lol

rich adder
swift crag
#

the BezierTo method malfunctions in a specific situation (i think when the line is entirely in the XZ plane?)

orchid trout
swift crag
#

This is probably going to differ from how unity splines work. notably, BezierTo only takes three arguments: start, a control point, end

orchid trout
#

Is that something built into unity?

amber spruce
swift crag
orchid trout
#

Yeah that too ^

rich adder
amber spruce
rich adder
verbal dome
#

GL lines are pretty harsh, no antialiasing

rich adder
#

something new to learn UnityChanCoder

swift crag
orchid trout
#

freya lines have AA and tons of other stuff

swift crag
#

Actually, you know...

rich adder
swift crag
#

BezierTo is ultimately just adding a bunch of points to the polyline

#

So it'd be just as good as evaluating a bunch of points on the Spline and making a polyline out of those

swift crag
orchid trout
#

I tried using a shapes polyline but was having a lot of problems with it, I thought it would be simpler and easier to brute force the answer by instantiating a ton of lesser individual lines

swift crag
orchid trout
#

I think so? I don't need 3D in my use case at least

swift crag
#

I haven't used Shapes in a bit so I'm a little fuzzy

orchid trout
#

I figured it would be easier to get answers on how to ask how to use the stock Spline asset than to ask how to convert a spline to a freya polyline

rich adder
#

yield return new WaitForSeconds

#

its literally in the name WaitForSeconds

swift crag
#

so, back to the original question: use EvaluatePosition to get a bunch of points along the spline

orchid trout
#

Okay so I am getting a bit overwhelmed by all the useful answers rapidly shifting. Let me go through my own code again and the posted code to see if I can reach understanding of what I should be using

#

Gotcha, okay will do that

swift crag
#

you can then construct polylines or individual lines from those points

rich adder
#

an interesting challange im gonna try it on mmy splines test scene

#

not a code question

orchid trout
alpine wraith
orchid trout
#

I guess search is hyper case sensitive?
Dunno why it cant find the EvaluatePosition in this

supple pumice
#

hi
I have 4 idle animations: up, down, left and right
this is my movement code

using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    public float speed = 5f;

    private Animator animator;
    private bool isMoving = false;

    private void Awake()
    {
        animator = GetComponent<Animator>();
    }

    void Update()
    {
        // Get input from the player
        float horizontalInput = Input.GetAxis("Horizontal");
        float verticalInput = Input.GetAxis("Vertical");
        if(horizontalInput != 0 || verticalInput != 0)
        {
            isMoving = true;
            animator.SetBool("isMoving", isMoving);
        }
        else
        {
            isMoving = false;
            animator.SetBool("isMoving", isMoving);
        }

        animator.SetFloat("moveX", horizontalInput);
        animator.SetFloat("moveY", verticalInput);
        Debug.Log("Horizontal: " + horizontalInput + " Vertical: " + verticalInput);

        // Calculate the movement direction
        Vector3 movement = new Vector3(horizontalInput, verticalInput, 0f);

        // Normalize the movement vector to ensure consistent speed in all directions
        movement.Normalize();

        // Move the player
        transform.position += movement * speed * Time.deltaTime;
    }
}```

the problem is that by doing this I get the when the player is not moving it just does the down idle animation, because its settings are x 0 and y 0
the problem is that I can't add x 1, y 0, y -1 x 0 ecc. because even movement has 1, 0 and eccetera
how can I fix
#

and the other problem is that idle animation is always active

rich adder
supple pumice
orchid trout
#

@swift crag @rich adder Thank you for the assistance both, it doesn't error anymore; I should be able to take it from here. Ill post results when I have some

rich adder
#

"idle is always active "

#

wdym

orchid trout
#

I spoke too soon 🫠

#

splines, math, and spline container apparently dont exist somehow?

#

I guess I can google this

rich adder
#

you regen project files and restarted

orchid trout
#

Oh not yet, Ill do that now

dense root
#

So I've got placeholder words in the inspector but I'm confused how that was made and how I change the words

rich adder
#

Once the script serialized with those initial values , you cannot change them via script on the initializer

#

use the Inpsector

orchid trout
rich adder
#

ahh yeah that will do it

dense root
#

Oh I see....

#

SerializedField is super confusing to me, my bad 😓

rich adder
modern rune
#

Guys my first post here. I want to animate emission property in material over time.

Then duplicate the 3d model like 100 times and randomly on and off emission slowly.

How to do that.?

dense root
#

right right...

rich adder
#

if you were to reapply / right click reset the script you would see the changes

dense root
#

thank you @rich adder

rich adder
#

but you would have to plug everything back in

#

so its easier to use inspector and change the list there

dense root
#

even for like 100 words?

rich adder
#

I usually have an external CSV or JSON

dense root
#

well i just will manually input them since they're so few

rich adder
#

either way you're typing them manually then

dense root
#

right

rich adder
#

what you can do is write them inside another script and load that in

#

this way if you ever move the script you dont lose all the wrods from inspector list

#

but to be honest a CSV file would be so simple for this

dense root
#

i'll just tinker with it manually in the inspector for now, and when i need something more intricate i'll figure that out at a later time but this works great for now

#

oh

#

yeah i think so too

rich adder
#

eg
imagine a text file with

word1, word2, word3, word4 etc.

dense root
#

yeah

rich adder
#

you can tell unity to map that to the array

#

with 1 line of c#

dense root
#

right

rich adder
#

actually h/o

#

textasset is a good idea.

dense root
#

i'm wondering how this would work when i add images

#

for example i'm thinking something like this:

{
  Image.show("apple.png")
}

sorrry about the syntax

#

but you catch my drift

rich adder
#

just use Sprite references

#

btw you can try this script

#
public class CSVData
{
public static List<string> GetData(TextAsset textasset, string splitStr = ", ")
        {
            if (textasset == null)
            {
                throw new Exception("should pass textasset.");
            }
            List<string> data = new();
            StringReader reader = new(textasset.text);
            while (reader.Peek() != -1)
            {
                string line = reader.ReadLine();
                string[] items = line.Split(splitStr.ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);
                data.AddRange(items);
            }
            return data;
        }
}
swift crag
#

What is this data?

dense root
#

Let me show you in video

swift crag
#

Okay, so you want to associate an image with a string

rich adder
swift crag
#

And you want to have a big list of these

umbral pike
#

how do you fix vr Controllers when they have trails

swift crag
#

you're going to have to elaborate

swift crag
dense root
#

ohhh

rich adder
#

I'm thinking you can also have a JSON

dense root
#

that makes sense

swift crag
#

you'd have a file named Resources/Images/Apple.png, and then the correct string would be "Apple"

rich adder
#

map each word to specific image there

swift crag
#

If this is not possible (maybe you need many valid answers), you'll need to explicitly define which image goes with which string(s)

buoyant knot
#

!code

eternal falconBOT
swift crag
#

It might wind up looking like this

eager elm
swift crag
#
[System.Serializable]
public struct Question {
  public List<string> validAnswers;
  public Sprite image;
}

public class Quiz : MonoBehaviour {
  public List<Question> questions;
}
#

you would set this up in the inspector

rich adder
#

I would still make everything solidified with a file

fierce mortar
#

I want to move my character and do it with transform.Translate but i want it to do smooth and not in a teleport motion

rich adder
#

easily map the struct to a json file with all the answers + image file

swift crag
#

It could be more convenient to edit the data if it's in a separate file, yes

dense root
#

I'm going to go with the file method later

swift crag
#

in that case, you'd still use Resources to fetch the sprite

dense root
#

after I get this picture to switch based on the word MercyRez

swift crag
#

You just need to decide if the file name will match the correct answer

#

or if the file name will be specified separately

#

I'd do the latter if there were many valid answers for each image

#

although, I guess you could just say that the first answer is the name of the image

rich adder
dense root
#

correct lol

rich adder
#

or Contains or Regex

swift crag
#

so if "Apple" and "Red Apple" are both valid answers, the sprite asset would be Resources/Images/Apple.png

buoyant knot
#

Can I get a second opinion to see if what I'm doing is dumb? https://hatebin.com/ocmfkfsiqa
The idea is:

  1. PhysicsMover contains ContactManager.
  2. ContactState can have different derived types.
  3. PhysicsEngine needs to look into/modify ContactState in ContactManager
  4. Player/Enemy scripts may have additional needs to specifically read/write to a derived class (TState : ContactState) stored in ContactManager
rich adder
#

depends how strict your want match

gaunt ice
#

i will strongly suggest Trie, if you want to store many strings and string matching.....

swift crag
#

and you'd do Resources.Load<Sprite>("Images/" + quizItem.answers[0]); to fetch the sprite

rich adder
#

TIL

swift crag
#

you aren't scanning every single string your game could ask you about

#

you're picking a random quiz item and showing it

#

you already know the answer (or maybe answers)

rich adder
#

yeah this Trie seems better for something else

#

like boggle or something

#

maybe spell checks

dense root
#

I'm going to do it the caveman way for now and just use the inspector and check against the string manually lol

rich adder
#

do whatever is easier for you

#

at the end of the day its your project

#

you have to understand it to use it

swift crag
dense root
#

Yeah haha

swift crag
#

Possibly with just a string instead of a List<string> if you don't want multiple answers for a single image

rich adder
#

I would still suggest you put all the words in a CSV for now and use TextAsset type to read the values

dense root
#

I'm gonna go with the CSV later on

#

That makes the most sense to me right now

rich adder
#

I would still fix that god awful GameObject.Find

dense root
#

i should just leave it there to upset you

rich adder
orchid trout
#

Progress on this, I got it drawing lines to the spline but I am having issues getting it to not subdivide where its not neccessary to subdivide UnityChanThink

#

I am not sure how to code some kind of... deviation check? Where it can somehow tell if a given segment is straight or not?

#

In a perfect world it would just be able to compare vector3 directions, but floating point issues block that? Unless I can check if its within some kind of window threshold?

#

this is FAR beyond my ability as a developer though so I might be better off handing it off to someone who knows maths

buoyant knot
#

Could I get a second opinion on if this pattern is dumb?

    public abstract ContactState currentState { get; }
..........(more stuff).....
}

public sealed class ContactStateManager<TState> : ContactStateManager where TState : ContactState, new() {
    public TState currentDerived { get; private set; }
    public override ContactState currentState => currentDerived;
}```
#

I tried simplifying to make it less tl;dr

humble condor
#

in any case, ppl try to not use it 1_ahhhh

buoyant knot
#

GameObject.Find is such a noob trap

hardy quartz
#

I'm coding movement into my game but for some reason its giving me Error CS1022

#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class InputManager : MonoBehaviour
{
private PlayerInput playerInput;
private PlayerInput.OnFootActions onFoot;
// Start is called before the first frame update
void Awake()
{
playerInput = new PlayerInput();
onFoot - playerInput.OnFoot;
}

// Update is called once per frame
void Update()
{
    
}
private void OnEnable()
{
    onFoot.Enable();
}
private void OnDisable
{
    onFoot.Disable();
}

}

gaunt ice
#

!code

eternal falconBOT
gaunt ice
#

and your ide should highlight the line "onFoot-XXXX"

hardy quartz
#

alr thx

#

can you explain it a bit more, im kinda stupid

polar acorn
uncut dune
#

This is the functions Im using to make my player dash, but sometimes when Im next to a wall and dash i t doesnt trigger and my player noclips
any ideas to solve this?

hardy quartz
polar acorn
eternal falconBOT
solemn fractal
#

Can I have 2 OnTriggerEnter2D on the same script?

buoyant knot
#

no

#

you can have 2 different scripts with that method separately defined in them

#

but there is no reason you would ever want to define that method twice in one script

solemn fractal
#

well, as I am not being able to do what I want, I am attacking and trying all the sides possible. haha

buoyant knot
#

how you are choosing to do it is wrong

#

triggers only tell you if you are in an area, yes or no

solemn fractal
#

well probably. I might need to delete all and start from scratch

buoyant knot
#

collider mode colliders can tell you direction

#

you do not want 4 different trigger collider hitboxes

solemn fractal
#

yeah, I have already too much code at least for me.. but it seems what I want to do wont work the way I am doing and I will need to delete all and findout another way probably..

spark ravine
#

Why is the lerping not working? it just instantly rotates...

if (groundPlane.Raycast(cameraRay, out rayLength))
{
    Vector3 pointToLook = cameraRay.GetPoint(rayLength);

    lookRotation.x = Mathf.Lerp(transform.localPosition.x, pointToLook.x, rotationSpeed * Time.fixedDeltaTime);
    lookRotation.z = Mathf.Lerp(transform.localPosition.z, pointToLook.z, rotationSpeed * Time.fixedDeltaTime);

    transform.LookAt(new Vector3(lookRotation.x, transform.position.y, lookRotation.z));
}
buoyant knot
#

that isn't going to work

spark ravine
buoyant knot
#

you are using rotation based on the real distance between two points

#

so if you want to change the point you are looking at, points that are far away will lead to very slow movement, while points very close will have very fast movement

#

rotation speed should be based on angle, not distance

#

also, your transform.localPosition is the position where you exists locally in the reference frame of your parent

spark ravine
#

This is my whole code, my player should always look towards the mouse but just not instantly

Vector2 move = InputManagerScript.instance.Move;

Vector3 movement = new Vector3(move.x, 0, move.y) * speed;

currentMovement.x = Mathf.Lerp(currentMovement.x, move.x * speed, Time.fixedDeltaTime * animBlendSpeed);
currentMovement.y = Mathf.Lerp(currentMovement.y, move.y * speed, Time.fixedDeltaTime * animBlendSpeed);

rb.AddForce(movement, ForceMode.VelocityChange);
animator.SetFloat(xVelocityHash, currentMovement.x);
animator.SetFloat(yVelocityHash, currentMovement.y);

Ray cameraRay = Camera.main.ScreenPointToRay(InputManagerScript.instance.Mouse);
Plane groundPlane = new Plane(Vector3.up, Vector3.zero);
float rayLength;
if (groundPlane.Raycast(cameraRay, out rayLength))
{
    Vector3 pointToLook = cameraRay.GetPoint(rayLength);

    lookRotation.x = Mathf.Lerp(transform.localPosition.x, pointToLook.x, rotationSpeed * Time.fixedDeltaTime);
    lookRotation.z = Mathf.Lerp(transform.localPosition.z, pointToLook.z, rotationSpeed * Time.fixedDeltaTime);

    transform.LookAt(new Vector3(lookRotation.x, transform.position.y, lookRotation.z));
}
buoyant knot
#

well looking at it as a whole

#

still totally wrong

#

for the same reasons

spark ravine
#

I tried it with angle but it didnt work

buoyant knot
#

well this is incorrect

#

and needs to be done with angles

spark ravine
#

how would you go about it?

buoyant knot
#

also, you are moving the rigidbody with forces, while also moving the transform. that is bad juju because they will keep writing to each othr

#

and overwrite what they are doing

#

if you have a dynamic rigidbody that moves using forces, then you need to move it with forces

#

you can't just rotate the rigidbody to force it to a fixed rotation, while applying linear velocity in a given direction. That doesn't make sense

#

because if you rotate + move, and bump into something that gives you force, now the two requests are at odds with each other

#

if you want to handle this on a dynamic rigidbody, then you need to apply torque

spark ravine
#

ok

buoyant knot
#

do you understand why?

#

you can alternatively assign initial angular velocity directly

orchid trout
#

neck deep in distress over repeatedly failing to progress this :/
Im about ready to give up because Im just too inexperienced to solve this nontrivial problem

#

it doesnt handle corners, its still jagged as hell, its spawning 1000000s of game objects

#

really frustrating that shapes doesnt just natively support splines

buoyant knot
#

what are you trying to do?

#

are you just trying to draw a curve?

#

this should be handled using particle system

orchid trout
#

yes I am trying to render the spline to something visible

#

but why would I do that with a particle system of all things????

buoyant knot
#

dude are you making 1 gameobject per pixel?

#

i just don't understand why you'd have 10^6 gameobjects from 1 curve

#

this whole curve should only ever be made with 1 gameobject

frosty hound
#

You can consider using Unity's spline package which also has the built in component to extrude along it to create pipes.

dry tendon
#

heyy, does someone know if it's there an easy way to give to this the kind of curve that has the subway sourfes?

buoyant knot
#

I feel like this would be best done with renderer magic

#

you could make a curved world, but that would make all your math suck

buoyant knot
#

like, change how you render the scene

rich adder
#

I think unity has this shader in their runner demo

orchid trout
#

Animal Crossing does a similar curved world through shaders, you can find resources related to that googling

dry tendon
buoyant knot
#

did you figure out the splining thing?

rich adder
turbid barn
#

hey guys im new to unity and im having trouble with a task. im a student in game dev but our facilitator has abandonded the class and i have nobody else to really turn to. is anyone able to just shoot me some tips for something? i have to print a quizz question and the player must stand on a pressure plate to pick an answer, and the right answer will open the barrier to allow the player to move forward. any direct assistance would be grand but ill take anything i can get

dry tendon
dry tendon
rich adder
#

its all shader magic 🙂

dry tendon
#

then it redirects me to this page... that explain me how exactly works a shader

rich adder
#

so you can just port it over

dry tendon
#

oh

#

so do i better use the one that is on the sample project?

#

or i can first try that?

rich adder
#

URP ?

#

You should open the sample project in a new project, and look how their shader is being implemented and copy it over

dry tendon
#

anyone...

#

im not using urp

#

its just a deffault 3d core project..

#

is that a problem?

rich adder
#

the sample is URP So prob

#

this is the old

#

i think

dry tendon
#

ok, so i just copy the shader and i paste it into my project?

#

i have to see more less how it works... but that's my work

rich adder
#

maybe its simply applied to the camera

dry tendon
#

yeah, i'm gonna download the project

dry tendon
sharp wyvern
#

Just FYI: Usually, shader are assigned to "Materials". Materials in turn hold the various parameters used by the shader. Materials are applied to "Renderers" in your scene, like a mesh renderer. @dry tendon

merry spade
#

if I do: StopCoroutine(<coroutine>) the coroutine gets paused doesnt it. How do i restart the coroutine after stopping it?

rich adder
sharp wyvern
#

not paused- stopped. You can start it again with "StartCoroutine"

merry spade
#

but it doesnt start from the beginning

sharp wyvern
#

thats wierd- it really should. I'd double check that

north kiln
#

!code

eternal falconBOT
merry spade
#

sry misclicked

#

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

public class DeadTimerUIScript : MonoBehaviour
{
    [SerializeField] private Image reviveTimer;
    [SerializeField] private Button cancelButton;
    private float currTime;
    private IEnumerator timer;

    private void Start()
    {
        timer = Timer();
    }


    public IEnumerator Timer()
    {
        print("start");
        currTime = 1;
        reviveTimer.fillAmount = currTime;
        while (true)
        {
            currTime -= Time.deltaTime * 0.1f;
            reviveTimer.fillAmount = currTime;
            if (currTime <= 0f)
            {
                cancelButton.onClick.Invoke();
                print("Invoke");
                break;
            }
            yield return null;
        }
    }

    public void TimerStart()
    {
        StartCoroutine(timer);
    }

    public void TimerStop() 
    {
        StopCoroutine(timer);
    }

}
sharp wyvern
#

all good- go again

merry spade
#

"start" is only printed once

#

but its going on

sharp wyvern
#

do you see "invoke" more than once (per "start")?

merry spade
#

wait a sec

#
    public IEnumerator Timer()
    {
        print("start");
        currTime = 1;
        reviveTimer.fillAmount = currTime;
        while (true)
        {
            print("starting");
            currTime -= Time.deltaTime * 0.1f;
            reviveTimer.fillAmount = currTime;
            if (currTime <= 0f)
            {
                cancelButton.onClick.Invoke();
                print("Invoke");
                break;
            }
            yield return null;
        }
    }

I see "starting" multiple times

#

I added it

sharp wyvern
#

this implies you are starting the coroutine more than once. is that your goal?

eager elm
#

'starting' is in a loop

merry spade
#

yeah but i see starting after stopping and playing again

sharp wyvern
#

oops, ignore my last comment- mixed up "start" and "starting" rereading now

#

ok- so "starting" should appear multiple times. but I'd expect only one "invoke" per "start" is that the case?

merry spade
#

if i do startcoroutine it doesnt start from the beginning

#

only the first time

#

but im stopping it before invoking

#

and if i play again

#

I see "starting" but not "start"

polar acorn
#

Store the result of StartCoroutine in a variable, not the parameter

merry spade
#

i dont understand

#

ahh

#

i should use the datatype coroutine instead of IEnumerator

sharp wyvern
#

yes, and store the value returned from StartCoroutine in a memberVariable.

merry spade
#

why should i store that value its null

sharp wyvern
#

then pass THAT member to StopCporoutine

merry spade
#

ah you mean timer

#

whats a memberVariable?

sharp wyvern
#

Coroutine myCoroutine; <- just a variable in your class

merry spade
#
    private void Start()
    {
        timer = StartCoroutine(Timer());
    }
#

like this?

polar acorn
#

You'll want to store the result of StartCoroutine in a variable whenever you start it, then call StopCoroutine on that

sharp wyvern
#

``public void TimerStart()
{
myCouroutine=StartCoroutine(timer);
}

public void TimerStop() 
{
    StopCoroutine(myCouroutine);
}``
polar acorn
merry spade
#

ah now i understand

#

Thank you!

rich adder
#

shader 🪄

dry tendon
# rich adder

Oh you did it 😆 thank youuu, I'm currently not at home so I have not been able to do it yet hehe... Is the shader assigned to the material as @sharp wyvern said? (Thank you too

sharp wyvern
# rich adder

nice- how did you apply it to all the materials- or is this some kinda- post-process thing?

buoyant knot
#

is there a way for a class to make sure that all derived classes of it contain a constructor of a given set of arguments?

rich adder
#

its only 1 script on the camera

sharp wyvern
#

wait ... a script? not a shader?

rich adder
#

its a shader

#

its applied between rendering passes

sharp wyvern
#

ah, interesting.. I have an effect like this- but I needed to add it to ALL my shaders- I need to figure out how this works.

#

guess it'll depend on my render pipline eh?

sharp wyvern
#

awsome- think that's exactly wat I need- thanks bud

dry tendon
#

And do you think that will cause performance problems?

rich adder
#

like the article of the sample project explained this is actually a perfomance boost

dry tendon
#

Yeah, true...

rich adder
#

wow interesting way unity did states for game maner

#

✍️ 🗒️

#

🤔 nvm ig

supple pumice
rich adder
supple pumice
#

oh sry

#

and this is caused by the fact that I basically tell him
when it receives ox and oy it is still
if it is still do the idle animation
if x is 0 and y is 0 do the down idle animation

#

but I don't know how else can I do that

#

I am following a tutorial but I changed a bit the movement script because it wasn't what I needed

rich adder
supple pumice
#

wdym?

rich adder
#

only change it if you move

supple pumice
#

mh

#

hold on let me try

#

like a "last move" var?

rich adder
#

!code

eternal falconBOT
rich adder
#

use link

supple pumice
#

I still haven't added the second v2 variable, do you want it with the variable added or without?

rich adder
#

but yeah youd probably need 2 blend trees 1 for idle / 1 for movement

supple pumice
supple pumice
rich adder
#

in the idle version

supple pumice
#

so like adding a v2 for the last position and pass it to the blend tree

rich adder
#

just put your inputs in a v2

supple pumice
#

do you mean this by 2 different blend trees? sorry but I am new to game development

rich adder
#

change your movement to this ```cs

private Vector2 move;
private void Update()
{
move.x = Input.GetAxis("Horizontal");
move.y = Input.GetAxis("Vertical");

    if(move != Vector2.zero)
    {
        Debug.Log("Moving");
    }
}```
buoyant knot
#

is there a way to ensure that all classes that derrive from a given base class must implement a constructor with a certain set of arguments?

supple pumice
#

without last 2 lines sorry

rich adder
#

so easier to copy

#

also more concise

#

v2 is just two floats

supple pumice
#

and so also change every horizontal input and vertical input with move.x and move.y right?

rich adder
#

yea

eager elm
supple pumice
# rich adder yea

ok last question, how do I separately set idle tree's variables and moving tree's ones?

rich adder
#
if(move != Vector2.zero)
        {
            Debug.Log("Moving");
            lastDir = move;
        }
        else
        {
            anim.SetFloat("IdleX", lastDir.x);
            anim.SetFloat("IdleY", lastDir.y);
        }```
supple pumice
#

ohh ok

dry tendon
#

Or is more complex than i imagine...?

rich adder
#

but knowing shader code is the hard part

dry tendon
#

its no c#?

rich adder
#

no shader code is not c#

#

shaders talk to graphics

dry tendon
#

oof, ill need chat gpt XD

rich adder
dry tendon
#

could you pass me the code if its near you? Plss

rich adder
#

you need at very least the whole Shader folder + a couple of more scripts

dry tendon
#

oh, i'll dowload it then

#

🙂

short hazel
# buoyant knot i’ll try it out

Classes that derive from a class declaring one or more parameterized constructors will be forced to call one of the base constructors and pass the relevant arguments. You can use that at your advantage here, but know that if you're dealing with generics, you cannot constrain a generic type parameter to types that have a specific constructor signature.

#

where T : new(int, string) for example is unfortunately illegal. Only new() is allowed

buoyant knot
#

unfortunate

#

but I guess there is a decent workaround

#

ty SPR2

#

another question (lots of questions around the same topic today), I want to make an interface with a method that outputs a type that must derrive from a given type. Is there a clean way to implement this without just enforcing by assertions?

#

I am trying to make a generic ContactStateManager that lives on a monobehaviour, and stores info about grounding. The base class has basic info that only enemies need (touching floor/wall etc), but my player will need a derrived class that has all that plus more fields. Any my physicsMover class needs to know which derrived ContactStateManager it needs to make

short hazel
#

Generic interface with constrained type param, method returns that type param?

buoyant knot
#

yeah

#

my idea is public interface IContactStateReceiver, which only has a single function, void goes in, and out comes a type that must derrive from ContactManager, and be non-abstract

short hazel
#

Or if it's just one type, then make the method return the base type, base type that is abstract

buoyant knot
#

oh wait, were you asking a question or making a suggestion

short hazel
#

Suggestions, both messages

#
ContactManager GetManager(); // non-generic
T GetManager(); // interface IThing<T> where T : ContactManager
buoyant knot
#

I don't understand

#

it seems like the right tool, but I don't understand

#

you mean I make an interface which is generic, the generic has type constraints, and then I read out the type... how?

#

and interface is totally empty, right?

short hazel
#

The interface would have the GetManager() method, and the class would implement it as a closed generic ie. where you pass a concrete type to the type argument, like these

class Sample1 : IContactStateReceiver<string>
{
    // forces you to implement
    public string GetManager() => stuff
}

class Sample2 : IContactStateReceiver<GameObject>
{
    // forces you to implement
    public GameObject GetManager() => stuff
}

There's no type constraint shown here which means you can pass anything, but it's for the example, feel free to constrain it as you'd like

buoyant knot
#

I'm not sure this is quite what I'm looking for?

#

oh but I think I do need to implement it

#

this feels close, but not quite right

#

PhysicsMover has a ContactStateManager. PhysicsMover's Awake looks for GetComponent<IContactStateReceiver>, calls constructor to make one of the right type, then calls ConnectToManager so that the monobehaviour with the interface can be connected to the properly typed manager in the derrived type

#

that is the idea, at least

#

but I don't think my syntax is correct to make this happen

#

I think i need some conceptual help to figure out how covariance/contravariance works here

short hazel
#

Covariant is only for return types, and contravariant only for parameter types

#

And even if it works, then you'll have a variable of type IContactStateReceiver<ContactStateManager> which is not what you want, you need the concrete type right?

buoyant knot
#

I need both

#

I think I figured it out.

#
        public ContactStateManager MakeManager(); }```
#

ty for the ideas, SPR. You helped me through this a bit

#

still wish I understood <out T> better

simple viper
#

I'm currently working on a character movement script in Unity, following the movement lab tutorial by Dave. I'm encountering an issue with the movement speed. Specifically, the speed increases as expected, but it never decreases. I've been reviewing my script, and I suspect the problem might be in the section related to speed control or the coroutine for smoothly lerping the movement speed.

Here's an overview of the relevant areas of the script:

  • I have a SpeedControl method to limit the speed on different conditions (ground, slope, or air).
{
    // limiting speed on slope
    if (OnSlope() && !exitingSlope)
    {
        if (rb.velocity.magnitude > moveSpeed)
            rb.velocity = rb.velocity.normalized * moveSpeed;
    }

    Vector3 flatVel = new Vector3(rb.velocity.x, 0f, rb.velocity.z);

    //limit velocity if needed
    if (flatVel.magnitude > moveSpeed)
    {
        Vector3 limitedVel = flatVel.normalized * moveSpeed;
        rb.velocity = new Vector3(limitedVel.x, rb.velocity.y, limitedVel.z);
    }
}```

- There's a coroutine (SmoothlyLerpMoveSpeed) for smoothly lerping the movement speed, considering factors like slope angle.

```private IEnumerator SmoothlyLerpMoveSpeed()
{
    // smoothly lerp movementSpeed to desired value
    float time = 0;
    float difference = Mathf.Abs(desiredMoveSpeed - moveSpeed);
    float startValue = moveSpeed;

    while (time < difference)
    {
        moveSpeed = Mathf.Lerp(startValue, desiredMoveSpeed, time / difference);

        if (OnSlope())
        {
            float slopeAngle = Vector3.Angle(Vector3.up, slopeHit.normal);
            float slopeAngleIncrease = 1 + (slopeAngle / 90f);

            time += Time.deltaTime * speedIncreaseMultiplier * slopeIncreaseMultiplier * slopeAngleIncrease;
        }
        else
            time += Time.deltaTime * speedIncreaseMultiplier;

        yield return null;
    }

    moveSpeed = desiredMoveSpeed;
}```
#

I am absolutely at a loss though, I'm an artist covering for an absence in my allocated team, so I've hit a bit of a wall now I've encountered this issue

wintry quarry
#

Nor is it clear where things like desiredMoveSpeed are coming from

simple viper
#

Apologies, I'm a tad overwhelmed with script

wintry quarry
#

It would probably be better to just share the whole thing in a paste site

#

!code

eternal falconBOT
simple viper
#

There's my main movement script and the sliding script that is referenced

wintry quarry
#

This seems wrong, line 149: desiredMoveSpeed = moveSpeed;

#

Isn't moveSpeed the thing you're changing all the time?

#

you need to have a separate variable for currentMoveSpeed vs normalMoveSpeed

#

normalMoveSpeed should NEVER change

#

so that you can do desiredMoveSpeed = normalMoveSPeed; when needed

#

make sense?

#

I would also make currentMoveSpeed or whatever you want to call it be private / not serialized

simple viper
#

Makes sense yes

#

however, the tutorial I'm following didn't have the currentMoveSpeed

#

not doubting your judgement, I can link his script if you'd like?

wintry quarry
#

sure - you might have missed something there

#

or his script might just not be that good

simple viper
wintry quarry
#

yeah so he has

#

private float moveSpeed; which is the equivalent of what I was calling currentMoveSpeed

#

he then has

    public float walkSpeed;
    public float sprintSpeed;
    public float slideSpeed;```
#

and walkSpeed is probably the equivalent of what I was calling normalMoveSpeed;

#

notice that his moveSpeed is private

#

and not something you can see in the inspector

#

so yes he's doing exactly what I described, just with different names

simple viper
#

Ah okay, I'll implement this now

wintry quarry
#

And notice on line 156 in his script:

            state = MovementState.walking;
            desiredMoveSpeed = walkSpeed;```
#

He's not doing desiredMoveSpeed = moveSpeed; he's doing = walkSpeed;

#

that's the main difference

simple viper
#

I see

#

Thank you for the quick and informative response

#

Been stuck with this a couple hours, everythings turning to mush

sage mirage
#

Hey, guys! How to make master volume on my game? I mean for both background musics and sound effects for every sound element with a few words?

simple viper
#

I've applied the change via adding walkspeed and now my player is unable to move

#

being an idiot

#

didn't set the variable

#

Ok I'm at a point where I'm very happy with the script and am now tweaking some movement "issues"

#

So my script uses vertical and horizontal to determine which way the player is moving. When I'm in the air it currently feels very weird as the speed stays the same whilst moving forward and back. How would I go about making the speed decrease when moving forward in the air and holding back?

modest barn
#

Hi! Is this where I can ask for help or should I create a thread?

eternal needle
round arch
#

woops, sorry bout that

eternal needle
north scroll
#
private void OnMovement(InputValue input)
{
    //•    Your character must support pressing down to crouch and must slow his horizontal movement or allow the character to "roll" left and right
    if (isCrouching)
    {
        //rb.velocity = input.Get<Vector2>() * crouchSpeed;
        Vector3 movement = new Vector3(input.Get<Vector2>().x, 0f, input.Get<Vector2>().y);
        rb.velocity = movement * crouchSpeed;
    }
    else
    {
        Vector3 movement = new Vector3(input.Get<Vector2>().x, 0f, input.Get<Vector2>().y);
        rb.velocity = movement * walkSpeed;
    }

Hai this is my current code for a movement system, and currently for keyboard, I can't just contiously move my player by holding my a or d key for a 2d side scroller im working on for school. Ive been looking into it a lot, rewriting different things, and Ive come to the conclusion that I think I need to change my player input behavior from send messages to invoke unity events instead. Is this true or is there a way to be able to do this with just send messages? I'd rather keep it with send messages instead cuz the calback context function parameter kinda confuses me and id rather not mess with it but yea...

#

oh yeah, i have to repeatedly press those keys for the player to keep moving, forgot to mention that

summer stump
north scroll
#

so unless its context.performed (i.e. invoke unity events), id have to do movement like this on fixedUpdate? or update ?

twin bolt
#

I'm having issues with raycasts, when my main camera is disabled, because i'm using Camera.main, so i want to change to Camera.current, but the issue is that i have over 20 scripts doing this, how can i change them all at once?

summer stump
small dagger
#

Is there a way to check why a gameobject is destroyed? I am having an issue with an object being destroyed when it connects to a host as a client and I am trying to find out why it gets destroyed

north scroll
#

ok so movement has to be in an update regardless. Makes sense, I just thought there'd be another way as it seems checking for input every frame or wtever would be inefficient

#

why FixedUpdate? What would the different be if putting it in update instead ? @summer stump

summer stump
summer stump
north scroll
#

thx bby

sand mesa
#

yooo I decided to learn c# anyone know the correct path

#

I want to learn it to start making games using unity

#

because I got tons of game ideas

#

I'm like oda but the game developer version

north scroll
#

https://www.youtube.com/watch?v=GhQdlIFylQ8&pp=ygUQbGVhcm5pbmcgYyBzaGFycA%3D%3D

https://www.youtube.com/watch?v=AmGSEH7QcDg&t=1074s&pp=ygUabGVhcm5pbmcgYyBzaGFycCBmb3IgdW5pdHk%3D

I feel like these 2 would be a good start, channels I think are usually reliable. Its a lot yes, but you are learning unity after all hah

This course will give you a full introduction into all of the core concepts in C# (aka C Sharp). Follow along with the course and you'll be a C# programmer in no time!

⭐️ Contents ⭐️
⌨️ (0:00:00) Introduction
⌨️ (0:01:18) Installation & Setup
⌨️ (0:05:03) Drawing a Shape
⌨️ (0:17:23) Variables
⌨️ (0:30:06) Data Types
⌨️ (0:37:17) Working With S...

▶ Play video

💬 This was a ton of work to make so I really hope it helps you in your game dev journey! Hit the Like button!
🌍 Course Website with Downloadable Assets, FAQ, Related Videos https://cmonkey.co/freecourse
❤ Follow-up FREE Complete Multiplayer Course https://www.youtube.com/watch?v=7glCsF9fv3s
🎮 Play the game on Steam! https://cmonkey.co/kitchencha...

▶ Play video
sand mesa
#

btw thanks for starting my journey

eternal falconBOT
#

:teacher: Unity Learn ↗

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

gray bough
#

Hi! I'm trying to get some text to update when a gameobject with a certain tag is clicked on. I have the portion of the script working where the player can click the object and it disappears (the name of the object is also displayed in the console) but I can't seem to figure out why the int variable for my money text isnt updating. If someone could please look over my scripts real quick that would be great

halcyon osprey
#

Can anyone tell me why the tilemap stutters like this? All code runs smoothly, I think I just did something wrong with the tilemap itself

#

Crap the video is compressed a tad so it's slightly harder to see, but there are lines on the grid now and then

wintry quarry
halcyon osprey
#

Pixel perfect camera?

Nvm, found it :D

summer stump
#

Oh, is the PlayerMoney script on the cam object? Maybe show that inspector instead
Either way though, you don't want to just do GetComponent every time, get it once in start

sand mesa
#

could you give me the download link of visual studio I deleted it to reinstall it idk why I did that dont ask me

#

alright chill

#

chillllll

#

what I wanted to say is I use mac is it oke if I downloaded the windows version because it is good for .net

slender nymph
#

if you're using macOS you need to download the version for macOS. why would you think the windows version would work?

sand mesa
#

because I'm dumb

#

I ask stupid questions

#

btw should I get the copilot too?

lime cove
#

Hey! I am trying to make an upgrade list, but I am unable to figure out how to make the positioning of the list dynamic (ex: when upgrade 1 is bought, upgrade 2 moves to the position of upgrade 1 as its removed from the list); What is the best way to approach this

slender nymph
#

what have you got so far?

lime cove
#

I got the individual upgrades D: Just no clue how to make them a list of sorts (something like html unordered list)

slender nymph
lime cove
#

visually, I can store the upgrades in an array I just dont know what is the best way to approach it other than manually saying stuff like move it 200 pixels above

cunning heath
#

https://docs.huihoo.com/unity/5.5/Documentation/ScriptReference/Texture2D.LoadImage.html
In this link under the code description a byte array is loaded as a texture into a Texture2D object. But it's supposed to be a 64*64 image. However there is nowhere this is specified so how does the Texture2D understand the image dimensions.

I also have this problem when trying to get the pixel data from an image as a matrix but all member functions give a 1 dimensional array instead of a 2d structure. So I am quite confused.

sand mesa
#

anyone know a c# lesson but for mac because I'm struggling learning windows version

slender nymph
#

c# works the same no matter what OS you are using

sand mesa
#

when he opens it he could press new file and pick whatever I cant

slender nymph
#

perhaps a computer literacy course should be your starting point

sand mesa
#

no no fr

cunning heath
# sand mesa no no fr

C# is a programming language. Its like English its the same both in your country and outside

sand mesa
#

how do I pick console app like that guy picked

slender nymph
#

you do realize that google exists, right?

polar acorn
sand mesa
#

chill I just started no need for all that

slender nymph
sand mesa
slender nymph
#

sure jan

sand mesa
#

wait idk what level are you

real falcon
#

is there an easy way to make it so that when an animation transitions, it doesn't reset? basically I have a state that plays an animation (crosshair contracting) and one thats just that one but reversed. and I want it to not "jump" if that makes sense

slender nymph
real falcon
#

ok

sand mesa
#

wait did visual studio for mac retire?

#

I see that all over youtube

frosty hound
#

It is ya

slender nymph
#

it's just visual studio now, isn't it?

sand mesa
#

rip visual studio for mac

slender nymph
#

do note that it does not mean there is not a visual studio version for macOS. it's just visual studio now instead of the rebranded xamarin studio that was called "visual studio for mac"

lime cove
#

another problem I have, I initalise a prefab (an empty object with a button and text), I set the parent to my canvas , but for some reason the button is uninteractive, it doesnt even highlight

slender nymph
#

do you have an EventSystem in your scene?

lime cove
#

yes, I figured it out, appereantly an invisible part of my text was catching my clicks

#

thanks anyways 😄

sand mesa
#

I'm downloading a version that says retiring at 2024 might be a virus but who cares

#

looks safe for me tho

frosty hound
#

Obviously downloading from a valid source or Unity Hub wouldn't result in a virus.

sand mesa
#

dude I wanted some action why did you say

#

noooooo

#

bro I'm getting excited what should I code

#

I will be moving my fingers all over the keyboard hehe

dense root
#

I guess succintly my question is how do I set the image based on the currentWord?

wintry quarry
#

Second step is to fix your compile errors

#

!ide

eternal falconBOT
dense root
#

what's wrong with my ide?

wintry quarry
#

It's not configured

#

and isn't showing you compile errors

wintry quarry
#

It will highlight this error for you in the code when it's set up properly

#

you will also get proper syntax highlighting and autocomplete

dense root
#

Okay i'll do that, but how do I set the image to the file I desire?

wintry quarry
#

what you have right now is oldImage = "some string"; which doesn't make any sense at all and is a compile error

dense root
#

Shoot I accidentally removed my visual studio package

#

Does anyone know how to reinstall the Visual Studio Editor package?

wintry quarry
# dense root

switch to the unity registry and install the package you want

#

you're looking at only the packages in the project already here

dense root
#

Oh awesome thank you

#

Hmm so a fresh install of the package didn't do the trick, still not showing syntax errors

eternal falconBOT
delicate river
#

might be really dumb mistake but i made an effect thats meant to take 4 seconds (now 6), however the effect itself takes like 2 seconds? not sure why

dense root
#

I followed those steps, no dice

wintry quarry
wintry quarry
#

skip nothing

delicate river
#

oh shi i didnt notice that thanks

wintry quarry
#

otherwise the visual studio package itself can't compile

delicate river
#

should fix it right

wintry quarry
#

maybe?

#

IDK the context of this code really

dense root
#

So how do I set the image?

#

Nevermind I think I got this

dense root
rich adder
dense root
#

wdym

#

ohhh

#

where's a better place to put it?

rich adder
#

Huh? got rid of the event ?

dense root
rich adder
#

Literally wasted an hour making that event yesterday only for you not to use lol

dense root
#

wdym not using it?

#

i thought i am lol

#

that's how it's able to get the currentWord

rich adder
#

Huh ? because you put a reference back

#

Anyway what you’re doing is cumbersome, you would have a giant ass if statement block

#

Use a dictionary

dense root
#

wait how do i go about using the event?

rich adder
#

Wdym ? We did it yesterday lol

#

Wasn’t your code Like this ?

#

It would go inside receiveString

dense root
#

oh

#

how does receiveString know when it's being called?

rich adder
#

Because yesterday you plugged it into the Unity Event ?

dense root
#

ohhhh...

sharp phoenix
#

Just a question, if I create a Dropdown button, is its type "Dropdown"? As I tried to create a SerializeField in a script where I want to access my Dropdown's values but I can't link it to it and it doesn't find it when I use FindObjectOfType<Dropdown>()

wintry quarry
#

since TextMeshPro is used by default

sharp phoenix
#

Ohhh okay, thank you ^^

solemn fractal
#

hey guys I have an object on my scene that is not a prefab he is always there called SpawnManager. I manage to make SetActive to False but to make it true never works, any ideas? I do like that for true and false. cs _spawnManager.gameObject.SetActive(true);

wintry quarry
#

for example if this code is on a script attached to the deactivated object, it's likely the Update for that script isn't running anymore

solemn fractal
#

I used a debug,log and it is going inside the IF i created that contains only this line

solemn fractal
#

no to activate it back is on the player that is always active

wintry quarry
#
  • SHow the code
  • Show the console when you run it
  • Show which object(s) are assigned to the thing
elfin eagle
#

Im trying to add footsteps into my game. I'm using .playoneshot how can I make it that it plays on loop and does not repeat the same clip? or is there a different method I can use to do this?

wintry quarry
elfin eagle
#

oh yeah actually thats true

wintry quarry
#

you need to add Debug.Log to see if/when various bits of code are running

solemn fractal
solemn fractal
#

Ho ho ho. My bad

verbal dome
#

There's also an overload that lets you find inactive objects it seems ^

solemn fractal
#

yeah I should check first documentation before coming here

#

thank you !!

#

Ok I have another problem now, when I deactivate the object from the hierarchy SpawnManager, it works and the enemies stop spawning. But when I turn it Active again, nothing happens and its like the code inside of it doesnt run and the enemies dont start to spawn again. Am I missing some steps here after activating it in order for the script to start working again?

solemn fractal
#

!code

eternal falconBOT
solemn fractal
#

And it gets active again here in the finalBoss script when it dies. ```cs
public void TakeDamage(float damage){

    _finalBOCurrentHealth -= damage;

    if (_finalBOCurrentHealth <= 0){

        _camera.Follow = _player.transform;

        Instantiate(_skillbounce, new Vector3(transform.position.x, transform.position.y, 0), Quaternion.identity);
        _spawnManager.gameObject.SetActive(true);
        Destroy(this.gameObject);
  
    }

} ```
rich adder
#

you dont restart coroutine again do you

solemn fractal
verbal dome
#

Most likely an issue with the coroutines, yeah.

solemn fractal
verbal dome
#

Start will not get called when you make it active again

#

You could try OnEnable instead of Start

solemn fractal
#

ok, thank you!

#

Also the coroutines are being controlled in the Update, so every frame it should do it, it is not inside the Start

solemn fractal
willow nexus
timber tide
#

I'd just make the active element the most centered of all other elements by just using the screen width probably

waxen adder
#

I want to do some procedural dungeon generation. I got something to work last year with rooms connected by hallways using pathfinding. Now, I kind of just want to have some connected rooms. A lot like the binding of isaac, but with the option of being able to change elevation. Anyone have any good resources to get started?

timber tide
#

You can probably look into using 3D arrays to structure it all

waxen adder
#

And this would be to make a 3d grid to spawn rooms?

timber tide
#

Yeah, you'd have another dimension for some elevation. Isaac probably just uses a 2D array anyway considering how static the bounds are for each level.

waxen adder
#

Yeah, iirc they use a 13x13 grid

#

Source: too many hours playing the game

timber tide
#

with 3D you can have a 13x13x2 ;)

#

rather 13x2x13 depending if you want to view it as x,y,z

waxen adder
#

True. Something I've always wondered is how they handled new room sizes. Like, it makes sense to me how a single 1x1 room fits onto a grid, but a 2x2 for some reason gives my brain a stroke

timber tide
#

Ah, yea that's some extra logic overall, but you can keep it simple and just make a single index any size room

#

like zelda (well, older zeldas)

waxen adder
#

Hmmm. What would happen if the game wants to spawn a room that has a valid grid location but not a valid size (i.e. they would overlap)?

#

Just redo it and try again?

#

Oh and how would I detect that?

timber tide
#

You'd confirm before placing anything

verbal dome
timber tide
#

Can it build a 3x3 room, no? Next,
Can it build a 2x2 room, no? Next

#

many ways to do it

verbal dome
#

Though you want to design the algorithm so that you have to do as few retries as possible

waxen adder
#

Gotcha

#

I think the main thing to do rn, is getting the grid set up and be able to spawn 1x1s

verbal dome
#

Yep, start simple

waxen adder
#

Already enough of a hurdle to do that

verbal dome
#

@waxen adder When searching for resources for proc gen, a good keyword is Roguelike since in that genre maps are usually generated procedurally

waxen adder
#

Here in the discord or on google?

verbal dome
#

Google

waxen adder
#

Gotcha

slender nymph
#

spell it correctly

uncut crypt
#

which part

#

im gonna kms

#

thank you

slender nymph
#

make sure that your !IDE is configured so that it provides intellisense and auto complete so you don't make spelling mistakes like this in the future

eternal falconBOT
copper perch
#

on the look pad on call of duty mobile when you hold, and swipe left you seem to look halfway of 180 degrees.
On my game with the unity starter assets fps controller with the floating joystick when I hold it left the player constantly goes around and around in circles.
I would like my look pad floating joystick to be like the look pad on call of duty mobile.
What settings in the unity starter assets fps controller should I adjust for the floating joystick to stop moving around and around in circles?

tawdry mirage
#
public GameObject selectedMarker;```
is it ok? does it have specific name?
wintry quarry
tawdry mirage
verbal dome
#

[field: SerializeField] public GameObject selectMarker { get; private set; }

tawdry mirage
#

i did something like public GameObject GetSelectedMarker { return selectMarker; }
but i think there is something better?

wintry quarry
#

there isn't anything "better" really, no

#

Osmal's example above is more concise

#

but effectively the same

gaunt ice
#

Google c# get setter, though someone has provided an example for you

wintry quarry
#

C# properties*

tawdry mirage
verbal dome
#

I think [field: SerializeField, HideInInspector]
Actually I think [field: HideInInspector] is enough

wintry quarry
#

jsut don't serialize in the first place

#
public GameObject SelectMarker { get; private set; }```
#

it all depends on what you want to do

tawdry mirage
verbal dome
#

We don't know what you wanted 😄

verbal dome
tawdry mirage
#

i need to be able to set it in editor, access but not set it from other classes

verbal dome
#

It uses a backing field

wintry quarry
wintry quarry
#

And you could have asked for that in the first place

tawdry mirage
tawdry mirage
#

i thought [field: SerializeField] is same as [SerializeField]

wintry quarry
#

they are different because they are different

verbal dome
#

Basically an invisible variable that holds the actual data

tawdry mirage
modest barn
#

Not sure where I should be asking this, but here I am. I'm creating a Unity app for the first time and I'm using GitHub for all my work (though that shouldn't be relevant here, I think). I've got the project created and have done a bunch of scripting and asset preparation but the Heirarchy is still just the default, new-project one. However I'm now adding a canvas for UI and it's asking me to save a file with type unity when I try and save the project. My question: where is it standard to store this file? Is this not the project file? If it is, how do I not already have a project file if I've been using the project window this whole time? Essentially I'm just asking whether it's standard to save this file in Assets, or Library, or any subfolders of these. TIA!

gaunt ice
#

Github desktop can generate a .gitignore of unity for you, the .git folder and the gitignore should be placed on root folder ie path/Your project/

waxen adder
#

What packages do people use from the package manager if they want to add textures to an in progress project. So, something like ProBuilder?

modest barn
#

But I don't know where to save my Unity project file

#

And whether it matters

dense root
gaunt ice
#

The .unity package file? It is created based on the assets of your project so you need to keep track of all asset and library and other packages

modest barn
#

In the folders like Assets and Library or where?

#

@gaunt ice where do you save yours?

gaunt ice
#

The packages should be exported to somewhere in your pc so idk

#

Or internet

dense root
#

Is it possible to change keyboard input language programmatically? Or is this something that can only be set by the user

modest barn
waxen adder
#

Erm, where's ProGrids in the package manager? I have the manager searching the unity registry with "enable pre-releases" on in project settings and can't find it

gaunt ice
#

Oh i misunderstood, .unity file is not .unitypacket, mb

#

But I remember the extension of scene file is .scene
btw i think the editor is asking you to save the modified scene, it should be placed on some subfolders under Assets

modest barn
#

Awesome, thank you

modest barn
#

Can someone help me really quickly with Buttons from TMP? I'm not understanding the On Click() method

#

How do I change what it does?

#

I can see that I can add Runtimes, but what are they?

#

Are they just functions that I can add? If so, how do I add those functions from a script?

gaunt ice
#

Addlistener

modest barn
#

What's that?

grizzled ermine
gaunt ice
#

Onclick is not a method, it is unityevent

modest barn
#

Ahh that makes sense with the vocabulary

#

How do I add to the List then?

#

How does this work?

timber tide
ivory bobcat
modest barn
modest barn
ivory bobcat
modest barn
ivory bobcat
modest barn
#

Ah right ok perfect thank you

#

Probably should've tried that instead of bothering you guys haha

timber tide
#

It needs to be an active instance or prefab usually

modest barn
#

Sorry, I'm not sure what that is.

#

An active instance?

timber tide
#

Meaning that there's an instance of it created already so you can bind a reference to it

#

anything on the scene is instantiated as a new instance

modest barn
#

What am I doing wrong here? I have a public void Test() in there

#

It should be a C# script I'm dragging in there, right?

#

How do I create a GameObject that is an instance of a script? Can you do that?

timber tide
#

make a gameobject on the scene and add the script to it

#

then drag that gameobject onto it

modest barn
#

It's already added to the button itself

#

Does it just have to be an empty gameobject?

#

Well that worked I suppose

#

Seems to be a really roundabout way of doing it

#

Is this bad practice?

#

To have the script coming from a component on the same object

timber tide
#

that's the idea

#

you could put* it on the button too that's fine

gaunt ice
#

I havent tried drag a script from folder to it indeed, it is just a text file in disk not instance in ram

modest barn
naive lion
#

Why exactly are public methods ‘bad’? Is it purely data encapsulation?

wintry quarry
#

Who said that?

#

Do you mean public fields?

#

If so yes it's for encapsulation

naive lion
#

sorry fields **

modest barn
#

Can I access a variable from another class, let's say string s = MyClass.str without putting this?

using MyClass;
wintry quarry
#

using is for namespaces, not class names

modest barn
#

Sorry it's another script

#

I confuse the two

gaunt ice
#

Using static Myclass; if myclass is static class

wintry quarry
modest barn
#

So other scripts are namespaces, correct?

gaunt ice
#

No

modest barn
#

If I say using MyScript;, MyScript isn't a namespace?

wintry quarry
#

MyScript is only a namespace if it's a namespace

#

Terrible name for one by the way

acoustic berry
#

Hello, I've just started to learn Unity and i've run into an issue where my button can't find the method I want it to find. I have the script (SkillMaster) attached to an object (SkillHolder) and then dragged that GameObject into the button's OnClick() field. While the script shows up in the dropdown list, the desired function gainXP does not show up. Can you see anything wrong here?

wintry quarry
modest barn
# wintry quarry MyScript is only a namespace if it's a namespace

@wintry quarry I'm new to C# and in general unclear on what a namespace actually is. A quick Google search leaves that very vague. For my understanding, if I create a script PlayerMovement, and in my other script, UserInput I put

using PlayerMovement;

At the top, does that then make PlayerMovement a namespace, as only namespaces can have the using keyword?

acoustic berry
#

oh, I see I have a type cast issue

modest barn
#

It's worked for me before

acoustic berry
#

I had errors that were being buried underneath warnings of unused values

wintry quarry
#

You can put classes inside the namespace

modest barn
#

I have never done that before

wintry quarry
#

The example you showed has never worked

#

You must be misremembering

modest barn
wintry quarry
modest barn
#

Or is that using statement utterly useless

wintry quarry
modest barn
#

Yeah gimme two secs i'll go delete it and see if it still works

wintry quarry
modest barn
#

Never mind, I was doing

Decoders decoder = new Decoders();
ListConstants listConstants = new ListConstants();

So I thought that I had to have

using Decoders;
using ListConstants;

Where Decoders.cs and ListConstants.cs are my scripts.
At the top but I did not. That's my bad. I suppose that's the whole point of public

wintry quarry
#

Indeed you do not need that and writing that would be an error

#

Because using directives don't work with classes

modest barn
#

Compiling error or just a bad thing to do?

wintry quarry
#

Compile error

modest barn
wintry quarry
#

Did you save your code

modest barn
#

Yep

#

I've had it for weeks now

#

I'll show you the code

#

Wait

#

I was doing

using static Decoders;
wintry quarry
#

Yes

#

That's totally different

modest barn
#

Ok

#

I'm so dumb

wintry quarry
#

That lets you use static members from that class without writing the class name in front

modest barn
#

Sorry for wasting your time 😅 still trying to wrap my head around all this

modest barn
wintry quarry
#

For example the full class name for GameObject is UnityEngine.GameObject

#

You can even write that everywhere

#

But it gets tedious

#

using UnityEngine; lets you skip the UnityEngine part and just write GameObject

modest barn
#

So you would say

using UnityEngine;
#

Ok

#

Cool I get it now

#

That's like python

wintry quarry
#

Yes quite similar

modest barn
#

C# is so much more confusing but you get so much more control than python

#

I'm starting to like it

little mural
#

what are the ways of stopping a while loop in a coroutine?
does the function StopCoroutine() count?

little mural
# spare mountain break..?

so to clarify,
if I were to use the StopCoroutine() function, the while loop wouldn't stop as long as the while loop parameter is true, right?

#

I would have to use break, a boolean, or a goto to stop it, but not StopCoroutine()?

keen dew
#

If you have a yield inside the loop then StopCoroutine stops the coroutine as usual

naive lion
#

You said the loop is within the coroutine correct?

little mural
#

yes

naive lion
#

i may be wrong but stopcoroutine should work

burnt vapor
#

So the main question is probably when should the while loop stop?

naive lion
#

Agreed ^

modest barn
#

Does anyone know if TextMeshPro's Input Field has a similar property to its legacy counterpart where it can change the CharacterValidation to Integer, for example?

graceful flicker
#

Do I have to keep every SO type in a separate file? Because when I rename something which is not "Item" it loses a script reference in the inspector

#

Like that

burnt vapor
#

In Unity, most of the times you are required to do this because even Unity expects only a single responsibility per file

graceful flicker
#

SRP? You sure we are talking about the same thing?

crude prawn
#

im trying to use the new input system for player rotation but it isnt quite working

#

on mousePos i used Input.mousePosition before input

#

and it stopped working

#

when i used input

burnt vapor
#

The whole point of SRP is to only have a single responsibility per file, which is exactly what Unity is expecting too

tawdry nymph
#

why is unity saying "Cannot implicitly convert type float to bool" in the if statement?

private float Rotation;
enum Directions
{
  Down = 0,
  Right = 90,
  Left = -90,
  Up1 = 180,
  Up2 = -180
}

Update()
{
  rotation = player.transform.rotation.z
  if(Rotation = (int)Directions.Down)
  {

  }
}```
twilit pilot
tawdry nymph
#

oh sorry i totally missed that

gaunt ice
#

enum is always int by default so you dont need to cast it

eager elm
#

you probably want eulerAngles.z tho

twilit pilot
tawdry nymph
eager elm
tawdry nymph
#

but when i remove it it gives the error "Operator '==' cannot be applied ot type float and Abilitys.Directions"

gaunt ice
#

oh i know why, you have still have to explicitly cast the enum to float or int for safety concerns, my bad

tawdry nymph
#

is there any advantage in casting it to float since im comparing it to a float?

gaunt ice
#

int can be implicitly cast to float so i guess no
using == to compare two float is bad but idk how to rotate the player so in your case it may work

keen dew
#

It's a bad idea to read the rotation from the transform in the first place. The enum should be in a script on the player and the rotation should be set based on the enum, not the other way around

crude prawn
#

this is what it gives me

#

ok on controller it barely works when i let go of the right stick it resets the rotation

#

and on mouse it doesnt even work

rare basin
#

so I have a ScriptableObject, with two dictionaries. I want to fill the second Dictionary based on the first one, and set the SO as Dirty, can I somehow do it like OnValidate or do i need to make this in mono behaviour?

[CreateAssetMenu(fileName = "Enemy Level Data", menuName = "Level Data/Enemy Level Data")]
public class EnemyLevelData : ScriptableObject
{
    public GenericDictionary<ObjectType, UnitData> enemyLevelUnits;

    [Header("Units AI Group")]
    public GenericDictionary<UnitGroup, List<ObjectType>> groupsOnLevel = new GenericDictionary<UnitGroup, List<ObjectType>>();

    public void InitAIGroups()
    {
        groupsOnLevel.Clear();

        foreach (var unit in enemyLevelUnits)
        {
            var unitGroup = unit.Value.unitGroup;

            if (!groupsOnLevel.ContainsKey(unitGroup))
            {
                groupsOnLevel.Add(unitGroup, new List<ObjectType>());
                groupsOnLevel[unitGroup].Add(unit.Value.objectType);
                SetDirty();
            }
        }
    }
}
#

I guess i can just do

public class EnemyLevelDataGroupFiller : MonoBehaviour
{
    public List<EnemyLevelData> datas;

    void Start()
    {
        foreach(var data in datas)
        {
            data.InitAIGroups();
        }
    }
}

and run it once, then delete the GameObject

twilit pilot
ivory bobcat
rare basin
#

i totally forgot about it

#

thank you

tawdry nymph
gaunt ice
#

have you logged the string?

crude prawn
#

can i randomize so something is either vector2.left up, right or down?

#

tryna spawn in enemies

tawdry nymph
pearl flower
#

How to make car not been pushed by the player, but at the same time be able to move.

#

I don't understand.

patent compass
pearl flower
#

What about collider of car?

#

It has frame, body that has collider.

#

@patent compass.

gaunt ice
patent compass
pearl flower
#

It has, but frame of car.

#

Due to the frame, car can be pushed.

#

Because frame/body of car also have collider.

#

@patent compass
Or you mean that each wheel has rigidbody.

#

But car itself (not wheels) doesn't have rigidbody.

eager elm
gaunt ice
tawdry nymph
gaunt ice
#

idk how quaternion math works, you may search it online but unity implements it in a slightly different way iirc

tawdry nymph
#

oh, do you know any other way to check if it matches the rotation?

rare basin
#

@tawdry nymph what do you want to achieve? sorry just jumped in

#

you want to read the value of the rotation x,y,z from the inspector of a transform component?

tawdry nymph
#

i want the string SelectedAbility to change when i rotate my player

#

its 2D btw

rare basin
#

why would you store an ability in a string

#

you should have separate class for your abilities

#

anyway, just check the player's rotation