#💻┃code-beginner

1 messages · Page 189 of 1

wintry quarry
#

A float would be just fine if you need to just store one value

vale karma
#

bc i needed it to make a quaternion 😮

#

im sure there are plenty more things in there that arent even needed, ill get to them soon

wintry quarry
#

Quaternion.Euler(0, yRotation, 0)

vale karma
#

yea i guess your right haha, i think i did that bc last time i got in a kerfuffle for doing math inside a MoveRotate() method with a quaternion

#

its not related but i miss on my part

viral tulip
#

so my intellisense stopped working, how do I get it back?

teal viper
#

!ide

eternal falconBOT
broken drift
#

does anyone know why my "if (Input.GetKeyDown(KeyCode.Space))" inside "playersCombat()" method only works once?

teal viper
broken drift
# teal viper Is the object getting disabled/deactivated perhaps?

i dont know but i didnt put any condition to disable it yet.
this in the entire code:
`using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class playerCombat : MonoBehaviour
{
[SerializeField] bunnyStatScripts _bunnyStats;
[SerializeField] GameObject _gameOverScene;
[SerializeField] int _damage;
int _newHealth;

void takeDamage()
{
    int _newHP = _bunnyStats._health - _damage;
    _newHealth = _newHP;
   
    if (_newHP == 0)
    {
        _gameOverScene.SetActive(true);
    }

}

void playersCombat()
{
    if (Input.GetKeyDown(KeyCode.Space))
    {
        takeDamage();
        Debug.Log("you pressed space");
        Debug.Log("HP: " + _newHealth);
    }
}

void Start()
{
    _gameOverScene.SetActive(false);
    Debug.Log("HP: " + _bunnyStats._health);
}

void Update()
{
    playersCombat();       
}

}`

gaunt ice
#

check if the method is running

broken drift
#

which method? playersCombat()? if so, then it runs but only once

gaunt ice
#

yes, or update, since your update will call that method

#

you can log in ondisable to find out the one that disables your object

teal viper
broken drift
gaunt ice
#

are there any error

broken drift
#

no errors

#

just nothing happens anymore after pressing space once

gaunt ice
#
void Update(){
  log i am called
}
#

or use debugger to check if it is called

broken drift
#

i used debug.log and yea it only shows once

gaunt ice
#
public void method(){
  if(some condition){
    log
  }
}
```is completely different from
```cs
public void method(){
  log
  if(some condition){
  }
}
```the above one is not the way that verify the method is running
#

btw i guess there are errors

vale karma
#

does basic movement go in a state machine or in a regular class on its own?

teal viper
teal viper
vale karma
#

im probably too inexperienced to even describe it, but im trying to break my movement up into states so I dont get spegeti code like i did last time. The catch is i have it set up but dont know exactly how to actually code the movement in there. Im sure i just need to watch a few more vids and be patient

vale karma
broken drift
keen dew
#

Pressing space works just fine. You have Collapse on in the console so you see each log only once.

#

The problem is that you never change _bunnyStats._health

teal viper
vale karma
#

Learn the fundamentals of programming State Machines in Unity with this new video break down!

This tutorial explains important concepts of the State Pattern, and how to use State Machines when programming! Today we will walk through an example project to showcase the benefits of using state, the state pattern and state machines in Unity!

This ...

▶ Play video
teal viper
# vale karma https://paste.ofcode.org/kFbVuaYDukLS6BUyDbxjch
  1. You're free to update the states in whatever update you want.
  2. You're not limited to only one update. You can implement both a regular and a fixed update in the states.
  3. You don't have to move the character from within the states, they could just be setting some important variables, like movement speed for them to be used in the actual character movement logic.
vale karma
teal viper
#

In which case it would have to be public

vale karma
#

thats weird, but useful

teal viper
#

Why is it weird?

vale karma
#

ill try with making a movement script and changing the values in the states

vale karma
#

and calling FixedUpdate on EnterState, Idk, just being new to it FixedUpdate and Update are intimidating to use correctly

teal viper
vale karma
#

im not going to write my movement code in there, bc it will only make my code redundant, but just a thought

teal viper
vale karma
#

no just having it in the managing script

#

it is challenging to break up this code correctly

zinc osprey
#

Not sure if this is the right chat for this, but I can't find anything more appropriate. Can I make the red image render on top of the other item slots?

teal viper
#

Move the image object below the item slots in the hierarchy

zinc osprey
#

I need it to be a child of one of the slots.

teal viper
#

Can't do that 🤷‍♂️
Will have to rethink whatever it is your doing.

zinc osprey
#

Damn.. ok thanks.

tawdry rock
#

Can someone explain to me if i write public float someFloat = 5.0f; and save it then i change the value to 2.0f and save why unity still thinks my float is 5?

ivory bobcat
tawdry rock
#

it's like once it declared it's set to stone and i only can change in editor not via script

keen dew
#

because that's the default value, the actual value comes from the inspector

#

If you don't want the inspector to set the value then don't make it public

tawdry rock
ivory bobcat
#

Show the log

tawdry rock
ivory bobcat
#

Show where you've changed it in code

#

And log the value after

queen adder
#

can someone help me with my web swinging movement codee please?

arctic ibex
#

Quick question, I'm well aware this can't possibly be the correct way to do this, but I'm not sure what the correct way is (I'm checking if the camera is within a set box, marked out by the corners) (Corners 1 & 2 are Vector 3s) (It's a 2D game) (This little overcomplicated if statement doesn't work anyway) (I think I'm addicted to brakets)

#

lol forgot to attach the screenshot

languid spire
# arctic ibex

you can create a Bounds and then use the Contains method

fierce shuttle
arctic ibex
languid spire
queen adder
arctic ibex
#

👍 thanks!

tawdry rock
# ivory bobcat Likely you're referring to a different instance

i have a 2 slider mouse X and Y sensivity. on valuew change i save it to player prefs: PlayerPrefs.SetFloat("mouseX", mouseX.value); and i load it with mouseX.value = PlayerPrefs.GetFloat("mouseX", 2.0f);. this works fine, even if i change scene still work. but for my mouseY it's working in the main menu (it loads the default 2.0f) but i can't load it in the game(after scene change).

ivory bobcat
#

Did you save the player prefs?

fierce shuttle
eternal falconBOT
tawdry rock
gilded elm
#

hii, when I assemble objects together (in VR) and I take the parent object, and I move the object in all directions, the objects which are assembled on it slide a little, it floats and I want to know if it is possible which remains fixed and no longer moves at all as if it were a single object ?

ivory bobcat
tawdry rock
#

but in the main menu always loads the correct sat value

ivory bobcat
#

Else you'll be working with a local copy that'll not update the file till after the application closes

tawdry rock
ivory bobcat
tawdry rock
#

im pretty sure but let me debug the heck out of it.

ivory bobcat
#

It's either you've called it or not, simple as that.

tawdry rock
ivory bobcat
fierce shuttle
gilded elm
fierce shuttle
# gilded elm I need physics and their collisions

If you have physics, things will slide and react to collision objects, alternatively then you could either freeze the constraints, increase the drag, set to "is kinematic" or force the position and rotation by code

tawdry rock
vague dirge
#

Hi, quick question, if I want to have a 1st person camera and a 3rd person camera on input, is it better to have 2 cameras and switching between them or changing all of one camera values ?

gilded elm
tawdry rock
fierce geode
#

Are there any tips for trying to do a camera-based third person character that moves respective to the normal of the ground?

#

Like I feel like I'm missing some key component; like if upside down and you still want them to move forward, but that's technically upside down.

fierce shuttle
twin ibex
#

I have dumb peoblem

gilded elm
fierce shuttle
hybrid sundial
#

I’ve programmed before and I decided to get back at it it using unity.learn and I realised that in the course the code is very well badly coded, it uses tons of unnecessary public variables and weird forms of writing simple code?

fierce geode
#

Does transform.rotation = (grounded) ? Quaternion.LookRotation(transform.forward, ground_normal) : Quaternion.identity; look bad? Trying to make my character constant stand upwards following the ground normal, and while it works with slopes going towards the X axis, but fails to rotate correctly with slopes going on the Z axis

#

Nevermind, played aroudn a bit and transform.rotation = (grounded) ? Quaternion.FromToRotation(Vector3.up, ground_normal) : Quaternion.identity; did the trick

hard hornet
buoyant knot
gilded elm
frigid sequoia
#

I have noticed that while at full screen in Game mode (but doesn't need to be actually running so is not script related), if I tab, the interface moves slighty, like it is resizing even though the screen size is not changing at all; I can not be sure of what's actually happening cause it only happens at full screen and I cannot check the inspector casue as soon as I exit full screen it resets back; is this normal? Is something wrong in my interface setup or what?

keen dew
#

If you know it's not script related then don't post to a code channel. If you mean the game's interface then post a video or screenshots to #📲┃ui-ux

frigid sequoia
#

Oh, you are rigth, there is a specific chanel for that, I though this was more of how the canvas is coded thing, sry

river bear
#

What should I do to make game like need for speed

#

What I should learn?

keen dew
#

C# and Unity

gilded elm
rare basin
fierce shuttle
gilded elm
amber spruce
#

hey so im currently working on a save and load sysetm using jsons i have ran into the problem of how do i save like the actual scene in it because for example i have enemy spawners placed throughout the scene and when you go past a certain area they spawn a few enemies how do i save those spawned enemies???

hallow gate
#

guys the guy in the tutorial is trying to teach me how to make collisions and he says i need layers, when he goes to the layer section there already are 2 layers assigned but for me there arent. how can i assign them to my player and to the background? here are the pics of reference:

#

left pic is his right one is mine

rare basin
#

save what data you exactly want

#

enemies positions

#

enemies health etc

amber spruce
#

if i save the gameobject can i then use that to instantiate it since its a prefab or do i need to drag the prefab from the editor

earnest atlas
fierce shuttle
# gilded elm

Doesnt look like you have any constraints frozen here, alternatively you could try toggling "is kinematic"

gilded elm
#

I found a solution I set its parameters to the maximum

earnest atlas
#

When making weapons why should I use raycast to check for hits instead of generting a bullet?

#

Considered raycast is pretty much instant

autumn tusk
#

i dont understand the addforce function at all

polar acorn
autumn tusk
#

basically i want to add a force leading from the direction the player's gun is firing in

#

recoil as a jumping mechanic basically

#
{
    [SerializeField] AudioClip ShotgunClip;
    [SerializeField] AudioSource audioSource;
    public Rigidbody2D playerbody;
    public Transform transform;
    [SerializeField] private float thrust = 832998f;
    Vector2 launchcalculation;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            PlayerShoot();
        }
        // Vector2 rotationshit = transform.rotation;
        print(transform.rotation.eulerAngles.z);
        launchcalculation = (transform.rotation.eulerAngles.z,thrust);

        //transform.rotation.eulerAngles
    }

    void PlayerShoot()
    {
        audioSource.PlayOneShot(ShotgunClip);
        playerbody.AddForce(transform.position * thrust, ForceMode2D.Impulse);
        print("player shoot");
    }
}
#

launchcalculation refuses to take eulerangles.z as a parameter

polar acorn
autumn tusk
#

refuses to take rotation as a parameter

#

as rotation is a quaternion

polar acorn
#

Honestly what is even the point of launchcalculation, you never use it

split dragon
#

Hi. I tried to find the difference between 2 types of security modifiers: "Empty" and "Private". I know that private can only be used in the same script, but it's the same with an empty one. Is there a difference and what is it? On the Internet, as usual, they talk about everything except this.

polar acorn
dry ravine
#

Whenever I try and click the button underneath the text it dosen't work because the text has a hitbox, is there a fix?

split dragon
dry ravine
#

Prolly should've posed in UI but whatevs

polar acorn
dry ravine
#

Thanks

#

I appreciate it dude

rare basin
#

it's 2 different approach

#

it depends on your game design

#

if you want raycast hits (hit-scans), or projectile-based hits

#

lasers (hitscan), arrows (projectile based)

earnest atlas
#

I noticed that at high speeds triggers happen to fail

rare basin
#

if you are moving throught modifying the transfomr position directly then it might happen

#

need physics for proper collisio ndetetion

#

and different collision detection mode for fast objects, like Continous

hybrid sundial
#

I’m using Input.GetAxis but I want it to only work when I press w and when I press x it does nothing

autumn tusk
#

i dont understand why my script isnt adding force to another rigidbody2d

#

basically with the script i have rn i want to make it so that it adds the force to the player character

autumn tusk
#

just experimenting with adding forces for now, have this rn

#
using System.Collections.Generic;
using UnityEditor.Experimental.GraphView;
using UnityEngine;

public class Player : MonoBehaviour
{
    [SerializeField] AudioClip ShotgunClip;
    [SerializeField] AudioSource audioSource;
    public Rigidbody2D playerbody;
    public Transform transform;
    public Transform crosshairpos;
    [SerializeField]  float thrust = 1f;
    Vector2 knockback;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            PlayerShoot();
        }
        // Vector2 rotationshit = transform.rotation;
        print(transform.rotation.eulerAngles.z);
        // launchcalculation = (transform.rotation.eulerAngles.z,thrust);

        //transform.rotation.eulerAngles
        Vector2 direction = crosshairpos.position;
        Vector2 knockback = direction * thrust;
        print(direction);
        print(knockback);
    }

    void PlayerShoot()
    {
        audioSource.PlayOneShot(ShotgunClip);
        //playerbody.AddForce(transform.rotation * thrust, ForceMode2D.Impulse);
        playerbody.AddForce(transform.up, ForceMode2D.Impulse);
        //print("player shoot");
    }
}
#

this works fine when i add a rigidbody to the shotgun object

#

but doesnt work on the player character for some reason

polar acorn
autumn tusk
#

this has nothing to do with mass and gravity scale

autumn tusk
hallow gate
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Playerr : MonoBehaviour
{
    public float moveSpeed;

    public bool isMoving;

    private Vector2 input; 


    private Animator animator;

    public LayerMask solidObjectsLayer;

    private void Awake()
    {
        animator = GetComponent<Animator>();
    }
    
    private void Update()
    {
        if (!isMoving)
        {
            input.x = Input.GetAxisRaw("Horizontal");
            input.y = Input.GetAxisRaw("Vertical");
            Debug.Log("This is input.x" + input.x);
            Debug.Log("This is input.y" + input.y);


            if (input.x != 0) input.y = 0;

            if (input != Vector2.zero)
            {   

                animator.SetFloat("moveX", input.x);
                animator.SetFloat("moveY", input.y);



                var targetPos = transform.position;
                targetPos.x += input.x;
                targetPos.y += input.y;

                if (IsWalkable(targetPos));
                StartCoroutine(Move(targetPos));
            }
        }

        animator.SetBool("isMoving", isMoving);
    }
    
    IEnumerator Move(Vector3 targetPos)
    {
        isMoving = true;
        
        while ((targetPos - transform.position).sqrMagnitude > Mathf.Epsilon)
        {
            transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime);
            yield return null;
        }
        transform.position = targetPos;

        isMoving = false;
    }

    private bool IsWalkable(Vector3 targetPos)
    {
        if (Physics2D.OverlapCircle(targetPos, 0.2f, solidObjectsLayer) != null)
        {
            return false;
        }

        return true;
    }
}
``` idk what i did wrong but for some reason my code wont make me collide as intended even tho i did as the tut said
#

Sorry for this video's bad editing :( I will improve!

Chapters:
00:00 - Intro
00:12 - Recap
00:56 - Theory on collisions
02:50 - Create Layers
03:59 - Create the object
08:02 - Coding the logic
14:33 - Debugging
15:54 -Testing the game

Links
Visual Studio Download: https://visualstudio.microsoft.com/downloads/
Character Sprite: https://gith...

▶ Play video
polar acorn
# autumn tusk just using a basic getaxisraw

So you're teleporting the character every frame without regard to the forces currently acting on it. Your addforce is working, but any movement it confers is overwritten by a teleport to a specific spot

autumn tusk
#

alright

#

should i just use an addforce for the player movement?

buoyant knot
#

if your player is a dynamic RB, then yes

#

if your player is anything else, then no

#

dynamic RB is always at the mercy of the physics engine. Kinematic RB only goes where you tell it to. I recommend you choose carefully.

autumn tusk
#

hmm, ill which works best

#

might use velocity instead

buoyant knot
#

Kinematic RBs work by MovePosition. Dynamic RBs work by AddForce and velocity

hallow gate
summer stump
#

Wait, your player is a UI element? Interesting

hallow gate
hallow gate
hallow gate
spiral narwhal
#

I remember there being a better practise than abusing recursion, what was it again?

private IEnumerator IncrementAge()
        {
            _age++;

            if (_age > EXPECTED_LIFE_TIME)
            {
                Die();
            }
            else
            {
                yield return new WaitForSeconds(10);
                StartCoroutine(IncrementAge());
            }
        }
summer stump
spiral narwhal
#

Can you give an example

summer stump
#

Might not need that yield null actually

gaunt ice
#

no need to yield return null

#

either break or wait for 10 seconds

summer stump
#

The while condition could also be the age
while age

summer stump
spiral narwhal
#
        private IEnumerator IncrementAge()
        {
            _age++;

            while (_age <= EXPECTED_LIFE_TIME)
            {
                yield return new WaitForSeconds(10);
                StartCoroutine(IncrementAge());
            }
            
            Die();
        }

So something like this?

summer stump
#

The whole point is to remove the start coroutine

spiral narwhal
#

Ah yeah right

#
        private IEnumerator IncrementAge()
        {
            while (_age <= EXPECTED_LIFE_TIME)
            {
                _age++;
                yield return new WaitForSeconds(10);
            }
            
            Die();
        }
hallow gate
#

can someone help me with fixing my collision issue? my character to solidObject collision works but for some reason the distance between them is bigger than intended

hallow gate
buoyant knot
wintry quarry
buoyant knot
#

I would store a timestamp for birth, have a property to interpret age, and a single coroutine to call Die() after a single wait call

hallow gate
spiral narwhal
wintry quarry
polar acorn
#

What value is it and what are you expecting

hallow gate
buoyant knot
#

do you need to know about accurate collision distances?

buoyant knot
#

are you using Physics2D?

wintry quarry
hallow gate
safe root
#

!code

eternal falconBOT
hallow gate
buoyant knot
#

ok, i can explain a bit then

hallow gate
#

ok

buoyant knot
#

Physics2D uses Box2D. For math reasons, all edge and polygon shapes have a radius tied to them for collision purposes.

#

This includes basically all Collider2D except circle colliders (and maybe capsule colliders?)

#

The default edge radius is something like 10^-4

#

If you get the “distance” between two colliders, this radius gets added in (depending on the type of query).

#

So if you get the distance between two Circles that are 1 appart, unity says distance =1. If It’s between two box colliders 1 appart, unity will say something like 0.998

#

This becomes relevant when you try to put two things into contact, and so the distance between them is very sensitive to that edge radius. The default edge radius is based on default contact offset, which is a setting in Physics2D project settings, and if you ever change this value, then everything will break.

#

@hallow gate

#

btw this affects the results of a LOT of Physics2D queries, like Collider2D.Cast, and Collider2D.Distance

safe root
hallow gate
# buoyant knot <@735431771360985109>

that seems mad complicated for some reason i just followed the tutorialist and he didnt show me any of that he just showed me code and that was pretty much it

buoyant knot
#

how relevant it is depends on what you are doing

#

if you need to move something to a precise location to be right in contact with something else, it becomes relevant. Or if you are trying to do something specific with the distance between two things in contact, it is relevant

queen adder
#

Ur missing a ending bracket for ur class MRW419

summer stump
hallow gate
buoyant knot
#

that sounds like this will be relevant then

summer stump
buoyant knot
#

ping me in the thread then. my discord mobile is weird, and won’t open it

#

ty

safe root
summer stump
#

The one for the class

safe root
summer stump
polar talon
#

Hi all, has anyone had issues with reloading the current scene a player is in?

I have a scene that instantiates a lot of procedurally generated content and deletes some other content. When I use SceneManager.LoadSceneAsync I'm expecting the scene to revert to it's original state, but the content I generated or deleted previously does not reset.

polar acorn
#

Yes, code would be nice to see how you're handling the scene transition. A before and after screenshot of the hierarchy would be nice too

polar talon
#

Thanks for the reply, I'll get the code and hierarchy examples

deep quarry
#
        groundedCheckDistance = GetComponent<MeshCollider>().sharedMesh.bounds.size.y / 2;

I am getting following error for this line of code:
NullReferenceException: Object reference not set to an instance of an object

languid spire
#

so there is no MeshCollider on the object

swift crag
#

a null reference exception has one, and only one, cause: you attempted to access a member from null

deep quarry
languid spire
#

that proves nothing

swift crag
#

that's not the only thing that can be null (:

deep quarry
#

There is a MehCollider to the object ^^

swift crag
#

notably...

swift crag
#

another object could have a RocketController but no MeshCollider, after all

#

You can find out exactly which object is responsible for many kinds of errors by clicking once on the error message in the console

#

it'll take you to the offending object in the hierarchy or project window

languid spire
#

we do not even know this is RocketController

deep quarry
languid spire
#

first post the stack trace for the error

swift crag
deep quarry
swift crag
#

for multiple reasons:

  • A MeshCollider must be given a mesh asset. If you have a MeshRenderer parented to whatever this object is, then you'd have to make sure you assigned the same mesh asset
  • You're checking the bounds of the mesh asset itself. This is not the bounds of the collider.
languid spire
#

not gonna generate a NRE

swift crag
#

yes, but I think the design is wrong even after fixing the NRE

#

sharedMesh is null so it's throwing up

languid spire
#

indeed

swift crag
#

not "get the ground check distance" or "find the bounds size"

#

explain what you're actually making your game do

deep quarry
swift crag
#

are you trying to detect when the rocket is properly landed, or just when it's hit the ground at all?

deep quarry
#

when it's hit the ground at all.

swift crag
#

I would suggest using Rigidbody.SweepTest

#

It tells you if the rigidbody would hit anything when moved in a certain direction.

#

This sounds applicable.

deep quarry
#

Thanks for the input. But I still want to learn why the MeshCollider gives an error.

swift crag
#

Log the result of GetComponent<MeshCollider>().

#

Then, log the result of GetComponent<MeshCollider>().sharedMesh

#

One of these will be null.

#

It doesn't matter if the component exists if you grab a null reference from it and then try to use it

swift crag
#

But if you just care about resting on any collider, then that should work fine

deep quarry
#

Solved it. However I get a new error, saying Non-convex MeshCollider with non-kinematic Rigidbody is no longer supported since Unity 5.. I suppose I need to make the Rigidbody Kinematic?

swift crag
#

A kinematic rigidbody is not affected by physics.

#

That is probably not what you want.

#

You need to...

  • Delete that MeshCollider
  • Attach a MeshCollider to the same object as your MeshRenderer
  • Make the MeshCollider convex.
#

A convex collider is shaped like shrinkwrap.

#

It doesn't have any holes or dents. It's a much simpler shape to reason about

#

Alternatively, just slap a box collider on it and call it a day

#

It's probably good enough

#

You can use multiple colliders, too: a Rigidbody will use all colliders parented to it

deep quarry
#

MissingComponentException: There is no 'MeshCollider' attached to the "Rocket" game object, but a script is trying to access it. You probably need to add a MeshCollider to the game object "Rocket". Or your script needs to check if the component is attached before using it

swift crag
#

you should remove that code

deep quarry
#

what code? the get groundcheck one?

swift crag
#

the code that tries to get the MeshCollider.

deep quarry
#

so how will I then get the size of the MeshCollider? :3

swift crag
#

you don't

swift crag
#

that's why I suggested using this method. it's way simpler and more reliable

#

your method would fail for any ship that's wider than it is tall (think a flying saucer)

nimble hinge
#

"The more you learn, the more you realize how little you know"

ivory bobcat
swift crag
bright oxide
#

Why is this returning 1? Am i missing something?

#

The way i understand it, Mathf.Sign returns 1 if the value is positive, -1 if it is negative and 0 if it is 0?

bright oxide
#

i see, cant always rely on chatgpt

polar acorn
#

Check the documentation

bright oxide
#

wouldnt go that far but yeah

earnest atlas
#

Do UI Image have tilable settings? I want to create something like healthbar and so far its decreasing is size to middle

polar acorn
# bright oxide wouldnt go that far but yeah

It literally does not know things. It has no memory, it has no concept of comprehension. It builds a probability curve of text based off of existing data, choosing words that are most likely to come in that order. It is a fancy version of the predictive text feature on your phone, just with more data.

#

there is no concept of "fact" only how common a set of words are

swift crag
#

most of the "magic" is just the enormous amount of data shoved into it

rich adder
#

but yea there is tiled mode, stretch and fill iirc

#

although for healthbar i would use Fill and change that

rare basin
#

and you could test it in 10 seconds 😄

earnest atlas
#

Its just UI image looks like its not having sprite parts

rare basin
#

you need sprite to be assigned to the Image to be able to set the mode, for healthbar set it to Filled and manipulate the fillAmount in code, anyway this is not a proper channel for that

earnest atlas
#

I had no sprite set to it so I couldnt manipulate the value

vast vessel
#

Lets say i have a script that needs refrances to 3 other scripts on the same component.

Is it better to have them be public properties and assign them in the inspector? Or will it just be fine if i have them be private and assign them in Wake(), with TryGetComponent?

earnest atlas
#

fine on awake when its on same object

vast vessel
#

Wont the latter will increase my Scene load times if i have that script on many game objects?

earnest atlas
#

Its not GameObject.Find so most likely not

#

You can totally serialize it

#

I just dont like serializing

vast vessel
#

Hmmm. Well i guess ill go with it, since serializing them and having them show up in the inspector will just make things more messy.

#

I mean, if i dont need to see them and assign them in the inspector, then why should i have them serialized?

summer stump
rich adder
#

I never understood the "I dont want my inspector cluttered"

#

this is nonesense statement

earnest atlas
#

I dont like serializing objects I need in multiple objects. I just find it at 1 place and access it like this

vast vessel
#

Also whats wrong with wanting a cleaner inspector?

rich adder
earnest atlas
#

DI interfaces still elude me

#

somehow making eveyrhing by guide they dont want to work

rich adder
earnest atlas
#

yeah

#

Im more of data manipulation course

#

So I was interested in making them

rich adder
#

whats DI have to do with Interfaces

earnest atlas
#

DI interface

vast vessel
rich adder
earnest atlas
#

I dont remember

rich adder
#

they are the same way used as any other type

earnest atlas
#

Wdym?

rich adder
#

if your pooling needs to inject something in the pooled objects sure

rich adder
#

its part of the SOLID principles

earnest atlas
#

Well I tried implementing them when was working with windows and then in android with dagger, but in first case it didnt work in second it absolutly broke my app

safe root
rich adder
earnest atlas
#
    {
        float forwardInput = Input.GetAxis("Vertical");
        float rightInput = Input.GetAxis("Horizontal");

        characterMovement.Input(forwardInput, rightInput);
    }```

Where does this lead?
earnest atlas
summer stump
#

I don't think they were saying that the d stood for DI
Just that the concept of separation by using interfaces aligns with SOLID

rich adder
rare basin
#

that's not what they meant lol

safe root
storm imp
#

@polar acorn world canvas?

polar acorn
rich adder
summer stump
#

Brackeys!! mad

rich adder
#

permanent wound

polar acorn
rich adder
earnest atlas
#

new DataHold(_images[0],0,GameController.Instance.Health)

I want to save link to Instance otherwise it will just save the value. Is it possible?

storm imp
safe root
rich adder
polar acorn
rich adder
#

thats stumbling on the same problem

summer stump
storm imp
# polar acorn Either move the image on the canvas instead of the camera, or use a world-space ...

but I followed this tutorial and it worked for him

https://www.youtube.com/watch?v=LLk4EYrcBQE&t=5s

This tutorial series teaches you how to take 360 images and make a virtual tour with points of interest in unity.

Follow me on twitter https://twitter.com/JamesDestined
Follow me on instagram https://www.instagram.com/artbydestined/
Buy my pieces on redbubble http://DestinedArt.redbubble.com

Any comments or questions welcome. Enjoy the video!

▶ Play video
rich adder
#

oh boy..

carmine elm
#

if i have more than one class in a script how can i acess a variable from it . if i do the normal thin like: ...GetComponent<.....>()....=0, it s says that isn t a definition for that.

summer stump
safe root
rich adder
#

you have to BE SURE

summer stump
polar acorn
#

The image doesn't move

rare basin
#

just A or B

carmine elm
#

not the script just the int

summer stump
#

Remove those

carmine elm
#

i did

summer stump
#

GetComponent<Player>().health

rich adder
summer stump
storm imp
carmine elm
safe root
summer stump
rich adder
safe root
#

Nothing happens pass that

rich adder
polar acorn
polar acorn
#

This tutorial is specifically on how to make a menu that swaps that material based on your input

#

The menu doesn't move

#

This is part 3. Did you view the first two parts

polar acorn
safe root
storm imp
# polar acorn The menu doesn't move

The menu is not supposed to move when you click the button it brings you to the first photo and you're supposed to be able to move in the photo

rich adder
polar acorn
safe root
polar acorn
# storm imp

Okay so you do have the sphere. Show the inspector for the object that controls the camera's movement

rich adder
polar acorn
#

Whatever object has that script on it

#

Also you haven't assigned any sites to this object

summer stump
# storm imp

Wait, is the issue that the menu picture doesn't go away?
After what digi said, show the button's onClick in the inspector

polar acorn
safe root
#

What values would I put?

storm imp
polar acorn
rich adder
# safe root What values would I put?

um ok for example

void LateUpdate()
{
   Debug.Log($"xAxis value is : {xAxis}, yAxis value is : {yAxis}");

   Quaternion newRotation = Quaternion.Euler(xAxis, yAxis, 0f);

   Camera.main.transform.rotation = newRotation;
}```
carmine elm
#

Now i have can t refference to the variable because the class from the other script has to be MonoBehaviour

summer stump
#

Component is a type, which MonoBehaviour inherits from

carmine elm
#

so besides that what can i do

summer stump
#

GetComponent only works for things that inherit from it

summer stump
rich adder
carmine elm
#

i wan to do an DataSaver

rich adder
#

it should be probably a Plain class that holds data

summer stump
polar acorn
summer stump
#

There is no script that moves anything there

rich adder
summer stump
#

You should know which script has code that moves the camera. Show that one

summer stump
#

And should the CamerController not be ON the camera? Could be wrong since I haven't seen the code

polar acorn
#

the one that had nothing in it

summer stump
safe root
polar acorn
# storm imp

So your camera controller is rotating this object, which seems to contain the camera and the sphere. So it's moving everything at once

summer stump
#

That's not what the tutorial had. Just sayin

rare basin
rich adder
storm imp
summer stump
polar acorn
#

Actually they have the spheres on the wrong object

summer stump
polar acorn
#

Why are your spheres a child object of your camera controller

dusty silo
#

I am wondering: if you put a script onto a prefab, will the script's constructor be called, or would I have to use start/awake?

carmine elm
summer stump
rich adder
languid spire
storm imp
rare basin
dusty silo
rich adder
polar acorn
#

You've made your spheres child objects of WorldCenter

languid spire
storm imp
summer stump
#

The screenshot there is from the tutorial. Notably, the spheres are NOT children of WorldCenter

rare basin
languid spire
#

ok, pedant, should not, happy now?

summer stump
polar acorn
storm imp
summer stump
#

That would make them children of WorldCenter. Which they already are

#

Drag them into a blank space

#

So they are children of the scene only

storm imp
summer stump
polar acorn
rare basin
#

you was sent that link already

#

did you check it?

rich adder
#

bro just ignored responses then askss again, A+

rocky canyon
#

copy paste response

#

ez solution

rare basin
rich adder
rare basin
storm imp
summer stump
languid spire
#

tbh the links are not relevant to his problem, it's a POCO

summer stump
#

You moved the camera

#

You needed to move the snow sites (the spheres)

storm imp
summer stump
#

WorldCenter needs the camera as a child

summer stump
rocky canyon
#

if ur following a tutorial just make it look like the tutorial.

rich adder
rich adder
languid spire
#

@carmine elm SaveDataObject.stats.something

rich adder
#

not clear how they want to grab it

summer stump
rich adder
#

so they need to access that field i assume from DataManagerSaver which is MB

rocky canyon
#

i hope ur mispelling the name of that variable

#

ohh ur not..

#

public SaveDataObject SaveDataObject; this is no bueno right?

#

having the exact same name as the class

polar acorn
#

why did you move the camera

rich adder
polar acorn
#

that was never suggested

rich adder
#

I would never use same name though

storm imp
polar acorn
#

Make the spheres not a child object of the camera controller

rocky canyon
polar acorn
rocky canyon
#

i dont do that, b/c its asking for errors imo

storm imp
rocky canyon
rich adder
rich adder
#

maybe a unity backing field if needed in inspector

rocky canyon
#

imma stick to normal naming.. (same as class) b/c i already confuse myself

rare basin
#

would be confusing to me and other programmers in the team

rocky canyon
#

absolutely

rocky canyon
#

yessir

rare basin
#

class BossFight, filename NormalMobFight lol

rich adder
#

yeah I rather keep MB named same as filename

summer stump
#

That is a 2022+ change

rich adder
rare basin
#

yea ig

storm imp
#

it works now thank you sooooooooo much for the help @summer stump @polar acorn

rich adder
#

eg one file can contain multiple classes related to each other

#

having a bunch of files for small classes sometimes is more clutter

rocky canyon
#

yea, thats a good example..

#

i was thinking the same.. if u have multiple classes within 1 file..

#

u can chose w/e is relevant

rich adder
#

Just wished we had File-Scoped namespaces tho 😭

scarlet skiff
#

when colliding with a gameobject that is a parent, is it possible to check for what part of the parent it collided with? say that the parent has a collider but also a child of the parent has a collider, can u check which one it collided with? code wise

dusty silo
#

Is this okay, or should I use getComponent?
Edge e = Instantiate(Resources.Load("Prefabs\\EdgePrefab")) as Edge;

rich adder
rich adder
scarlet skiff
#

full method

#

both the force field and the shiled have trigger colliders

#

wait.... is it cuz none of them has a rigidbody? i think i didnt give either a rigidbody..

summer stump
rocky canyon
#

well, thats atleast (1) reason

summer stump
#
  1. if you have a rigidbody on the parent, it will treat all the colliders as a composite collider
#

I always recommend simply having the OnCollision/OnTrigger code ON the children, and pass pertinent collision data up to the parent

scarlet skiff
rich adder
#

Yup usually my child colliders send data to parent

summer stump
scarlet skiff
#

well.. i want some projectiles to bypass, and some not

#

currently i have 4 layers for the collision, to do it via layers, id need 2 more layers for this

#

do i just do it anyways?

#

or try a diff appraoch

rich adder
#

you can just do ignore for the colliders

#

it doesnt have to be layers

native seal
#

what should I consider when choosing to use a singleton vs a static class?

summer stump
rich adder
#

so you can assign specific colliders to collide or not

rich adder
#

imo

native seal
#

why is that the case though?

#

cause it seems static classes can work for tha ttoo

rich adder
#

Just personal thing I do, so take it as opinion and not fact.

#

static can cause more problems than it can solve sometimes

#

the instance itself is static and is fine for me when doing singleton

low path
#

helper functions are things that generally don't need state. the static class is just a namespace. if you have something in unity that is part of your game logic and has state, you generally want to be able to control it with scene controls, etc.

#

like reloading a scene or something will just reinitialize. otherwise you will have to manually re-initialize the static class, which is another place bugs can happen.

rich adder
low path
#

also, monobehaviors can't be static classes, so you can't do things like update

native seal
#

okay so for example, I have a Save System and and Item Database, does it make more sense to make them singletons or static

rich adder
#

also you cannot see static variables in unity inspector etc

native seal
#

the save system just saves/loads all stuff on exit/enter and the item database holds a SO that has all the items avaliable in my game

rich adder
#

the system that deals with System.IO is static class

#

the one that interacts with MBs(gets data to pass to static IO class) is static instance (singleton)

summer stump
#

Ok, yeah that's fair

low path
#

i think static class is fine for a save system because you can make the save system without any state - it reads stuff from disk, puts it int your game objects, etc., or does the opposite.

native seal
#

same with the item database no?

rich adder
#

database , system file same crap

native seal
#

i just holds a list of items that can be accessed

low path
#

personally i'd not use a static class for the database because i'd like to be able to plug it into the unity inspector

native seal
#

thats why i use an SO to hold all the items

rich adder
#

use the most basic database . Json file xD

low path
#

but if you want to just have it completely separate, that's fine i guess

scarlet skiff
native seal
#

json cant serialize SO's correctly

#

atleast from what ive tried

rare basin
#

SO cant be serialized at all

native seal
#

yea

rare basin
#

its not about json

rich adder
native seal
#

I do

rich adder
#

then it should be no problem

native seal
#

my save system saves the name and then gets the name on load

#

to build the item

#

i know thats not my issue im just wondering about the singleton/static thing

rich adder
#

thats bad

#

I put a POCO on the SO and serialize the POCO

#

getting names sounds horrid

low path
#

singletons are more for like... managers/controllers within the game itself. things you definitely dont' want/can't do with a static class

native seal
#

wdym poco

rich adder
#

Plain old C# object ( a regular class)

rich adder
#

or plain old clr

#

w/e

low path
summer stump
low path
#

or if you need to use the inspector

native seal
#

okay so thats the only difference really

low path
#

and also, it's easier to deal with scene changes/reloads using monobehaviors

low path
#

yeah but it's a big difference

rich adder
summer stump
rich adder
native seal
summer stump
#

I dunno how many they need

rich adder
#

nah but Ignore collision just needs colliders

#

no need for layers

summer stump
#

Oh, or do you mean the PROJECTILE would ignore it for different types...

#

Yeaah, I hear you

scarlet skiff
rich adder
rich adder
scarlet skiff
#

what do you mean?

#

its what i was gonna try, is what i meant, so i was asking iof that could work, rather than using collision2d,ignore()...

native seal
#

could also use a guid

rich adder
rich adder
scarlet skiff
#

and it works now!

native seal
#

then when I load the game back up, it rebuilds the items using the name

#

fetching the SO/item from the database

rich adder
#

yeah you're recreating it

#

I used guid before when making items that cannot respawn if you Load a game

#

like chests that already hold items picked up etc

#

had to tap into the SerializableDictionary realm

#

it was annoying

native seal
#

so what I'm doing is bad?

#

the only issue is when changing item names and using a GUID wouild fix that, I just haven't implemented it yet

rich adder
#

Where did I say that?

native seal
rich adder
#

Ohh I thought you meant you were getting references back by names, I misread

native seal
#

ah okay

#

👍

stuck cliff
#

Does anyone know if there is a C# script for a 2d game, basically I want to create a mechanic, that after the knife cuts the bread (goes through all the bread collision) changes the sprite

rich adder
#

not likely.
dissect the problem into smaller ones and build it yourself

native seal
#

maybe on collision exit?

rich adder
stuck cliff
#

yes

#

Im trying to make a game, in that game I will pick the knife with the mouse then i need to cut the bread

#

and i had that idea

rich adder
#

You could def do a raycast from mouse to the bread collider or something

stuck cliff
rich adder
#

something like that

stuck cliff
#

oh i already know how to do that

rich adder
#

well there you go

#

when you solve those smaller issues you build up to the thing you want

violet falcon
#

Hello i have an error on a code that " SceneManager.LoadScene" giving me this error "Severity Code Description Project File Line Status Deleted Details
Error CS0117 'SceneManager' does not contain a definition for 'LoadScene' Assembly-CSharp D:\GAMES BY ME\Pixel Run\Assets\Scripts\menum.cs 22 Active
"

stuck cliff
#

alr

#

ty

rare rivet
#

How can i tell if i have collided with the parent of a group and not a child? When I tried collision.transform.name(name) it still fired on the child object

polar acorn
rare rivet
#

I have reasrched with no lick

violet falcon
polar acorn
violet falcon
polar acorn
rare rivet
violet falcon
storm imp
#

how come I get this hold on when I hit play?

polar acorn
# violet falcon yes

Go to the line the error is on, put your cursor over the SceneManager text and press F12. Screenshot what comes up

violet falcon
storm imp
rich adder
storm imp
polar acorn
rich adder
#

otherwise just disable the Domain Reloading and you're gonna be in playmode in a fraction of a second

storm imp
median ruin
#
void Start()
    {
        CursorText = GameObject.Find("/GameHUD/Popup/CursorText");
        CursorText.GetComponent<Text>().text = text;
        CursorText.SetActive(false);

    } 

Is this incorrect? What does "Object reference not set to an instance of an object" mean?

crystal venture
#

I'm doing some practice with the basic movements, I managed to make a cube move, rotate and jump.
I would like to implement a jump similar to Mario Bros but in 3D, can you help me?

rich adder
#

but yeah you possibly have lots of script doing GetComponent, or something heavy in Start/Awake @storm imp

polar acorn
median ruin
#

21, the middle oe

#

cursortext null?

crystal venture
polar acorn
rare rivet
rare rivet
#

How can i tell if i have collided with the parent of a group and not a child? When I tried collision.transform.name(name) it still fired on the child object

crystal venture
rare rivet
rare rivet
#

Tryed

#

Threw eeror

#

Error

rich adder
rare rivet
#

Nullexception

hardy tartan
#

hey

rich adder
#

then your object hit has no parent

rare rivet
#

Bruh it does rho

#

Tho

rich adder
# rare rivet Tho

computer says otherwise according to you, so i incline to always believe computer

rare rivet
hardy tartan
#

dumb dumb question, i have a .unitypackage file thing i wanna import, but it's not showing up as a .unitypackage file extension thing, it showing as GZ, help pls, (very new to unity)

rich adder
rare rivet
median ruin
crystal venture
silver flicker
#

hey, so im trying to get the value of the angular velocity in an rb2d in order to make a drifting-type system, although its constantly at 0. Currently I'm changing the rotation of the object dependent on the mouse location on screen, anyone know why its constantly set to 0?

rare rivet
rich adder
wintry quarry
rocky canyon
median ruin
median ruin
rare rivet
crystal venture
rocky canyon
#

physics are physics, and math is math

rare rivet
rocky canyon
#

just use Rigidbody vs Rigidbody2D

eternal falconBOT
#

mad No

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

rare rivet
#

Mb, im on my phone rn

#

And i cant use discord

median ruin
#

dusty code

rocky canyon
#

since you putting it out there for the world to see, clean your monitor bro

rich adder
rare rivet
#

School coding is crazy

median ruin
#

very dumb of school...

rocky canyon
#

u just blocked the only person thats probably gonna help ya

#

oh u mean teh website is blocked

rocky canyon
#

i read that wrong

rare rivet
median ruin
rare rivet
#

@rich adder I could use my hotspot if u think u would be able to help with the text code tho?

rare basin
#

bunch of text objects

#

appearing after delay + input fields

rare rivet
fervent abyss
rich adder
fervent abyss
#

how

rocky canyon
#

i been using this website like wildfire lately

rare basin
fervent abyss
rare basin
#

what did you google exactly

rocky canyon
#

are you making some new cutting edge thing? if not google has solutons

rocky canyon
rare basin
#

googling is a skill

#

all devs need to learn

#

everything is in the internet

rare rivet
median ruin
#

I can't figure out how to get the component type "textmeshpro" from a gameobject? I looked up a unity forum thread but couldn't find a good answer

rare rivet
#

Maybe its because theres a difference between transform and gamepbjext?

rare basin
#

text mesh pro is an asset

#

and it has multiple components

#

like TexMeshProText etc

#

or TMP_Text

median ruin
#

I want to access this component

rare basin
#

TMP_Text then

median ruin
#

Why are there so many similar names?

rare basin
#

and what would it be?

#

1 name for everything?

#

that's not possible

rich adder
#

Text(UI) is the type of Text component

#

not that diffcult

#

TMP_Text is the baseclass for Any of TMP text (UI and Mesh)

rare basin
#

yea, TextMeshPro - Asset
TMP_Text - text component of TextMeshPro asset

amber spruce
rare rivet
rare basin
#

and save only things you want to save? 🤔

median ruin
rare basin
#

you dont need to guess anything

rich adder
amber spruce
rich adder
rare basin
median ruin
rich adder
languid spire
rocky canyon
#

i like..

#

i use it for everything.. then if i need a specific i'll change it if/when it doesnt work

amber spruce
rich adder
rare basin
#

save the things you want

rocky canyon
#

make a function that just saves that 1 part

rare basin
#

and dont save thing you dont want

rocky canyon
#

instead of saving all of em..

median ruin
grand forge
#

hello im new to unity u think a 2d platformer is way to go for first thign

rocky canyon
#

lmao.. thats a weird thing to say..

rare basin
#

yea it's insane xd

rich adder
rocky canyon
#

unlike u I like driving my car, instead of going out and purchasing a car first

rare basin
#

some people thinking logics are just crazy xD

languid spire
grand forge
#

just like a small 1

wintry quarry
glass urchin
#

how does the layerMask bitmask thing work?

rocky canyon
#

but yea a simple 2d game would be the best first project

glass urchin
#

I'm seeing someone use negative integers and I'm confused

grand forge
median ruin
#

TMP_Text doesn't seem to work

rocky canyon
amber spruce
# rare basin save the things you want
public void Save()
{
    float playerSkin = selectedOption;

    SaveObject saveObject = new SaveObject
    {
        playerSkin = playerSkin
    };
    string json = JsonUtility.ToJson(saveObject);

    SaveSystem.Save(json);

}

so this wont overwrite the players location and health right

grand forge
spiral narwhal
#

Will Instantiate(this) create a new copy of the entire game object of the script?

wintry quarry
spiral narwhal
#

Including the parents?

wintry quarry
#

no

rocky canyon
#

i believe w/o anything else.. ya this is referring to the GameObject

languid spire
#

mo

wintry quarry
#

only the children

spiral narwhal
#

Okay thanks

rocky canyon
#

then its the MonoBehaviour?

median ruin
prime cobalt
#

Does anyone know how could I use code to make it so I can grab, drag, and resize UI elements like this in game like I can in the editor? Similar to what I'm doing in this video.

languid spire
#

it is this class

wintry quarry
rocky canyon
#

ahh, ok my mistake

polar acorn
rocky canyon
#

did you include the using TMPro; using statement?

rare basin
#

or did you import TMP Essentials at all

rich adder
#

no because they rather spend time coding

rare basin
#

lmao

languid spire
#

not coding if all you generate is compile errors

#

that's just writing

median ruin
rocky canyon
polar acorn
median ruin
rocky canyon
#

did you include the using statement ^

rich adder
#

if only there was something that told you which namespace

rocky canyon
#

if ur not sure then its probably not installed

median ruin
wintry quarry
#

TMP is installed by default in most new projects

rocky canyon
#

the only thing u need to do is go in there and import the essentials

rocky canyon
#

after you pull in the essential stuff it should be ready to rock n roll

amber spruce
rich adder
# rocky canyon

doesnt that just Import like materials and shaders n stuff

median ruin
rare basin
polar acorn
rare basin
#

and dont save the other things

rocky canyon
polar acorn
#

The namespace is part of main package

rare basin
rocky canyon
#

ohh.. well then i'll ignore it next time..

#

i thought it was a requirement

amber spruce
rich adder
polar acorn
median ruin
rocky canyon
rich adder
#

I recall someone had pink font without it

rocky canyon
#

the Liberation Font.

#

a classic

languid spire
rocky canyon
#

lol

#

but i always import those starter things.. so thats probably why

rich adder
languid spire
#

I remember it, don't think we ever found the cause

#

good to know

rich adder
median ruin
rare basin
rocky canyon
#

The TextMesh Pro UPM package is already included with the Unity Editor and as such does not require installation. TextMesh Pro "TMP" does however require adding resources to your project which are essential for using TextMesh Pro.

#

i was gaslit !

wintry quarry
rocky canyon
#

ive never read teh TMP docs.. nows a good time i guess 😄

wintry quarry
rich adder
wintry quarry
#

where is your script file
what folders(s) is it in

polar acorn
rich adder
#

unless the error is Unity not VS ofc

rocky canyon
#

Curl error..

rich adder
#

UnityTls

#

clever name

rocky canyon
#

ive had soo many issues with 2022.3.5

#

just random errors every time i boot lol

median ruin
rare rivet
rich adder
swift crag
wintry quarry
rocky canyon
#

i think he means what folder within the project

polar acorn
swift crag
#

that smells like a networking problem

rocky canyon
swift crag
#

click on the darn thing

median ruin
rocky canyon
#

its a third party asset..

#

no worries

rich adder
wintry quarry