#💻┃code-beginner

1 messages · Page 316 of 1

summer stump
whole idol
#

So here's the funny thing

#

it prints anything other than the NextLevelObject

#

it hips the floor, it hits the upper ceiling

#

and it logs that on the console

#
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("NextLevelTag"))
        {
            Debug.Log("Player passed through a pipe, score + 1 ");
        }
        Debug.Log(other.name);

    }
}
summer stump
#

It does match, but that also doesn't matter if the version is 2022.2+

whole idol
#

perhaps it should be inside of update()?

summer stump
#

Absolutely not

#

If by it you mean OnTriggerEnter

whole idol
#

ok, tried that and it doesnt work either

summer stump
#

It has every possible reason for it to not work

whole idol
#

ok lemme ask u a question

#

I am receiving neither a collision message

#

nor a trigger message

#

so which one of these is it?

rich adder
#

do you have a rigidbody ?

rocky canyon
#

which one are you trying to do?

whole idol
#

my player has yes

summer stump
whole idol
rocky canyon
#

🤔 what? lol

rich adder
#

Your code says trigger

rocky canyon
#

is it OnCollisionEnter.

#

or is it OnTriggerEnter

whole idol
#

oh okay, maybe i should use that

rocky canyon
#

which one are you trying to debug at this moment

summer stump
#

It is OnTriggerEnter

summer stump
#

Stop just randomly trying things

summer stump
#

Go through the guide already

rocky canyon
#

it doesn't matter which one u want to use.. just click the message about your error

summer stump
#

You are going for OnTriggerEnter

#

That is the code you wrote

#

So trigger message

rocky canyon
#

^ if ur using OnTriggerEnter then click ~I am not getting a Trigger message~

whole idol
#

So mine is this guy right here, right?

#

It's Green

#

so that means it should be able to work I guess right?

summer stump
#

Your trigger doesn't have a rigidbody, only the player

rocky canyon
#

ur Trigger isn't moving around w/ physics.. ^

summer stump
#

There are multiple pages past that one, just to be clear

whole idol
#

ok so after turning its renderer on i can see that its always following the pipes, I turned off its gravity and gravity scale so that it doesnt fall off, and the second debug outside the if statement works, the if statement never gets executed

    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("NextLevelTag"))
        {
            Debug.Log("Player passed through a pipe, score + 1 ");
        }
        Debug.Log(other.name);

    }
#

And I gave it a rigidbody like you said

summer stump
whole idol
summer stump
#

Do not give it a rigidbody

#

I pointed out that it does not have one. Which is good

whole idol
#

you said my trigger doesn't have a rigidbody

#

only the player

summer stump
#

Note that it DOES NOT MEAN "give it a rigidbody"

#

You have a static trigger. Which is green in that chart

whole idol
#

what is a static trigger?

summer stump
whole idol
#

so if its green it should work

#

(?)

#

anyway so i noticed something else weird

rocky canyon
#

yes, an object w/ a rigidbody and a collider will trigger when entering a collider w/o a rigidbody (when its marked isTrigger)

whole idol
#

whenever I try to touch the huge fat round finishing line after the pipes

#

the pipes themselves disapear

#

so maybe before i even get the chance to touch it

summer stump
whole idol
#

it automaticalyl destroys itself, and thats where it begins instantiating a new clone pipe

whole idol
#

I didn't put my MessageFunction inside of Update() (?)

#

I tried that and it didnt work

#

and you told me not to do that, so I didn't

#

Mine are all turned on here

summer stump
#

See the red dot?

whole idol
#

yeah bro, I know

#

and I didn't do that

#

lol

summer stump
#

Then why say that

#

Don't give us every single step

whole idol
#

ok

summer stump
#

Just do the guide and come back after

whole idol
#

mine are all enabled

#

so thats good right?

#

Imma try that and see if it works

#

That doesn't seem to change anything actually

#

btw, how do I turn this on?

#

I don't see any Simulated setting

rocky canyon
#

its on the Rigidbody2D component

#

its right there.. 3rd property down

whole idol
#

oh isee

#

that is already turned on

rocky canyon
#

yea, its the default setting

whole idol
#

It's hinting me to report this issue to unity's developers team?

#

By the way, I just realized after reading this that my Player had a CircleCollider on

rocky canyon
#

that page is run by one of the moderators here. (not actually unity) .. but theres nothing wrong with it
i think ur just missing something

whole idol
#

and the Is Trigger wasn't turned on

#

and I turned that on just now

#

and it still doesnt work

#

lol

summer stump
#

Are you deleting the pipes?

#

It looks like you delete them when going between the visible ones

whole idol
#

yeah thats what i also noticed

summer stump
#

Yeah, so that is the issue

whole idol
#

they were going all the way to the left

#

thats what they were supposed to do

summer stump
#

You have some code destroying it BEFORE you evek get to it

whole idol
#

but now they just disapear after i hit them or right before i hit them

#
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Xml;
using TMPro;
using UnityEditor;
using UnityEngine;
using UnityEngine.SocialPlatforms.Impl;
using static UnityEngine.RuleTile.TilingRuleOutput;
using UnityRandom = UnityEngine.Random;

public class Creator_Destroyer : MonoBehaviour
{
    public GameObject whatIstoBeDestroyed;
    private GameObject m_clone;
    //public TMP_Text scoreText;

    public float DestroyWhenReachesThisXPosition = -15f;
    // Start is called before the first frame update

    public float _timer = 0; //we need a time slowdown to slow the speed of generating new obstacles in our game
    public float when_timer_should_stop = 2f;

    Vector3 pipeSpawnVector;

    private float speed;
    private void Start()
    {
        

        cloneInstantiator();
        Vector3 pipeSpawnVector = new Vector3(7.73f, UnityRandom.Range(-3.15f, 3.3f), 0);
    }
    private void Update()
    {
        Check();
        _timer += Time.deltaTime;

        speed = _timer * 2.1f ;

        m_clone.transform.Translate(Vector2.left * Time.deltaTime * speed);
    }
    private void Check()
    {
        if (_timer >= when_timer_should_stop)
        {
            _timer = 0; //reset
            Destroy(m_clone);
            cloneInstantiator();


        }
    }
    void cloneInstantiator()
    {
        float randomY = UnityRandom.Range(-3.15f, 3.3f);
        m_clone = Instantiate(whatIstoBeDestroyed, new Vector3(7.73f, randomY, 0), transform.rotation);
    }

    /*
    void Check_If_Player_Passed()
    {
        float localXPosition = m_clone.transform.localPosition.x;

        if (localXPosition < -20)
        {
            float.Parse(text_score) += 1;
        }
    }

    */
}

#

I didnt change anything in this code

#

the only thing that I changed is the new next_level script

#

I also store this script in an empty gameobject

#

because why not

summer stump
#

Destroy call right there....

whole idol
#

destroy call where?

summer stump
#

In Check()

whole idol
#

it already is

summer stump
#

I know

#

That is the problem

#

You are destroying the pipes

#

Thus you cannot collide with them

whole idol
#

well they are supposed to be destroyed after a while, after they're no longer visible

#

by the way, now it seems to work

#

but there is a problem

#

it only works and debugs on the first one

#

that i hit

#

the first time that i hit it

#

then all the others fail to execute the if (statement)

#

also... after i go through one of these pipes

#

somehow time seems to slowdown

#

or the speed with which they move on the left

storm lagoon
#

Hey, I'm trying to set a point light in a 2D platformer, but the light does not appear and instead increases gravity for the Rigitbody2D of the player sprite

#
using System;
public class playermovement : MonoBehaviour
{
    [SerializeField] private float speed;
    private Rigidbody2D body;
    private BoxCollider2D collision;

    private bool grounded;
    
    private void Awake()
    {   
        //Grabs references for rigidbody and animator from game object.
        body = GetComponent<Rigidbody2D>();
        collision = GetComponent<BoxCollider2D>();
    }
        private void Jump()
    {
        body.velocity = new Vector2(body.velocity.x, 1600*Time.deltaTime);

        grounded = false;
        Debug.Log("jump");
    }
 
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag == "Ground")
            grounded = true;

    }
 
    private void Update()
    {
        float horizontalInput = Input.GetAxis("Horizontal");
        body.velocity = new Vector2(horizontalInput * speed*Time.deltaTime, body.velocity.y);
 
        //Flip player when facing left/right.
        if (horizontalInput > 0.01f)
            transform.localScale = Vector3.one;
        else if (horizontalInput < -0.01f)
            transform.localScale = new Vector3(-1, 1, 1);

        if (Input.GetKey("up") && grounded)
            Jump();
        Debug.Log(grounded);
        body.SetRotation(0);
 

    }
 

}
timber tide
#

where be thy light

storm lagoon
#

I can send a .zip file of the entire scene if that would give me info

timber tide
#

show the light's gameobject components

#

if you arent creating it via script

storm lagoon
timber tide
#

no seeing anything would would affect a rigidbodies gravity

storm lagoon
#

well thats whats happening lol

#

heres the inspector for the player sprite

timber tide
#

click the checkmark and on the directional light to keep it inactive and try it again

storm lagoon
#

yeah that fixes the rigidbody

#

light is still gone tho

timber tide
#

and this light isnt parented to anything right

storm lagoon
#

nop

storm lagoon
timber tide
#

the idea is that two unrelated components are affecting each other and Ive no clue why if that's the case

#

imma go out on a whim and say that the light is somehow creating a large dip in your fps which creates the illusion of gravity because the framerate is tanked

#

lel

storm lagoon
#

and also the fps is fine

timber tide
#

I think first you should consider fixing some of your controller logic such that rigidbody operations should be done in fixed update

#

input should be in update

storm lagoon
#

huh ok

timber tide
#

refer to the docs

#

as for your sprite, you do not need to change the localscale but instead use flipx on the sprite render's class

storm lagoon
#

mk so I used fixedupdate and now the speed and jump is insanely fast

#

also the light still fails to appear

timber tide
#

I only care for the gravity issue atm

#

fix that then deal with the rendering

storm lagoon
#

yep the gravity's still bugged

#

changing the rigidbody variable also doesn't do anything

storm lagoon
timber tide
#

is your code looking like the docs yet

#

problem with the 2D docs is they do it in update, but really you should be doing it in fixed. Not exactly sure why but that goes against what the developers say on the forums

storm lagoon
#

ok so should I put the up key detection in update

#

and then put the movement stuff in fixed

timber tide
#

anything that uses rigidbody is usually done in fixed

#

but yeah, best practice is input in update and anything that uses physics system (rigidbodies) do it in fixed

storm lagoon
#

wait whats the input code for the up arrow key

#

so like what should I put in the

#

input.getkeydown thingy

timber tide
#

you can do by string or keycode

storm lagoon
#

ok

#

so uhhh I put the jump key into update and know the jump key works 50% of the time and doesnt the other 50%

#

istg why do I always get the strangest coding issues in existence

timber tide
#

usually you use forces for jumps and stuff, but otherwise you need to kinda flip the bool on and off everytime you jump

storm lagoon
#

ohhh

#

but why does the light

#

effect physics

timber tide
#
private void Jump()
{
    body.velocity = new Vector2(body.velocity.x, 1600*Time.deltaTime);

    grounded = false;
    Debug.Log("jump");
}

Not even sure how this code was working before

storm lagoon
#

what

#

why

timber tide
#

well, beyond the freakishly large value, you're also multiplying by frame time but the method already does it for you

storm lagoon
#

oh

#

mk then i'll remove the time.deltatime

#

ok so thye physics issue is gone but I still have 2 other bugs

timber tide
#

your horizontal movement too is being multiplied by deltatime

storm lagoon
#

1.At the start of the game, the sprite appears at like 1/2 normal size. pressing the arrow keys to move solvwes this issue but its strange

#

2.light is gone

#

rip

timber tide
#

dont change your sprite scale by localscale

#

SpriteRender has swapx method to do that for you

#

as for the light im not too sure as I don't really know too much about 2D lights

#

can always try remaking it and making sure it works in the scene

storm lagoon
#

ok then thanks for the help

timber tide
#

could be camera related too

storm lagoon
#

yeah

timber tide
storm lagoon
#

mk

covert crown
#

 // Start is called before the first frame update
 void Start()``` can anyone help me? The error says that token void is invalid as well as an error saying this error was expected. does anyone know whats going on?
covert crown
#

well these are the lines that are supposedly making these errors

#

if you want me to send the entire code, I will.

frosty hound
#

What is public UnityEvent on Interaction supposed to be doing for one thing

covert crown
#
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public class ObjectInteraction : MonoBehaviour
{
    Outline outline;
    public string message;

    public UnityEvent on Interaction

    // Start is called before the first frame update
    void Start()
    {
        outline = GetComponent<Outline>();
        DisabledOutline();
    }

    public void Interact()
    {
        onInteraction.Invoke();
    }

    public  void DisabledOutline()
    {
        outline.enabled = false;
    }

    public void EnableOutLine()
    {
        outline.enabled = true;
    }
}
``` this is my whole entire code
teal viper
#

What is on supposed to be in your code and what is Interaction?

covert crown
#

It's to interact with an object

#

supposed

frosty hound
#

Where did you get the idea that that's what it's supposed to do?

teal viper
#

Did you write this code yourself? Or are you following a tutorial?

covert crown
#

I'm following a tutorial

teal viper
#

Then go and double check that line in the tutorial

covert crown
covert crown
frosty hound
#

Show the tutorial you're following that gave you that line.

#

The error is telling you that that line is missing a ; though.

teal viper
rich adder
eternal falconBOT
onyx tusk
#

How 2 fix size of button?

teal viper
eternal falconBOT
#

:teacher: Unity Learn ↗

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

wary sigil
#

Would anybody know why this code isn't creating a json file?
(I assume it would create a file if the specified path didn't yet exist)

void thicket
wary sigil
#

how would I specify the directory?

verbal dome
#

There's also streamingAssetsPath and persistentDataPath, see which one suits your needs

wary sigil
#

I changed the code to the below to specify a relative path but it's still not creating...
I also tried specifying an absolute path like C:/User/... but that didn't work either

burnt vapor
#

Consider logging the actual path being saved

green ether
burnt vapor
#

It should be created on write but still

#

Actually, where do you expect this to be saved @wary sigil?

#

You specify a relative path so it will be saved wherever your executable of the game is

wary sigil
#

I expected it to be saved in the assets folder

burnt vapor
#

Nope

#

Use a proper path

wary sigil
#

like an absolute path?

burnt vapor
#

Use this, in combination with Path.Join Path.Combine, to a proper file

green ether
burnt vapor
#

That's what I mean, yes

green ether
#

ah okok

burnt vapor
#

Path.Join is the same but more performant and simple

verbal dome
#

Application.dataPath has been linked 3 times already lol

void thicket
green ether
#

xD

wary sigil
#

I used Application.dataPath, and I know I am getting the correct path from the logs, but the file still isn't created

burnt vapor
#

What is logged?

wary sigil
#

I added the Start() function and the path is logged to the right

burnt vapor
#

Oh I just noticed I linked the wrong docs because the previous guy also did

#

Try this instead, it points to the folder I was talking about

#

@wary sigil

#

And in this case it goes to C:\Users\<user>\AppData\LocalLow\<company name> as docs specified

whole idol
#

So i was watching this tutorial

#

then I noticed .OnFootActions

#

wtf is OnFootActions?

#

It doesn't even exist as a build-in method on unity or c#

wary sigil
burnt vapor
#

Why would you want to save in assets? You are storing persisting data

burnt vapor
whole idol
#

The first video in a series where we are creating a First Person game!
In this video we look at setting up our characters movement.

I've setup a Discord!!! and I would love to have you help me start up a friendly community where we can all help each other grow as game developers!

Discord invite link:
https://discord.gg/xgKpxhEyzZ
Can't wait t...

▶ Play video
#

nope

#

he just goes ahead and codes this without explaining

#

all I know is this

wary sigil
whole idol
#

top left he named OnFoot on the ActionMaps

burnt vapor
whole idol
#

he never created a file called that

green ether
#

Its autogenerated

green ether
burnt vapor
burnt vapor
green ether
#

6:20 in the video

burnt vapor
#

You specify just the directory

wary sigil
#

oh you are right thanks let me try that

whole idol
#

ok

#

I just rewatched it

green ether
#
       string json = JsonUtility.ToJson(myGameData);
       string path = Path.Combine(Application.persistentDataPath, "gameData.json");
       File.WriteAllText(path, json);
whole idol
#

in what way did he explain it?

#

cause I fail to understand

#

what that is

#

pls someone explain

#

i keep watching and i dont get it

burnt vapor
#

I never used the new input system but my guess is that you specify the keybinds and then generate a file that listens for these

#

But perhaps share the generated file in here

#

I personally think you should create a basic input system yourself first where you manually listen for keybinds, rather than doing this

green ether
#

So you have this Input Action Asset

burnt vapor
#

This is far more complex

green ether
#

Which looks like this

#

here you set all your keybinds etc

green ether
whole idol
whole idol
burnt vapor
#

The file that is created in the same folder

green ether
#

This is mine for the above example, I dont have much setup yet cause I was just testing the functionality but it all works

wary sigil
silent vault
#

Hello everyone. I have a problem where I update a mesh materials at runtime but somewhere in my code, those new materials get destroyed. Is there a way in Unity to find out which part of my code destroy the materials?

burnt vapor
green ether
# green ether This is mine for the above example, I dont have much setup yet cause I was just ...

public class InputManager : MonoBehaviour
{
    private void OnEnable()
    {
        _inputs.InGame.Enable();
    }

    private void OnDisable()
    {
        _inputs.InGame.Disable();
    }

    private Inputs _inputs;

    public static InputManager Instance;
    private void Awake()
    {
        Instance = this;

        _inputs = new Inputs();

        _inputs.InGame.Esc.performed += ctx => Escape();
    }

    private void Escape()
    {
        UiManager.Instance.ToggleEscapeMenu();
    }
}


#

then I can use those Inputs like this

burnt vapor
#

My guess is that it's not serialized

#

Because JsonUtility is crap and you should get rid of it

green ether
#

yeah I never did anything with Json in unity its just the first thing that came up in my googling

rocky canyon
#

why is jsonutility crap? ive never noticed an issue

wary sigil
burnt vapor
#

Rather than changing everything in your data to support serialization, just download Newtonsoft and use something that does work properly

burnt vapor
rocky canyon
#

oh, fair. my uses dont extend much past a handfull of floats and vectors

burnt vapor
#

Yes, that works fine, although you're forced to use fields rather than properties

#

But beyond that it's very quick to break

wary sigil
burnt vapor
#

It's a string too

#

I don't remember the full behavior for File.WriteAllx but perhaps it doesn't write the file due to the content being empty anyway

wary sigil
#

oh when I click on gameObjects there are no logs...

#

maybe the code is wrong somehow?

silent vault
# silent vault Hello everyone. I have a problem where I update a mesh materials at runtime but ...

OK to answer my own question, I didn't find any way but I finally could pinpoint my problem. This is a really WEIRD behavior by Unity. Basically, I was putting my material in cache at runtime with a unique md5 key. This cache was a simple dictionary with md5 as key and the material itself as value. I never initialized the cache dictionary to = new() on the start of the project. Instead, I just put = new() in the general declaration of the property. The weird part now is that when I was usign a ContainsKey on this dictionary on first play, the result was empty and it did create my material. But then, if I stopped the play and restart right away, expecting the cache dictionary to be empty, it was not. A ContainsKey returned true but the material did not exist thus loading the purple HDRP missing material stuff.

wary sigil
#

do I need to attach specific things to the gameobjects that I want to be stored?

burnt vapor
#

And that is a different problem altogether

silent vault
#

By simply adding the cache = new() in the start, i made sure the dictionary was always empty. I was assuming Unity was resetting stuff by itself but it appears not? Really weird bug...

wary sigil
burnt vapor
#

No because you only shared the method and I don't know how you call it

#

But perhaps put a debug log at the start of it and validate it's truly not called

#

Because you logged the path and this was logged correctly, no?

wary sigil
#

yes

burnt vapor
#

So it is called

wary sigil
#

yeah but only the start() function is called

burnt vapor
#

So OnMouseDown is not called?

wary sigil
#

I don't think so...

#

do I need to attach it to something?

burnt vapor
#

So this whole time it wasn't as much an issue with where you saved the file, it was the fact that the whole method was not called

#

Next time please make sure your method is actually called

#

Please actually place down a log message at the start of the method and see if this is called

wary sigil
#

onMouseDown is supposed to be called when mouse is clicked right

burnt vapor
#

Did you read the docs? There is a specific case required where this happens

wary sigil
#

I did enable the trigger for all 3 GameObjects which I wanted to be clicked and they are Box Colliders

burnt vapor
#

Are you trying to click actual gameobjects in the world or is this some UI you are clicking?

wary sigil
#

what does actual gameobjects mean
I made 3 rectangular prisms that I want to click pretty much

burnt vapor
#

I mean something in the world you try to click

#

Or is this part of a UI

abstract finch
#

Is there a reason I'm getting this error? I just want to have the transform face the direction of the velocity.
Look rotation viewing vector is zero

    {
        if (IsObstructed(transform.position, velocity, _radius, _mask))
        {
            return;
        }
        transform.position += velocity * (speed * Time.deltaTime);
        transform.rotation = Quaternion.LookRotation(velocity);
    }```
wary sigil
burnt vapor
blazing ruin
#

Hi, I have a problem. I have created an empty object, in which I have placed an object "obstacle". I have a script that lowers the transparency of the walls if the ray between the camera and the player collides with the wall(marked by obstacle layer). I have the script for the camera and walls written correctly. However, this script doesn't work when attached to a parent object when the walls themselves are its children.

What is the best way to handle this situation? At the moment, as a dumb beginner, I add the script to each child object manually.

P.S Notify me if my question is related to another branch
thx

sullen rock
#

Hello! Im trying to work with scriptable objects for the first time and Ive ran into an issue
https://gdl.space/esovuyaqes.cs
here is my SO and my method that writes data into it. The lines outside of the for cycle (for creating entirely new entries) works just fine and the debug logs at the bottom show correct values. However, the part that adds new set of distances into an already existing entry throws a null reference error on line 25, which Im not sure I understand why. I assume the list is not instantialized, but that makes no sense since Ive added something to it before...?

rare basin
honest haven
#

Mornign i have this function ``` public Transform GetEnemyAtOriginalPos2()
{
for (int i = 0; i < cubes.Length; i++)
{
if (cubes[i].position == originalPositions[1] && cubes[i].childCount > 0)
{
return cubes[i].GetChild(0);
}
}

    return null;
}``` that checks what enemy is at postion 2. then in update i have ``` if (GetEnemyAtOriginalPos2().GetComponent<BattleCharacters>())
     {
         currentEnemy = GetEnemyAtOriginalPos2().GetComponent<BattleCharacters>();
     }
rare basin
#

!code

eternal falconBOT
honest haven
wary sigil
rare basin
#

either GetEnemyAtOriginalPos2() or GetComponent<BattleCharacters>() is null

burnt vapor
#

Also, you are trying to click an UI object. Is this a button? Because then you might aswell use a proper button

honest haven
rare basin
wary sigil
blazing ruin
burnt vapor
#

The object that must be clicked must have that interface in a script as a component

rare basin
#

you need to do

var enemy = GetEnemyAtOriginalPos2();
if (enemy && enemy.TryGetComponent(out BattleCharacters battleCharacter))
{

}
#

@honest haven

burnt vapor
#

If you did all that, log a message in the method to call and see if it's called

sullen rock
blazing ruin
rare basin
wary sigil
blazing ruin
burnt vapor
wary sigil
#

the bottom field

#

do I need it?

rare basin
#

for what?

wary sigil
#

for clicking on a gameobject

burnt vapor
#

I don't recall that component, you should just have a script with IPointerClickHandler

#

Or a button

rare basin
#

you can use it just fine

burnt vapor
#

And the event system should be in the root hierarchy

languid spire
# wary sigil

that looks like you have dragged in a script rather than a gameobject containing that script

rare basin
#

add whatever youw ant to PointerClick method

rare basin
#

can be used without code

burnt vapor
#

Ah good to know, then you can use that instead

rare basin
#

im not sure what will happen tho if use EventTrigger + your own interface implementation

#

on the same game object

wary sigil
#

ok I removed event trigger but I have this script but it isn't logging anything when I click

languid spire
wary sigil
#

im not doing it on a physical object but on a gameobject i created

abstract finch
#

What the term called for using code to make a characters bone face a certain way? I want to make the spine face toward the mouse

languid spire
#

the gameobject has a collider?

wary sigil
#

box collider

languid spire
#

then it is a physical object

wary sigil
#

oh interesting

abstract finch
#

thanks

blazing ruin
#

May I film here my problem ?

verbal dome
#

@abstract finch Is it a 3D character?

burnt vapor
#

Either way @wary sigil the issue you mentioned is now boiling down to two separate issues. Always make sure you actually ask help with the problem rather than one of the reactions that might happen from it, or you are prone to the XY problem: https://xyproblem.info/

abstract finch
#

yes im doing a isometric/topdown atm

verbal dome
#

If yes, you can try something like spine.rotation = Quaternion.FromToRotation(spine.up, dirFromSpineToMouse) * spine.rotation;
Might be something else than spine.up depending on your bone orientation

abstract finch
verbal dome
#

But yeah you can do it with IK too

abstract finch
#

i remmeber having to do something to make it override animator

verbal dome
abstract finch
#

ahhh thanks

rare basin
sullen rock
wary sigil
sullen rock
wild mantle
#

anyone has a tutorial project that i could learn about bubble shooter or puzle boble game in 2d?

eternal needle
wild mantle
#

ive tried, its for my college exam

#

but usually its paid project or source code material

eager spindle
eternal needle
# wild mantle ive tried, its for my college exam

well just to let you know, you most definitely arent gonna find a tutorial that teaches good coding practices while making a full game. They are going to be complete shit, but hardcoded enough that everything works and cant be extended further.
Its really best if you start, and just split up what you need to do in steps. ask if you have specific questions

eager spindle
#

but the whole series wont be done for another month

#

@wild mantle how much programming do you already know?

wild mantle
frozen solar
#

hello, i want to use a int[,,] map variable in different scripts but everytime i "import" it in another script the variable is null. i'm blocked

#

how can i do it ?

#

i tried to use public int[,,] map; in every script but it doesnt work

gaunt ice
#

you just declare it, where you create the array?

teal viper
frozen solar
frozen solar
teal viper
#

Share the errors and code that throws them then

frozen solar
#

there isnt any error, i just cant get the array in another script, it gives me a null object

teal viper
gaunt ice
#

it is an error

frozen solar
#

what do you mean by an "error" ?

gaunt ice
#

how you reference the WorldGeneration

teal viper
frozen solar
#

public WorldGeneration worldGen;

frozen solar
teal viper
frozen solar
#

because i wrote if map == null to test it

gaunt ice
#

again, it is just a declaration, show the inspector/ the place that you assign it

teal viper
frozen solar
#

oh men yes i forgot the inspector

#

i need to assign it ?

teal viper
#

Probably. We don't have enough info.

frozen solar
#

now it works

#

thanks a lot

#

i forgot to assign it !

candid gate
#

i'm making a player controller and i need to get when the player press E (use key) using Input.GetKeyDown(KeyCode.E) but for some réson its returning true 1/10 of the time

gaunt ice
#

where you call it

#

probably in fixed update

candid gate
#

yes

gaunt ice
#

the update rate of input=rate of calling update not match with the rate of fixed update

#

so capturing any key down/up event in fixed update not work

abstract finch
#

I have a script that gets the mouse position on the camera from a raycast in order for my character to look at the mouse position, however I simply want the character to look in that direction rather than at the hit point. How would I be able to do that? The surface is flat.

#
        if (success)
        {
            // Calculate the direction
            var hitPoint = position - transform.position;
            hitPoint.y = _minYLook;
            _mousePos = hitPoint;
        }```
tiny rain
raw kindle
#

In my game the player's gameobject is destroyed when they lose, when I restart the game (reload the scene) I get nullreferenceexception (The object of type 'GameObject' has been destroyed but you are still trying to access it.) from that object even though it is set up on void start(), I believe the problem to be the scene not truly resetting and maybe some variables carrying over? I am not really well versed in the structure on how scripts in unity operate which could be my issue.

tiny rain
tiny rain
raw kindle
#

do variables in unity reset when a scene is reloaded?

tiny rain
#

Mostly yes

tiny rain
raw kindle
#

that probably why

strong wren
#

Reloading the scene (not exiting and entering play mode) can expose errors.

manic sphinx
#

can anybody help me please? I'm coding and I'm stuck for a while on one thing

tiny rain
raw kindle
#

I never touched it

abstract finch
tiny rain
raw kindle
#

now I turned it on and I still got the same issue

tiny rain
raw kindle
#

Using Scenemanager

strong wren
raw kindle
#

when I exit and enter I get no errors

tiny rain
raw kindle
#

The Gameobject is inside of a static list so maybe thats why?

#

do static lists get reset when you reload a scene?

tiny rain
wintry quarry
#

Why would they

tiny rain
#

Is why to be safe I do a lot of initialization in Awake()

strong wren
raw kindle
#

Ok I see

unborn sinew
#
        if (movementController.moveInput.x != 0f)
        {
            Quaternion targetRotation = Quaternion.Euler(cameraHolder.localEulerAngles + Vector3.forward * strafeTilt * movementController.moveInput.x);
            cameraHolder.localRotation = Quaternion.Slerp(cameraHolder.localRotation, targetRotation, slerpAmount);
            slerpAmount += Time.deltaTime;
            slerpAmount = Mathf.Clamp01(slerpAmount);
        }

        else
        {
            if (slerpAmount <= 0f || slerpAmount == 1f) slerpAmount = 0f;
            slerpAmount -= Time.deltaTime;
            slerpAmount = Mathf.Clamp01(slerpAmount);
            Quaternion targetRotation = Quaternion.Euler(cameraHolder.localEulerAngles.x, cameraHolder.localEulerAngles.y, 0f);
            cameraHolder.localRotation = Quaternion.Slerp(cameraHolder.localRotation, targetRotation, slerpAmount);
        }

slerpAmount starts at 0. It rotates to strafeTilt properly, but doesnt rotate back smoothly. Why?

raw kindle
#

I will try and reset the static variable on Start and see what happens I guess

tiny rain
unborn sinew
tiny rain
manic sphinx
#

Hello, I'm coding something and I've been stuck for a while, can anyone help me?

tiny rain
#

if (slerpAmount <= 0f || slerpAmount == 1f) slerpAmount = 0f;
Is this intended lol?

burnt vapor
unborn sinew
tiny rain
frosty hound
#

Show your code, explain your problem.

manic sphinx
#

I'm learning, and I'm programming the death of an enemy after its animation, but when I hit it, instead of doing the animation and disappearing it disappears directly, so I added a coroutine, but now it plays infinitely and doesn't disappear...

burnt vapor
eternal falconBOT
tiny rain
frosty hound
#

If you're running a routine every time it gets hit, it'll stack them. You need to disable the collider or add a bool to check isDead

manic sphinx
#

I have a bool that detects if your life is empty and when it is empty that is when I try to do things

unborn sinew
tiny rain
manic sphinx
#

public class HurtBox : MonoBehaviour
{
private float animTime = 0.40f;
private Collider2D currentCollider;
private bool animationTriggered = false;

private void OnTriggerEnter2D(Collider2D other)
{
    currentCollider = other;
    if (!animationTriggered && other.CompareTag("Enemy"))
    {
        Animator enemyAnimator = other.transform.parent.GetComponentInParent<Animator>();
        if (enemyAnimator != null)
        {
            StartCoroutine(TriggerDeathAnimation(enemyAnimator));
        }
    }
}

private IEnumerator TriggerDeathAnimation(Animator enemyAnimator)
{
    animationTriggered = true;

    enemyAnimator.SetBool("lifeIsEmpty", true);
    yield return new WaitForSeconds(animTime);
    currentCollider.transform.parent.gameObject.SetActive(false);
}

}

tiny rain
#

Also, are you using that slerp as a mean to lerp from current rotation to target rotation?

unborn sinew
#

so yeah thats a good interpretation

tiny rain
#

Tbh I think that you can just make your life simple and always slerp by a fixed amount

#

For basic purposes it works, although there might be an issue when dealing with different Frames per seconds...

eternal falconBOT
unborn sinew
tiny rain
#

Though somewhat recommended to do it at a fixed timestep

manic sphinx
frail star
#

How can I display a countdown timer between two dateTimes?

tiny rain
# manic sphinx

IEnumerators don't count down when you're in scene mode while the game is running, just a reminder since it might cause a lot of confusion

manic sphinx
#

So what can I do to make the death animation play first and then disappear?

cosmic dagger
# manic sphinx

if it's small, you can just format it, or use a paste site for large code blocks. most people can't see the script within discord (like myself) . . .

tiny rain
manic sphinx
#

I don't know how that is, my code before adding the coroutine was like this. What can I do from there?

manic sphinx
#

thanks, I'll see

tiny rain
#

You can easily use that to make the character shoot projectiles at a certain point of an animation, or, in your case, make the character disappear

tiny rain
manic sphinx
tiny rain
#

Idea is basically that it moves x% to the target, and as it approaches target the amount it moves slows down.

Unless if you use it in fixed update or so though, otherwise it will have trouble with Time.deltaTime, you can ask me for details why if you're curious

tiny rain
#

It's limitations often feel annoying but it's one of the easy ways to get something like this done

unborn sinew
#

it just snaps

tiny rain
whole idol
#
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerMovement : MonoBehaviour
{
    public Rigidbody rb;
    public float forwardForce = 2000f;
    public float sidewaysForce = 500f;

    // Update is called once per frame
    void FixedUpdate()
    {
        rb.AddForce(0, 0, forwardForce * Time.deltaTime);
        if (Input.GetKey("d"))
            {
                rb.AddForce(sidewaysForce * Time.deltaTime , 0, 0);
            }
        if (Input.GetKey("a"))
            {
                rb.AddForce(-sidewaysForce * Time.deltaTime , 0, 0);
            }
    }
}

#

so why is my player not automatically propelling forward?

unborn sinew
whole idol
#

im following a brackeys tutorial

tiny rain
frail star
deft grail
unborn sinew
mystic pike
#

Why does this make the object move up forever? It works fine on another project.

deft grail
tiny rain
tiny rain
#

You know what slerp/lerp does right?

wintry quarry
whole idol
#

that was the actual problem causing this

#

i removed it and he moved forward

unborn sinew
frail star
mystic pike
tiny rain
#

slerp(x, y, 0) = x
slerp(x, y, 1) = y
slerp(x, y, 0.5f) = right in between x and y

wintry quarry
tiny rain
unborn sinew
#
            Quaternion targetRotation = Quaternion.Euler(cameraHolder.localEulerAngles + Vector3.forward * strafeTilt * movementController.moveInput.x);
            cameraHolder.localRotation = Quaternion.Slerp(cameraHolder.localRotation, targetRotation, slerpProgression);
            slerpProgression += Time.deltaTime;
            slerpProgression = Mathf.Clamp01(slerpProgression);

I want to smoothly rotate it to strafetilt along the local z. Like this. I'm trying to get the reverse of it now

manic sphinx
tiny rain
manic sphinx
#

🙂

stuck palm
#

if (!EventSystem.current.currentSelectedGameObject) {

is this equivalent to if (EventSystem.current.currentSelectedGameObject == null)?

stuck palm
#

thanks

unborn sinew
# tiny rain So if you set the rotation to the center of the current rotation and target rota...
        if (movementController.moveInput.x != 0f)
        {
            Quaternion targetRotation = Quaternion.Euler(cameraHolder.localEulerAngles + Vector3.forward * strafeTilt * movementController.moveInput.x);
            cameraHolder.localRotation = Quaternion.Slerp(cameraHolder.localRotation, targetRotation, slerpProgression);
            slerpProgression += Time.deltaTime;
            slerpProgression = Mathf.Clamp(slerpProgression, 0f, 0.99f);
        }

        else if (slerpProgression != 1f)
        {
            if (slerpProgression == 0.99f) slerpProgression = 0f;
            Quaternion targetRotation = Quaternion.Euler(cameraHolder.localEulerAngles.x, cameraHolder.localEulerAngles.y, 0f);
            cameraHolder.localRotation = Quaternion.Slerp(cameraHolder.localRotation, targetRotation, 1f);
            slerpProgression += Time.deltaTime;
            if (slerpProgression == 0.99f) slerpProgression = 0.999f;
            slerpProgression = Mathf.Clamp01(slerpProgression);
        }

This is what I currently have. Rotate smoothly on move, then snap back when there is no sideways input. After the if statement, It should remain in the rotated state, then I can reset slerpProgression to zero. I should then be able to smoothly slerp it back to 0 rotation along the z axis.

tiny rain
unborn sinew
#

or at least thats how it works in my head

tiny rain
#

Like do it verbally, not in your head

pure haven
#

Hi, can I please get some help on a project

https://www.youtube.com/watch?v=rJqP5EesxLk&list=PLGUw8UNswJEOv8c5ZcoHarbON6mIEUFBC
i'm following this tutorial, and i'm currently up to the gravity part, but i can't get it to stop applying force constantly, can someone please help me to get this part working?

The first video in a series where we are creating a First Person game!
In this video we look at setting up our characters movement.

I've setup a Discord!!! and I would love to have you help me start up a friendly community where we can all help each other grow as game developers!

Discord invite link:
https://discord.gg/xgKpxhEyzZ
Can't wait t...

▶ Play video
unborn sinew
pure haven
#

here's the file needed I think

#

i will provide the input Manager as well if needed

tiny rain
pure haven
#

would anyone be able to help?

tiny rain
#

And Imma be out after this one

tiny rain
#

Though character controller has a slight issue, you actually need to move down a little all the time, as otherwise the character controller assumes that it's not on ground every other frame

onyx tusk
pure haven
#

like this?

onyx tusk
#

!isGrounded

languid spire
# pure haven like this?

read your code

        playervelocity.y += gravity * Time.deltaTime;
    
        
    
        // Use isGrounded property of CharacterController
    
        if(controller.isGrounded && playervelocity.y < 0)
    
            playervelocity.y = -2f; 
    
 
    
        controller.Move(playervelocity * Time.deltaTime);

It makes no sense

tiny rain
#

That's what I was talking about xD

pure haven
#

remove one of the & signs?

onyx tusk
#

@pure haven, does it work in guide?

tiny rain
#

Tho really, CharacterController has a bit of an issue where if you don't move down against the ground everytime before a groundCheck, your onGround will flicker

pure haven
#

yeah

onyx tusk
tiny rain
#

&& means true if both the right and left conditions are true

#

& is something totally different

pure haven
#

alright

#

the code works in guid, and if you want i can send a picture of the code from the guide, it may be as simple as i've missed something because dyslecia

tiny rain
#

I think why they keep adding velocity down is simply cus of the issue I mentioned lol

pure haven
pure haven
#

here's mine as well for reference

onyx tusk
pure haven
#

that has caused continual errors to appear

onyx tusk
fringe plover
#

!code

eternal falconBOT
languid spire
fringe plover
#
 private void HandleInputKeyboard()
    {
        if (canPlay)
        {
            float h = Input.GetAxis("Horizontal");
            forKeyboard += h /3;
            Mathf.Clamp(h, leftLimit, rightLimit);
            spawnPoint.transform.position = new Vector2(forKeyboard, 4);
            if (Input.GetKeyDown(KeyCode.Space)) MouseUp(); // This thing doesnt override any value
        }
    }

I dont know why but value doesnt clamp, can someone help?

pure haven
#

that has apparently fixed it

tiny rain
onyx tusk
fringe plover
onyx tusk
#

oh, wait

pure haven
tiny rain
pure haven
onyx tusk
languid spire
brazen canyon
light relic
#

Hi there Can some One help me with integrating Ads if they have done it before please provide the script and the method to do so i have tried unity doc's and youtube but wasn't able to do it succesfully

#

also i need Help with NavMesh it is not there in the designated place like with the physics and all that stuff

young warren
pure haven
#

that'll do

#

but on a note, in the tutorial it says mathf square root, etc, when i've typed that in on unity it gives this error

gaunt ice
#

mathf Mathf

pure haven
#

thank you

#

(it's for practice and getting to know unity primarily)

brazen canyon
brazen canyon
#

It's not that nice in term of movements and logic

pure haven
#

thanks to the people here i've got that fixed

onyx tusk
#

How 2 make TMP on runtime?

brazen canyon
manic sphinx
# manic sphinx 🙂

and so that the player has a little recoil when hitting, I put a variable that is the recoil force and a function that does: hero.velocity = new Vector2(bounceForce, hero.velocity.y); My player controller is an instance but when I call the function from my hurtbox, which is when I hit and deal damage, it doesn't do any recoil.

young warren
onyx tusk
young warren
#

do you know what a prefab is?

onyx tusk
#

yes, i can

onyx tusk
young warren
#
Unity Learn

Prefabs are a special type of component that allows fully configured GameObjects to be saved in the Project for reuse. These assets can then be shared between scenes, or even other projects without having to be configured again. In this tutorial, you will learn about Prefabs and how to create and use them.

onyx tusk
unborn sinew
manic sphinx
#

I have this simple function( public void Bounce(){
hero.velocity = new Vector2(bounceForce, hero.velocity.y);
}) that is to push the player and I call it when I damage the enemy but it doesn't work.

languid spire
eternal falconBOT
manic sphinx
dusty canopy
#

I want to disable a script in a gameobject with another script. Would gameObject.GetComponent<ScriptName>().enabled = false; Work? Given scriptname is the valid name of the script attached to the game object

pure haven
#

Hi, i'm now getting this error,

#

basically it's saying the look action map doesn't exist within the playerInput.cs

#

how would I fix this?

languid spire
pure haven
pure haven
#

it is exclusively affecting this line in the input manager

manic sphinx
dusty canopy
#

How do I pass a script as a type? because <> requires it to be a type and cant gather that type from a string representation

burnt vapor
#

Either way, make a dictionary of string keys representing the script name, and Type values for the script type

#

Most, if not all methods accepting a generic type, also accept a play Type type

dusty canopy
#

Okay I have a weird but functional way of doing it

#
(XRComponent.GetComponent(item) as MonoBehaviour).enabled = false;``` just incase anybody needs this behaviour
#

item is type string, so you can just have an array of strings, ensure the strings are the class names and it should disable them accordingly

pure haven
#

I'm still having this damned error and have no idea why it isn't working

onyx tusk
#

how 2 get access 2 this component throught code?

slender nymph
#

the same way you do for any other component, get a reference to it

dusty canopy
#

why am i being X'd? loool

slender nymph
#

because that is wrong, it is not a TextMeshPro component

dusty canopy
#

is it not?

#

oops

slender nymph
#

it is a TextMeshProUGUI

dusty canopy
#

close enough loool

slender nymph
#

no, because TextMeshPro is the 3d mesh text, not the UI one

onyx tusk
dusty canopy
#

eh well the formatting of how its done is correct, even if the type is wrong

dusty canopy
onyx tusk
toxic cloak
#

if i assign it like this when does it runs private Player player = PlayerManager.Instance.player;

onyx tusk
slender nymph
toxic cloak
#

even before awake?

slender nymph
#

yes

onyx tusk
summer stump
# onyx tusk idk what is awake

A method that runs when an object is instantiated (or runtime begins, if it exists before runtime starts)
It runs one time in the objects lifetime

toxic cloak
onyx tusk
slender nymph
#

field initializers run when the object's constructor is called which is way before even Awake runs (which is also the first second unity message to be sent to the objects)

toxic cloak
rich adder
final kestrel
#

https://hatebin.com/jwzcbuhzcb I am just trying to disable the image that is a crosshair. I drag the image in hierarchy but it stopped working now. Why is that?

#

Could it be that the image is inside the Dialogue Manager's prefab's canvas? Is it okay to have two canvases in scene?

rich adder
#

two canvas is fine, depends what ur doing. Always check the Event System in playmode to debug your camera ray

final kestrel
#

I could disable my crosshair with crosshair.enabled = false I meant before moving them into the canvas I believe.

#

Interaction is working fine if thats what you mean with camera ray

#

Its just the crosshair image does not get disabled for some reason

rich adder
#

You mean crosshair.enabled = false;

#

is the line running at all ? but debug.log inside

final kestrel
#

all right I will try

bright siren
#

define disable? hide is not same

final kestrel
#

crosshair.enabled = false means disable no?

#

i mean disable the image

#

I put crosshair in a different panel and made the panel gameobject setactive false and its working now.

final kestrel
#

its logging

bright siren
#

to hide the Image - better to call SetActive(false) on the gameObject... yep indeed

icy sluice
bright siren
#

enabled is only for a component/monobahaviour - generally I suggest SetActive on the gameObject holding the Image etc

final kestrel
bright siren
#

yes

final kestrel
final kestrel
icy sluice
#

tnx, that is so usefull

rich adder
#

unless you were setting it back to true somewhere, there is nothing wrong with disabling component to hide img btw

bright siren
rich adder
final kestrel
#

I have this little teleportation fade screen and I want to disable the crosshair image.

#

then enable back again once player teleports

bright siren
final kestrel
#

What I did in my case is way more convenient I believe. I was enabling and disabling stuff inside methods one by one. Putting them all together in a panel is better but still... Wonder why it did not work

rich adder
#

Instantiating and Destroying is what causes garbage in that sense

#

disabling does not, cause object is already loaded but preserved untill destroying (scene switch or manually)

final kestrel
#

Do non programmer people you worked with ever get upset about the fact that they had to drag and drop stuff in the inspector if they wanted to set up things by themselves?

rich adder
#

noo they actually prefer it for me

#

they hate when i do "everything in the script"

#

and want all sorts of custom editors

final kestrel
#

I have some serialized stuff and I'm kind of worried that it will be a hassle for them.

rich adder
#

whats hard about drag n drop?

#

never had any designer complain about that

final kestrel
#

Nothing hard on my side but maybe for some people that are not programmers. Though you do not have to be a programmer to drag and drop stuff haha

rich adder
#

exactly.

final kestrel
#

A quick question. Is it okay to have empty scripts attached to gameObjects that I want access to through script? Just to FindObjectOfType and get whatever I want?

rich adder
#

I mean you can sure, if its already in the same scene ideally stick to Serialized fields

final kestrel
rich adder
final kestrel
#

yes thats why they have to keep dragging when they want to use prefabs right?

rich adder
#

since thy live in the project folder

rich adder
final kestrel
final kestrel
#

I mean like. I have a prefab that lives in the prefab folder. I take it out and place it in the scene. Then in the inspector all the serialized fields are empty because I have to assign the relative objects.

rich adder
#

right

final kestrel
#

Thats what I meant by dragging. Since they cannot hold references.

rich adder
#

they can only reference other assets (prefabs, scriptable objects, sprites etc.)

#

(when not placed in scene)

final kestrel
#

assets that are in the folders?

polar acorn
#

Assets are files in the project. As opposed to GameObjects in the scene

rich adder
#

yes like sprites etc

polar acorn
#

A prefab is a GameObject made into an asset

final kestrel
#

ahhh makes sense.

polar acorn
#

Assets cannot reference things in scenes, since an asset always exists, but the objects in a scene only exist when that scene is loaded

final kestrel
#

but assets can reference assets because they always exist

polar acorn
#

Yes. So your prefab can reference another prefab, or a material, or an audio clip, etc.

rich adder
#

yeah they are living on your disk and are tangible objects

final kestrel
#

Wooh okay damn. This shit was bugging me for weeks. Thanks for the help!

onyx tusk
#

How 2 get button component throught code?

rich adder
buoyant meteor
#

So im working on my inventory system in unity and I have a object in the scene I want to pick up and store in another gameobject variable. this variable it public so I can set the picked up object to it. So my questions is how do I then set the picked up object to the variable then be allowed to delete the picked up object with out the variable losing its value.

onyx tusk
rich adder
onyx tusk
#

& tabButton but this is from basi c#

rich adder
buoyant meteor
rich adder
#

depends on many things

onyx tusk
rich adder
buoyant meteor
#

well i basically want to transfer it from a scene object into a variable, I dont want it to stay in the scene.

polar acorn
onyx tusk
rich adder
#

ofc it doesn't

#

did you lookup docs for OnMouseDown ? doesn't work on UI

#

its for colliders

polar acorn
onyx tusk
rich adder
rich adder
#

ui elements should not have colliders

#

you outta be using the canvas itself with Raycaster already built in

#

Just use the unity Button component on the UI object like Digiholic said

onyx tusk
polar acorn
rich adder
#

make a prefab for the button that already has the Button component on it

#

spawn it in the canvas as child

onyx tusk
polar acorn
rich adder
onyx tusk
rich adder
#

You don't even need that, just link the function in inspector

summer stump
rich adder
#

on the OnClick

summer stump
#

But yeah, what nav said is better

onyx tusk
rich adder
onyx tusk
onyx tusk
polar acorn
rich adder
#

You are trying to Run Open URL right? and just pass a diff url when you make button

onyx tusk
rich adder
#

when you create the button pass that info directly

onyx tusk
rich adder
#

MyCustomButton theButton = Instantiate(etcc.
theButton.Url = "http://something" ?

onyx tusk
rich adder
#

idk man Im just going by the limited info and code you sent 🤷‍♂️ maybe I misunderstood it

daring heath
#

hey there guys! testing a point and click game, i want the player to only be able to click and move within the blue object but not entirely sure how to add those boundaries

green ether
#

Just keep that on your mouse always, except when your mouse is outside that area, then have it on the closest point possible to your real mouse in the blue area

#

or something like that

wintry quarry
daring heath
#

thanks for getting back! would that not make it so the mouse itself cannot move beyond the bounadaries? i want the player to be able to click outside of them, in case there are interactable objects outside etc, just not move outside

wintry quarry
#

and IPointerClickHandler

green ether
green ether
#

Is it a canvas or in the world?

analog glen
#

Hello. Is it possible to make that raycast reacts different to different? Like when it collide with 1 layer it do something, but when layer 2 it do something else.

polar acorn
#

Either two different raycasts with different layer masks, or put an if statement inside the raycast block

green ether
#
gameObject.layer
#

i think to check the layer of an object

green ether
#

2 different raycasts with 2 different layers set

#

Or

green ether
#

To check which layer you hit

analog glen
#

How I can use that with raycast?

slender nymph
#

do you know what an if statement is?

polar acorn
analog glen
#

(Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out RaycastHit hitInfo1, 2.5f, czerwony))

#

Where I need to use if?

#

sorry new to raycasts xd

slender nymph
#

this is not a concept specific to raycasts

polar acorn
analog glen
#

but how I can make that that reycast returns different value with if?

green ether
#

you dont

#

You look at the returned value

polar acorn
#

So you check that thing for a property you want to know about

green ether
#

and check if it is layerX or if it is layerY

polar acorn
#

before doing the code you have this raycast run

analog glen
#

okey thanks

tender stratus
#

Hey does anyone have any tips on learning how to code 2d movement?, im really reluctant on watching tutorials as i dont want to merely copy,

wintry quarry
#

you're meant to follow along and understand/learn

#

if you were just meant to copy there would be no need for a tutorial, you'd just download the project.

tender stratus
#

I see

#

maybe i need to brush up on my c sharp coding

wintry quarry
tender stratus
#

Ive started with unity and i have learned how to introduce tiles so next steps ahead!

willow scroll
#

If you haven't, watch once again

tender stratus
#

will do!

#

Could someone explain what this text means?

willow scroll
tender stratus
#

No i mean i wrote that so i get that but the stuff above.

willow scroll
#

namespaces?

tender stratus
#

above console.writeline, as in the sativ void ect

willow scroll
#

the static void Main(string[] args) is the default method, which is executed when the console app is started

tender stratus
#

Oh so is a method like s ubroutine in python?

willow scroll
#

It's described as

the entry point of a C# application

gaunt ice
#

entry point of the whole program, and you dont need it when writing c# in unity

willow scroll
tender stratus
#

oh

#

Okay what about the other things

willow scroll
#

what about them?

tender stratus
#

IS that all necessary?

willow scroll
#

No, the namespaces, which are darker, are redundant

#

This means, currently, from all those namespaces, you only need System

polar acorn
#

In a standalone C# program, a method with that signature will be executed when the program runs but Unity is not a standalone C# program so that function will not do anything unless you call it from inside of Unity

summer stump
eternal falconBOT
frosty lantern
#

how do I stop this from happening

rich adder
short hazel
frosty lantern
#

It doesn't link back to my code

short hazel
#

Then you can ignore that

polar acorn
rich adder
#

yeah somewhere the editor visuals took a poop

short hazel
#

If it breaks stuff, restart the editor and it'll most likely get rid of it

frosty lantern
#

I'm trying to match up unity's Offset Even Q coordinate system for hexagonal tilemaps with my Cube Hex coordinate system, but I'm struggling to get the conversion right.
The debug shows the pawn coordinates in Offset from left to right:

#

I did what I could on paper:

#

here a is an integer, and I've lined up the two axes with the two rows of pawns

wintry quarry
#

Yeah Unity uses its own cockamamie scheme

frosty lantern
#

it's awful
they could have at least added support for the cube/axial version

wintry quarry
#

I have no idea if this is helpful or valid

#

but I made a hex game a while ago and made these conversion functions

sharp wyvern
frosty lantern
rich adder
#

yeah hex on tilemap is pain when following redblob

frosty lantern
#

Unity uses the offset even q so I was hoping it'd be easier to convert

wintry quarry
sharp wyvern
frosty lantern
sharp wyvern
#

note.. that's actually TWO-numbers (z is always 0)

wintry quarry
#

Note I wrote this 3 years ago so i can't walk you through what it's doing if I wanted to.

frosty lantern
wintry quarry
#

this is for an extension function

#

in is to pass it by reference and not allow modifications to it.

sharp wyvern
#

it lets you call the function like it was a member of that parameter's type.

wintry quarry
#

in is basically a performance optimization.
this lets you do myCubeCoord.CubeToUnityCell() for example

#

instead of CubeToUnityCell(myCubeCoord)

frosty lantern
#

so I can just use it on a vector3int rather than having to call an instance of a class?

#

that's pretty cool

sharp wyvern
#

yes, but do read up on extension functions, lots of limits.. e.g. they musst be static functions, and so cannot reference members. Also, unlike member functions, they cannot actually access private static members.

hushed glen
#

Does anyone want to help me get started on making my game?

willow scroll
#

no

sharp wyvern
#

sure, but this is the coding channel, what do you need help with?

tender stratus
#

Anyone know why i cannot rreference rigid body in my code?

languid spire
eternal falconBOT
gusty dome
#

heya folks, im having an issue with trying to get an object pick up mechanic working, its giving me an "identifier expected error" for this one part of the code, any ideas?

short hazel
#

!vs

eternal falconBOT
#
Visual Studio guide

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

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

short hazel
#

(This step is required to get help here)

gusty dome
#

cheers

tender stratus
short hazel
tender stratus
#

I have all the steps checked

#

all updated

short hazel
#

In Visual Studio, open the "Solution Explorer" tab (menu: View > Solution Explorer), and post a screenshot of it here

tender stratus
#

its empty

short hazel
#

Close VS, open a script from Unity by double-clicking it
This should open VS automatically