#💻┃code-beginner

1 messages · Page 177 of 1

timid saffron
#

i have this

rare basin
#

@timid saffron put debug logs

#

before that if

#

and inside that if

slender nymph
#

i see the issue. you have more than one camera, i bet they aren't properly stacked

#

or you have another object affecting that component

timid saffron
scarlet skiff
#

i cant figure out why the if statement wont run..

the object its colliding with does indeed have the tag "energyball", none of them ahve isTrigger checked, the objects don infact collide during runtime, yea idk

verbal dome
#

Does the first log run?

#

Log the tag too

scarlet skiff
#

yes

#

first log yes, second no

scarlet skiff
verbal dome
#

Like you are logging the name, log the tag too

#

collision.gameObject.tag

scarlet skiff
#

hmm turns out the parent of the object had the tag but not the child inside the parent

#

weird why u would need it on both, since both had colliders

#

but both prob shouldnt have colliders only one

#

alr, works now thanks man

earnest atlas
#

Bounds gives me full image size, not just image before tiling leading to me not looping image correctly.

Will multiplying moved distance by 10 help this issue?
Spoiler: it did not

#

Looks so borked 😄

#

where can I find sprite renderer script functions?

frosty hound
#

Docs

earnest atlas
#

Cant find anything where it sais what it accepts only of what it consists

#

I want to get this

earnest atlas
#

Yeah I have guessed it by name.

north kiln
#

Also, if you're not getting autocomplete in your IDE, you need to configure it. !ide

eternal falconBOT
frosty hound
#

So annoying how Google defaults to old versions

earnest atlas
#
var sizeMultiplied = spriteRendererList[i].size.x;
var realsize = spriteRendererList[i].bounds.size.x / sizeMultiplied;
_dataValues.Add(realsize, transformObjectsList[i]);```

Will this work as intended?
I want to get size of tiled, then get bounds for getting full image size. Devide bounds/size and get real size of image before tiling.
#

spriteRendererList is just list of sprite renderers

timber tide
#

tryitandsee.jpg

earnest atlas
#

Yeah its still crused

timber tide
#

are they different size sprites? The size should be relative to the grid size you've used inside of the sprite editor

earnest atlas
#

It shouldnt matter due to how logic should work.

#

It gets their size, when I reach same amount of distance as

#

wait

#

Its teleporting them half way isnt it?

#

whatever I will deal with this later it at least looks like its working

queen adder
#

Look for c# delegates/events. It's an intermediate concept, may take you some time to absorb, but it is very useful and worth the time studying.

queen adder
olive bane
#

I got it to work by learning how to pass a parameter into a unity event and putting the x and y variables in there. Thanks for the help!

glossy eagle
#

Hi everyone, does anyone know if there's a way to do the following:


myAction.AddCompositeBinding("Axis")
    .With("Positive", "<Gamepad>/rightTrigger")
    .With("Negative", "<Gamepad>/leftTrigger");

But without knowing how many "With()" there will be?

keen dew
#

You'll have to elaborate

short hazel
#

With a loop? The With methods return the same instance they were called on, so chaining can be done

wicked thistle
#

Hello!
Why do i need to put "UnityEngine" before "Vector3" for example?
i am already u8sing the Unityngine library, but Unity sais it's ambiguous if i dont put that?
did i mess something in the instalation process?

short hazel
gaunt ice
#

delete the numerics namespace

glossy eagle
# keen dew You'll have to elaborate

Like, I am trying to make a system so the player can rebind the actions. The problem I had with the default unity rebinding was that it wouldn't let the player rebind to "space" or "ctrl+space", as it performed the rebind before another key was pressed. So I was trying to make a system where it first read all the keys and then created a composite binding based on how many keys the player had pressed. The problem was that I don't know how many keys the player will press so I don't know how to do that😅

wicked thistle
#

Thank you!

short hazel
glossy eagle
short hazel
#
var binding = action.AddCompositeBinding("");
foreach (var thing in things)
{
    binding = binding.With(thing.Axis, thing.Path);
}
glossy eagle
#

ohhhhhhhh okay thank you so much, I didn't know that was possible 😄

woeful hedge
#

I've drawn a raycast to the location of two objects, but they often don't get hit by the ray. What am I doing wrong?

#
    GameObject CheckSights(Vector3 myPos)
    {
        Collider[] targets = Physics.OverlapSphere(myPos, SightRadius);
        foreach (Collider targetObj in targets)
        {
            //Debug.Log(targetObj.gameObject.name);
            if (targetObj.gameObject.layer == 7)
            {
                RaycastHit[] hits = Physics.RaycastAll(myPos, (targetObj.gameObject.transform.position - myPos).normalized, Vector3.Distance(myPos, targetObj.gameObject.transform.position));

                Log("HitBefore -" + hits.Length.ToString());
                RaycastHit[] hitsBetween = Array.FindAll(hits, obj => obj.transform.gameObject != gameObject && obj.transform.gameObject != targetObj.gameObject);
                bool isFirePossible = false;
                Log("HitAfter -" + hits.Length.ToString());
                Log("HitBet -" + hitsBetween.Length.ToString());
                ...
lilac crow
#

any thought about why im geting this error for Enqueue in this code?
(im following a tutorial)
https://gdl.space/cavubucagi.cs
'string' does not contain a definition for 'Enqueue' and no accessible extension method 'Enqueue' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

short hazel
#

Consider using the C# naming conventions and not naming local variables with an uppercase first letter. Also it's one sentence, so it should not be plural: foreach (string sentence in dialog.Sentences)

lilac crow
verbal dome
#

Also side note, you can shorten a lot of that by using transform instead of gameObject.transform and vice versa

faint sluice
wicked thistle
#

how do i instantiate cubes in a hollow rectangle pattern?
is there a known method?

verbal dome
wicked thistle
#

yes

#

i cant figure out the matrix algorytm

verbal dome
#

Vector maths

#

To get an offset for a side, use half of the main cube's size in the given axis

#

If your cube's X size is 3 then you would spawn the right side cube at X 1.5

wicked thistle
#

Thank you!

faint sluice
#

I would maybe recommend create one in editor, the way you want it to look , copy position/rotation/scale and instantiate that way

wicked thistle
#

the things is......i want to make a chain of slabs with rigid body components attached and hinge joints. Then i want that chain to be a closed loop and put in a hollow square pattern on the YZ plane while the slabs are horizontal and each one of them is looking at the next one in front

#

that's why i wanted to know how to arrange them

blazing estuary
#

can someone help me, i need to make my camera constantly face an object but i don't remember how to.

verbal dome
#

You should google it next time

#

Very common stuff

blazing estuary
#

i didn't know how to say it

paper sable
#

Hey, I'm making the movement for my game but if i hold W i only walk forward once (in the video i first hold W and then i spam it)

earnest atlas
#

code

paper sable
#
private void Start()
    {
        rb = GetComponent<Rigidbody>();
        rb.freezeRotation = true;

        GameManager.input.Player.Move.performed += Move;
    }


    private void Move(InputAction.CallbackContext ctx)
    {
        Vector2 input = ctx.ReadValue<Vector2>();

        moveDirection = orientation.forward * input.y + orientation.right * input.x;

        rb.AddForce(moveDirection * moveSpeed * 10f, ForceMode.Force);
    }
swift crag
#

That's because you're only moving in response to the performed event of the Move action

#

If you want to continuously check the value of the Move action, just do this in FixedUpdate:

earnest atlas
#

yeah you need to get vector like that

#

and movement on FixedUpdate

swift crag
#

var moveInput = GameManager.input.Player.Move.ReadValue<Vector2>();

#

Since this is a continuous input, it's reasonable to read it in FixedUpdate.

paper sable
#

i fixed it now, thanks!

swift crag
#

I used to do it like you did in your code, but it turns out to be kind of awkward -- you have to remember the last value you got from a performed or cancelled event

#

I subscribe to performed for non-continuous actions, like jumping and using items

earnest atlas
#

Is there like any pros of subscribing to an event against just reading it?

swift crag
#

If you don't subscribe to performed, then you'd have to constantly check action.WasPressedThisFrame() in Update

blazing estuary
#

just had to check unity guide

swift crag
#

using events lets you just write methods that run when the action fires

jagged marlin
#

Hey, I have a problem with the Animations of my Sword. The Sword is a child object of the Character and so i cant animate both together right? I feel like I have to animate both objects indepently and make it somehow work this way but I have no Idea how to implement that. I'm somewhat new to Unity and so i dont know if there is a nice way to fix that. Thank you!

woeful hedge
vast saffron
#

why does it take me to the bottom of the line when i press enter

#

shouldn i be above //

#

like right above

#

here?

woeful hedge
#

seems normal i think

swift crag
#

given the squiggle after the {

faint sluice
# woeful hedge

There's no object between yellow line, what's expected result?

vast saffron
#

i mean i didnt touch it

#

i just opened a new C# file

#

its the code that comes up first

swift crag
#

there's an error, so you probably modified something

#

share the entire script !code

eternal falconBOT
faint sluice
vast saffron
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Test-1 : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
swift crag
#

invalid syntax.

#

names cannot contain the - character

#

Test-1 is not a valid class name

vast saffron
#

oh

#

okay

swift crag
#

The parser has no idea what's going on at that point

vast saffron
#

yea

swift crag
#

Syntax errors often cause errors in multiple places

vast saffron
#

imma edit the file name

swift crag
#

file names should generally just be PascalCasedNames

#

since, for a MonoBehaviour, the file name should match the class name

#

and that's how you write class names

vast saffron
woeful hedge
vast saffron
#

why is it saying Test-1

#

when i renamed it

#

imma jus remove the -

swift crag
#

renaming the file just renames the file

woeful hedge
#

very true

swift crag
#

renaming dog.png to cat.png wouldn't turn it into a cat photo

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

public class Test1 : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        int console.print(hi)
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
swift crag
#

😛

blazing estuary
#

Can someone tell me what the variable type for TMP text is?

vast saffron
#

how do i do these things

swift crag
#

Although, it is possible for your IDE to rename the file for you and change the class name, I believe

swift crag
vast saffron
#

i can only do this

#

""

swift crag
#

lower-case tilde

blazing estuary
#

Its TMPro. something but i dont know what

woeful hedge
blazing estuary
vast saffron
#

``

#

ohh

#

ok

#

thanks

vast saffron
#

for the help @swift crag

swift crag
#

but yes, use TMP_Text

swift crag
#

That covers both TextMeshPro (non-UI) and TextMeshProUGUI (UI)

blazing estuary
blazing estuary
#

'''

vast saffron
#

learning how to code is so much more fun while doing it in unity

swift crag
#

There are differences, but they usually don't matter, hence you usually use TMP_Text

faint sluice
#

Same, always using TMP_Text cuz of versatility

warm anvil
#

Good morning. I have a basic logic problem. I'm using Unity's new Input System with a gamepad and wanting to keep the code so that it can leverage the ability to change key mapping in the Input system manager (aka not hardcode keybindings in the code.

My real scenario is that I wish to have an inventory UI open when I press the East button on the gamepad. I also wish to have the same East button close the inventory if it's open. Unfortunately since both tests for logic are in the Update() method, it interprets both actions one after another several times while I am pressing the button a single time. I'd rather not use something crude like a delay timer to calculate the last time the inventory was opened and/or closed to allow the opposite.

Is this simply a known phenomenon and perhaps developers simply chose a different button to open vs. close an element like a menu?

Here's some code but not sure if it will assist with the main idea:

    void Update()
    {
        if (playerBackpackPanel.gameObject.activeInHierarchy && _input.BackpackActionIsPressed)
        {
            playerBackpackPanel.gameObject.SetActive(false);
            Debug.Log("closing backpack");
        }

        if (!playerBackpackPanel.gameObject.activeInHierarchy && _input.BackpackActionIsPressed)
        {
            playerBackpackPanel.gameObject.SetActive(true);
            Debug.Log("opening backpack");
        }
    }

Thanks in advance for any closure to the basic logic idea(s) or even some spoon-fed code if you wish!

swift crag
#

just use an else if!

#
  • if open and pressed, close
  • else, if closed and pressed, open
warm anvil
#

....this is why coffee exists 😛

swift crag
#

zap

warm anvil
#

ty Fen, sometimes I wonder about myself

swift crag
#

you're correct that a "delay timer" would be a bad idea

#

that just invites Weird Problems

blazing estuary
#

hey uh, how to change TMP text, i just can't find anything on that

swift crag
#

you mean how to change the text it's displaying?

#

i have to admit that it's really hard to find specific things in the new-style documentation pages

#

i had to scroll down quite a bit

blazing estuary
#

yeah thank you

swift crag
#

also that's an ancient version oops

#

that's a little better

warm anvil
warm anvil
#

you have to click and drag your TMP object in teh heirarchy into your script for it to work ofc

blazing estuary
#

ill try both, thank you

timid saffron
timid saffron
#

why is this not blue?

swift crag
#

it has no body and it's not inside a class

vast saffron
#

should i enable this?

swift crag
#

the parser is very upset

blazing estuary
swift crag
warm anvil
swift crag
#

or did you accidentally click a button

vast saffron
blazing estuary
vast saffron
swift crag
timid saffron
swift crag
#

just hit cancel

vast saffron
#

after i started my code

#

alright

swift crag
#

If you do enable debugging, it makes the game run a bit slower

blazing estuary
swift crag
#

you can turn it back off with the bug icon in the bottom right corner of the editor

blazing estuary
#

its not

blazing estuary
timid saffron
#

inside public class

swift crag
#

inside a class

#

classes are very often public, but that's not relevant here

blazing estuary
#

exactly

timid saffron
swift crag
#

Every method must be defined inside of a class.

blazing estuary
timid saffron
#

it doesnt

#

its not blue

verbal dome
#

It says Unity message though

blazing estuary
swift crag
#

i'm not sure what the criteria is for coloring it

blazing estuary
#

trust me

#

thats how it is

swift crag
#

but yes, "Unity Message" means that the IDE recognizes that this is a unity message

verbal dome
#

So it detects it. Not sure why its not blue, or if its even supposed to be

swift crag
#

i.e. a method Unity will invoke when a condition is met

blazing estuary
#

only MonoBehaviour methods are blue

swift crag
#

It's probably upset that it's an empty method

blazing estuary
#

urs are yellow

swift crag
#

the dots mean the IDE has a suggestion

verbal dome
#

Maybe its not blue because it is from UnityEngine.Object, not MonoBehaviour

swift crag
#

Ah, perhaps that's it

timid saffron
#

ok i fixed it 👍

swift crag
#

(since it's, indeed, a message for any unity object)

blazing estuary
#

i tried it myself

timid saffron
blazing estuary
swift crag
#

Empty methods will still get invoked by Unity

verbal dome
#

Its still empty though?

swift crag
#

so it's worth removing them if they aren't needed

blazing estuary
swift crag
verbal dome
#

What fixed the color?

blazing estuary
#

ig

timid saffron
#

writing fdokgfd then deleting it fixed it

blazing estuary
vast saffron
#

anyone have a good yt tutorial for c# unity?

verbal dome
swift crag
#

it might be a bit lazy in updating the colors

short hazel
#

It's probably the syntax colorizer not being fast enough, typing more will make it react as it has to update the document

vast saffron
#

completely beginner

swift crag
#

seems like a very poor format for learning programming

vast saffron
#

i dont have them

swift crag
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

stuck jay
vast saffron
#

oh ok there is a tourt

#

tour

#

thanks

#

imma go through it

verbal dome
#

Game Maker's Toolkit's flappy bird video is a decent introducion tbh. If you insist on learning from youtube

stuck jay
#

That also works

swift crag
#

i made a flappy bird game in unreal as my first project in that engine

stuck jay
#

But it teaches you the absolute basics

timid saffron
#

I dont recommend gamemaker c# and gml is completely different 😄

swift crag
#

flappy bird is eternal

vast saffron
swift crag
#

it's a youtube channel

#

it isn't just about the GameMaker engine

stuck jay
#

And game design in general

vast saffron
#

wich one do i need

#

for c#

stuck jay
vast saffron
#

oh nvm

#

its just unity basics right?

stuck jay
#

Unity and coding basics

blazing estuary
#

is it bad to use legacy text??

stuck jay
#

Nothing wrong with using it, especially if you aren't planning on using Text Mesh Pro's features

blazing estuary
#

ok

stuck jay
#

Though keep in mind, Unity replaced it for a reason

blazing estuary
#

why

buoyant knot
#

you should only use TMPro, not Text components

#

do not bother

stuck jay
buoyant knot
#

TMPro is Text, but better in every way

#

and not harder to use, either

short hazel
#

Yeah it has more settings, like character spacing, vertical alignment, shading, outline etc.

#

And it's not blurry when you make it big

blazing estuary
#

at least for me

#

i can't figure out how to change text

#

no matter where i look

#

i may be dumb

buoyant knot
#

you probably need to know the right namespaces for each component

warm anvil
#

are you talking about the value for text?

verbal dome
#

I dont see how it is easier. It is pretty much the same as legacy + the whole font asset thing

blazing estuary
vast saffron
#

where can i find assets like charackters? wherer do i download em

buoyant knot
#

to use TMPro, you need to use using TMPro or something

short hazel
#

In code, it's the exact same as the old one. Only the variable type change

verbal dome
#

For me the reason to use it is quality

blazing estuary
short hazel
#

TMP_Text instead of Text

warm anvil
blazing estuary
buoyant knot
verbal dome
buoyant knot
#

i forget the exact name

#

also I think the name of the component is TMProGUI or something

#

once you have that, it is trival

#

do not waste time learning the normal Text. It is a complete waste of time

buoyant knot
#

any font needs you to make a material for it, tho

#

which isn’t hard, but it’s a step you need to do per font

#

you can’t normally just use whatever font anyway

blazing estuary
#

yeees it works

warm anvil
#

whoops forgot the TMModule but you get the idea 🙂

#

public TextMeshProUGUI myText;

warm anvil
# swift crag just use an `else if`!
        if (playerBackpackPanel.gameObject.activeInHierarchy && _input.BackpackActionIsPressed)
        {
            playerBackpackPanel.gameObject.SetActive(false);
            Debug.Log("close backpack");
        }
        else if (!playerBackpackPanel.gameObject.activeInHierarchy && _input.BackpackActionIsPressed)
        {
            playerBackpackPanel.gameObject.SetActive(true);
            Debug.Log("open backpack");
        }

think I'm in the same boat, opens [by the 2nd clause] then closes when it ticks the next update

#

what's the snake that's about to bite me here.

faint sluice
#
If(_input.BackpackActionIsPressed)
{
playerBackpackPanel.gameObject.SetActive(!playerBackpackPanel.gameObject.activeInzheirarchy);
}
warm anvil
#

I don't think using a 2nd bool condition would get me out of the update tick issue

#

do I not need the 2nd condition then Sexy?

vast saffron
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

faint sluice
warm anvil
#

hmmm, i'll give it a shot, ty!

#

sorry is quala a bot?

#

or a real person just being somewhat sarcastic

faint sluice
paper sable
#

how can i add those show/hide arrows to my script headers?

timber tide
#

make nested classes

faint sluice
warm anvil
wintry quarry
faint sluice
paper sable
faint sluice
#

Like
gameObject.SetActive(condition);

Instead of
if(condition)
Active
Else
Inactive

warm anvil
#

preciate the example

swift crag
faint sluice
swift crag
#

it's just setting foo to !foo

rich bluff
#

just to note that is not a dynamic bool, dynamic in c# is a very specific thing and i never heard anyone refer to a member bool as dynamic, im just saying its not a common term to use

swift crag
faint sluice
paper sable
swift crag
#

dynamic has a very special (frightening) meaning, yes

faint sluice
#

Just said whatever first came to mind lol

swift crag
#

i don't know how your input class works, so i can't say for sure

warm anvil
swift crag
#

no, because those methods are on InputAction

#

Keyboard.current is just a convenient way to directly use the keyboard

faint sluice
swift crag
#

Keyboard.current.escapeKey is a KeyControl with a wasPressedThisFrame property

#

If you use that, then yeah, you'll only care about when the escape key on the keyboard is hit

warm anvil
#

wait a sec, I could have sworn I tried that.... this is valid?

_input.BackpackActionIsPressed.wasPressedThisFrame

swift crag
#

I have no idea what BackpackActionIsPressed is

#

that's your own code

#

if that's a bool, then no, that would be invalid, since bool doesn't have a wasPressedThisFrame property on it

warm anvil
#
    private void SetBackpackAction(InputAction.CallbackContext context)
    {
        Debug.Log(context.phase);
        BackpackActionIsPressed = context.started;
        BackpackActionIsReleased = context.canceled;
    }

this is my input handler

swift crag
#

yeah, you're just setting those bools to true and false

swift crag
#

consider something like this

#
[SerializeField] InputActionReference backpackActionReference;
public bool ToggleBackpack => backpackActionReference.action.WasPressedThisFrame();
#

ToggleBackpack is a property that will run a method when you read it

#

That method checks if the backpack action was pressed this frame

#
if (_input.ToggleBackpack) { ... }
warm anvil
#

ty man, i'll absorb this as well. preciate both of you!

swift crag
#

you would need to assign a reference to the backpack action in the inspector for the input component

stark flint
#

hello the bit of my script that is not commented about collision is not working, why?

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

public class CowboyAnimationScript : MonoBehaviour
{
    // Start is called before the first frame update

    public Animator cowboyAnim;
    public Transform lookObject;
    public float maxTurnSpeed = 50f;
    public float movementSpeed;
    public float damageAmount;
    public bool walkCurrently  = true;


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

    void Start()
    {
        
    }
    void OnCollisionEnter(Collision collision) {
        Debug.Log("Entered collision with " + collision.gameObject.name);
    }
    //private void OnCollisionEnter(Collision collision) {
        //Debug.Log("Entered collision with " + collision.gameObject.name);
        //if (collision.gameObject.name.Contains("Cowboy 1.1")) {
            //walkCurrently = false;
        //}
    //}
    
    //private void OnCollisionExit(Collision collision) {
    //    if (collision.gameObject.name.Contains("Cowboy 1.1")) {
    //        walkCurrently = true;
    //    }
    //}
    
    private void Update() {
        Vector3 direction = lookObject.position - transform.position;
        transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(direction), maxTurnSpeed * Time.deltaTime);
        if(walkCurrently == false) {
            cowboyAnim.SetBool("walk", false);
        }
        if (walkCurrently == true) {
            cowboyAnim.SetBool("walk", true);
            transform.position += transform.TransformDirection(Vector3.forward) * Time.deltaTime * movementSpeed;
        }
    }
}
swift crag
#

It sounds like you already have a PlayerInput component on it, so you won't need to enable the action yourself

swift crag
#

go through these pages

#

they'll walk you through the places you need to check

faint sluice
swift crag
#

(well, those are the commandments of a trigger message)

faint sluice
swift crag
#

The rules are different. Notably, two kinematic rigidbodies won't collide

faint sluice
#

Just commandment 2 is toggled

#

Ah true, wait lemme go grab the 3 commandments for collision lmao

warm anvil
#

"thou shall not touch thyself"

faint sluice
#

There we go

swift crag
#

and that's 2D!

stark flint
#

that worked

#

tysm

swift crag
#

we've got like 12 commandments

#

I used to struggle with collision and trigger messages

#

since I didn't read the dang instructions

#

that really helped :p

blazing estuary
#

can someone tell me how to access rigidbody in the class

swift crag
#

"in the class"?

blazing estuary
#

in the script

#

i meant

swift crag
#

I presume you have a class that inherits from MonoBehaviour, and that you're writing a method in that class.

#

Where is this Rigidbody?

#

Is it attached to the same object as your component?

swift crag
#

add a field to your class

blazing estuary
#

is there a doc for rigidbody

swift crag
#
[SerializeField] Rigidbody rb;
#

drag the Rigidbody component into this field in the inspector

blazing estuary
swift crag
blazing estuary
#

ok

swift crag
#

it's a field, just like any other field

#
private int x;
public float y;
[SerializeField] GameObject z;
protected string w;
#

[SerializeField] makes it appear in the inspector.

warm anvil
#

if it's a 2D game you can use Rigidbody2D

stark flint
#

do u know why it is not stopping when it touches the XR Rig ```using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CowboyAnimationScript : MonoBehaviour
{
// Start is called before the first frame update

public Animator cowboyAnim;
public Transform lookObject;
public float maxTurnSpeed = 50f;
public float movementSpeed;
public float damageAmount;
public bool walkCurrently  = true;


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

void Start()
{
    
}
private void OnCollisionEnter(Collision collision) {
    Debug.Log("Entered collision with " + collision.gameObject.name);
    if (collision.gameObject.name.Contains("XR Origin (XR Rig)")) {
        walkCurrently = false;
    }
}

private void OnCollisionExit(Collision collision) {
    if (collision.gameObject.name.Contains("XR Origin (XR Rig)")) {
        walkCurrently = true;
    }
}

private void Update() {
    Vector3 direction = lookObject.position - transform.position;
    transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(direction), maxTurnSpeed * Time.deltaTime);
    if(walkCurrently == false) {
        cowboyAnim.SetBool("walk", false);
    }
    if (walkCurrently == true) {
        cowboyAnim.SetBool("walk", true);
        transform.position += transform.TransformDirection(Vector3.forward) * Time.deltaTime * movementSpeed;
    }
}

}

swift crag
#

log when you exit too

#

perhaps it's immediately exiting

stark flint
#

wdym

swift crag
#

I mean to log when OnCollisionExit runs.

stark flint
#

ok ill try that

glass crest
#

Hello, I'm trying to add hold effect using the new input system, where a function keeps running as long as I'm holding a button, how can I do that? here's what I have atm

swift crag
#

don't respond to performed, then

#

what is shootingAction?

#

what type is that variable?

glass crest
#

Oh sorry, so this is the InputAction "Fire"

swift crag
#

just an InputAction? that means you're directly configuring it in the inspector

glass crest
swift crag
#

Oh wait

#

My bad, that's correct. I missed the second line of Awake

glass crest
#

It's okay

swift crag
#

Okay, so all you need to do is check if IsPressed() is true

#

do that in Update

swift crag
# glass crest

(you should make shootingAction private, so that it doesn't clutter the inspector)

#

if (shootingAction.IsPressed()) { ... }

glass crest
#

I'll do that

swift crag
#

also, note that you're subscribing to started and then unsubscribing from performed, which doesn't match!

#

you can remove those entirely, since you aren't going to be listening for events

glass crest
stark flint
woeful hedge
swift crag
stark flint
swift crag
#
Ray ray = new(myPos, theirPos - myPos);
float distance = Vector3.Distance(myPos, theirPos);
#

e.g.

#

that won't fix anything, but it'll make the rest of the work easier!

glass crest
#

@swift crag it worked, thank you

queen adder
#

Snas. You here?

nimble hinge
#

Yup

queen adder
#

private void Update()
{
if (Input.GetKeyDown(pressUp)) {
_direction = Vector2.up;
GetComponent<Transform> ().eulerAngles = new Vector3 (0, 0, 0);
} else if (Input.GetKeyDown(pressDown)) {
_direction = Vector2.down;
GetComponent<Transform>().eulerAngles = new Vector3(0, 0, 0);
}
else if (Input.GetKeyDown(pressLeft)) {
_direction = Vector2.left;
GetComponent<Transform>().eulerAngles = new Vector3(0, 0, 0);
}
else if (Input.GetKeyDown(pressRight)) {
_direction = Vector2.right;
GetComponent<Transform>().eulerAngles = new Vector3(0, 0, -90);

 }

}

#

You wanted this right?

nimble hinge
#

Sure, if you dont mind

queen adder
#

I don't. It's not like it's mine.

nimble hinge
#

private void Update()
{
if (Input.GetKeyDown(pressUp)) {
_direction = Vector2.up;
transform.eulerAngles = direction;
} else if (Input.GetKeyDown(pressDown)) {
_direction = Vector2.down;
transform.eulerAngles = direction;
}
else if (Input.GetKeyDown(pressLeft)) {
_direction = Vector2.left;
transform.eulerAngles = direction;
}
else if (Input.GetKeyDown(pressRight)) {
_direction = Vector2.right;
transform.eulerAngles = direction;

 }

}

#

lets try this

queen adder
#

Direction doesn't exist in current context. Do i have to add something?

nimble hinge
#

well

#

just add vector3 _direction

eternal falconBOT
nimble hinge
#

maybe you forgot to copy that from tutorial

stark flint
#

does anyone know what my problem is

willow scroll
stark flint
#

well im just asking

nimble hinge
#

is it rule violation to post it raw?

#

or what

queen adder
willow scroll
queen adder
#

Oh.

nimble hinge
#

just write Vector3 _direction there

nimble hinge
#

okay

queen adder
#

Where the direction is?

willow scroll
queen adder
#

Like just add it?

stark flint
#

because i posted it earlier on

#

not to far up

nimble hinge
#

you see

{

}```
right?
#

just after that bracket

#

write

#

Vector3 _direction;

#

with semicolon too i forgot

willow scroll
stark flint
willow scroll
stark flint
#

look at the series of questions

stark flint
#

and u will be able to help

willow scroll
# queen adder

Your issue is obvious. You first have to learn some basics. !learn

nimble hinge
eternal falconBOT
#

:teacher: Unity Learn ↗

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

queen adder
nimble hinge
nimble hinge
queen adder
nimble hinge
#

noooo

#

you did it wrong way

#

Do Vector3 _direction

willow scroll
nimble hinge
#

not Vector3_ direction lol

queen adder
#

11 errors.

willow scroll
#

They first should learn C# syntax.

nimble hinge
#

show me what did you do lol

swift crag
#

what is a Vector3_?

#

the compiler clearly doesn't know what a Vector3_ is

nimble hinge
queen adder
nimble hinge
#

and forgot a variable

nimble hinge
#

You had that variable whole time?

swift crag
# queen adder

the first error is explicitly telling you that the compiler has no clue what a Vector3_ is

nimble hinge
#

you're sneaky haha

#

it looks like you have

#

just change vector2 to vector3

queen adder
#

OOOOOHHHHHHHHHHHHH

willow scroll
#

it's just gonna slow down the process

queen adder
#

Still 11 errors. :///

nimble hinge
#

remove the previous thing i made you write

queen adder
#

Kay.

swift crag
#

read the error message. it explicitly tells you what the problem is.

nimble hinge
#

that Vector3 _direction

swift crag
#

you can't just see errors and give up

nimble hinge
#

yo fen remember me

#

i was having rendering issue

queen adder
nimble hinge
#

show me the screenshot

#

ill tell you where to remove something

swift crag
#

The compiler does not enjoy this.

nimble hinge
#

i have this, i installed urp and prefabs are not okay. their materials are changed. im confused why (this is 2D)

#

is it because of my code?

swift crag
#

right click and reimport the prefab first

#

the preview could just be stuck

nimble hinge
#

does not work

swift crag
#

then the prefabs use a material that is incompatible with URP

swift crag
#

pick one and look at the shader it's using

nimble hinge
#

I'm using right material

swift crag
#

click on it to find out what shader it actually uses

queen adder
rich adder
queen adder
#

what is that.

rich adder
#

read the error

swift crag
#

again, you must actually read the error messages

nimble hinge
#

you see

swift crag
#

the compiler is telling you exactly what is wrong

nimble hinge
#

there are 2 variables with same name

#

and compiler cant tell the difference

queen adder
#

Okay now only the direction; is an error.

rich adder
#

bro you need some basics c#

rich adder
#

Knowing why it error is more important than fixing something that will break again

nimble hinge
#

the crazy thing is

#

it works in game, and scene

#

but prefab preview is the one that is stuck

swift crag
#

hm, it might be "Refresh" that you need

#

in the right click menu

nimble hinge
#

doesn't seem to do anything

swift crag
#

otherwise, I'd just throw a fit and do a Reimport All

#

that'll take a bit

nimble hinge
#

alright

swift crag
#

I've had strange prefab preview problems in the past

nimble hinge
#

it's weirdly confusing

nimble hinge
queen adder
nimble hinge
#

also compiler is designed in such way to tell you, whats wrong, not to only say, you made something wrong

queen adder
#

The name "direction".

swift crag
#

well, did you declare a variable anywhere named direction?

nimble hinge
#

did you change your

rich adder
nimble hinge
#

_direction to direction

rich adder
#

you need basic c#

nimble hinge
#

meaning, you removed underline

rich adder
#

fix one thing, you break another and come back

swift crag
#

i agree with navarone. we can't just write the entire script for you one line at a time over Discord

#

you need to actually learn how to do this stuff, properly

#

hence, !learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

queen adder
#

Thanks.

nimble hinge
#

you're welcome

rich adder
#

see ya when it breaks again UnityChanLOL

nimble hinge
queen adder
#

My man's head isn't moving.

#

My game is 2D.

rich adder
hasty vault
#

Im getting this error when trying to make a animation event, someone knows what is wrong? im extremely new to unity.

queen adder
#

Maybe that was important.

nimble hinge
#

wait

#

WAIT

#

you see this code right

#

look below

queen adder
#

Yeah.

nimble hinge
#

so you have _direction = vector3.right

#

and transform.eulerAngles = direction

queen adder
#

Mhm.

nimble hinge
#

without underline

#

how is that possible lol

rich adder
#

because euler angles is a v3

nimble hinge
#

it didnt give you an error?

nimble hinge
queen adder
#

I put the underline under the directions.

nimble hinge
#

but variable name

#

is the one

short hazel
wintry quarry
#

probably a third variable with the name direction 😝

queen adder
#

Yeah my head isn't turning.

#

There isn't an error however.

nimble hinge
#

How in the-

#

okay so

#

you have direction and _direction

#

both at the same time

#

I'm just confused about this thing

queen adder
nimble hinge
#

ohhhh

#

i see, smart

#

anyway you see those transform.eulerAngles right

swift crag
nimble hinge
#

just multiply them by 90

swift crag
#

if you don't target an Image method, it should be fine.

queen adder
#

Where?

#

The direction?

swift crag
#
Quaternion.FromToRotation(Vector3.up, _direction);

This computes a rotation from the +Y direction to whatever _direction is

#

This should be appropriate for a 2D object.

queen adder
nimble hinge
#

i just noticed

#

the code

vast saffron
nimble hinge
#

you're using transform.eulerAngles i see

swift crag
#

oh, you know, I just remembered

#

you can assign to transform.up

#
transform.up = _direction;

this will make the transform face that direction

vast saffron
#

why am i a bot @warm anvil

nimble hinge
#

exactly

#

fen is right

swift crag
#

it'll align the "up" direction with the vector you give it

nimble hinge
#

oh thank you fen

#

after reimporting all

#

it somehow

#

fixed the issue

swift crag
#

i dunno what the pipeline is for creating a prefab preview

nimble hinge
#

I can't believe how simple reimport does nothing

daring basin
#

I was making a script where when you press a button, it would bring the user who clicked it to a YouTube Channel. But when I went on the "OnClick()" section of the button, it did show OpenURL but when I hovered on it, it only showed the normal functions, not the one that I added.

nimble hinge
#

and reimport all does

swift crag
#

it must have missed some other change

swift crag
wintry quarry
swift crag
#

looks fine to me

rich adder
swift crag
#

i was curious if that would make Unity mad

nimble hinge
#

just hover over this

warm anvil
# vast saffron why am i a bot <@266990656122126357>

I realize text is always a 2D conversation and I wasn't sure if you were talking to me directly when your message just said "Learn". Based on context is came across in so many words "RTM or figure it out yourself". Sorry if I misinterpreted.

nimble hinge
#

and you will see something like

#

"OpenURL"

#

and press that

rich adder
daring basin
swift crag
#

Bingo.

#

Your IDE isn't configured to show errors

#

and you have compile errors.

rich adder
#

yup

nimble hinge
swift crag
#

Fix your IDE. !ide

eternal falconBOT
vast saffron
daring basin
vast saffron
#

all good

rich adder
nimble hinge
#

okay, did you save the script

rich adder
#

You have compile errors

rich adder
#

they have errors

swift crag
#

the code will never work as-is

nimble hinge
swift crag
#

i suppose you wouldn't see any errors if the file wasn't saved, yes!

nimble hinge
#

I think there should be nothign wrong with "Application.OpenURL

swift crag
#

That's fine.

#

It's the method named OpenURL

#

It matches the name of the type, which is forbidden

nimble hinge
#

yup

daring basin
nimble hinge
#

just change it to something else

rich adder
nimble hinge
#

"OpenLink"

#

or whatever

queen adder
#

Snas...

nimble hinge
#

wassup

rich adder
verbal dome
#

URLOpener

queen adder
#

I deleted the code. What do i do it won't work.

nimble hinge
#

okay, i want to ask this so bad

#

what tutorial did you watch lol

#

this code was garbage

swift crag
#

"I deleted the code"

#

this could mean basically anything

nimble hinge
#

"GetComponent<Transform>()" literally made me laugh 10 times

queen adder
#

But seriously why is it hard to rotate a block.

#

Or a sprite.

nimble hinge
#

That code. is garbage.

rich adder
#

because you lack the basics

#

you are trying to run before knowing how to walk

wintry quarry
nimble hinge
queen adder
#

Yeah. How do i learn the basics.

swift crag
#

you're trying to build an alarm clock when you don't know what a battery is

nimble hinge
#

you just understand it hard way

swift crag
#

by using !learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

swift crag
#

there will not be a tutorial for how to make the exact kind of game you want to make

#

but you will learn how to express your ideas in code

nimble hinge
#

well said, Fen

queen adder
#

hi im looking on how to code does anybody have good youtube tutorials i cloud use?

queen adder
nimble hinge
#

can you just first

swift crag
#

you will probably not be shown how to rotate a sprite based on a direction input

nimble hinge
#

try to learn

#

what transform is

swift crag
#

you will learn how to write code

#

and how to implement really fundamental ideas

rich adder
#

including sprite renderer and rotating objects

queen adder
#

So yes.

nimble hinge
#

transform, you see a component that every object has, if you rotate an object, which axis do you do. you just write it same way but in code.

queen adder
#

Okay.

#

Is that free? Like the tutorial?

rich adder
#

they're all free mate

queen adder
#

Fine. I will try if you suggest it.

#

But writing code is hard i doubt i will learn anything from those tutorials.

rich adder
polar acorn
timid saffron
#

that should help you

swift crag
summer stump
timid saffron
#

thats what i do

swift crag
#

If you've already concluded that you will never learn anything, why are you even trying?

rich adder
swift crag
#

I think you can.

queen adder
timid saffron
rich adder
queen adder
#

How did you learn to code?

rich adder
queen adder
#

How long did it take you to make your first game?

swift crag
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

swift crag
#

gonna keep hammering on this drum until you listen

#

just do it

#

go make a tiny little game with one of those courses

rich adder
verbal dome
#

I wish there was Unity learn when I was starting out

faint sluice
#

As a beginner I would stay the heck away from AI as much as possible

rich adder
queen adder
#

Hope i'm not too late to get into coding.

timid saffron
verbal dome
#

I used since like 2016 but only got to know about Learn when I joined this server lol

rich adder
queen adder
#

Okay.

timid saffron
#

you can google but ai already googles and gives best answers to you

queen adder
#

But realistically. How hard would it be to make a game like "Faith"?

vast saffron
#

how do i know if a unity tutorial is based on C#?

faint sluice
rich adder
faint sluice
#

They do pretty good job explaining

timid saffron
rich adder
swift crag
rich adder
#

"based on c#"

swift crag
#

Unity ditched Boo and UnityScript a LONG time ago

blazing estuary
#

how to send code

#

what are the symbols

rich adder
eternal falconBOT
timid saffron
#

when

vast saffron
timid saffron
#

is it advanced codes

#

or basic ones

vast saffron
#

im new dont blame me

#

for smth i dont know

blazing estuary
#
{
    [SerializeField] Rigidbody rb;
    public int jumpStrenght;
    void Start()
    {
        
    }
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            rb.AddForce(transform.up * jumpStrenght * Time.deltaTime);
        }
    }
}
rich adder
blazing estuary
#

why isn't my player jumping?

rich adder
vast saffron
blazing estuary
#

i think this code is fine

faint sluice
# timid saffron for example?

If you've been in this channel for a long time you'll know how often people came here asking for help with their "AI generated code" that was completely beginner level

blazing estuary
#

but its not doing anything

queen adder
#

Like what i did.

faint sluice
#

To the point it became a rule to prohibit helping AI generated code

blazing estuary
#

or

timid saffron
rich adder
#

also use ForceMode.Impulse

faint sluice
blazing estuary
verbal dome
#

Ok im a sloth

rich adder
#

the parameter on the AddForce

#

put a , and you will see it

blazing estuary
#

thanks

verbal dome
#

Did that deltatime come from a tutorial?

blazing estuary
#

is there a list

blazing estuary
rich adder
blazing estuary
#

just though it put it there

blazing estuary
verbal dome
#

Or not just functions but anything

timid saffron
#

and theres also this sometimes ai lets you down 😄

rich adder
#

guys this isn't a "thinking machine"

#

its just a regurgitation of internet info

#

it doesnt "think" , hence why the coding sucks

verbal dome
#

Why does a bot care about time consumption lol

rich adder
#

fr

#

(I'm tryina save compute time) - microsoft

verbal dome
#

Maybe it literally has a limiter on the processing power

timid saffron
#

also this

#

too sensitive

#

you cant write anymore

rich adder
#

alr lets not get carried with the off-topic

timid saffron
#

yeah

rich adder
timid saffron
#

i didnt realize this was help channel I opened discord and this was the first channel i saw

#

sorry

queen lodge
#

I've just downloaded Unity and made a project but it always gets stuck to this whenever I open the project, I've tried to close it and re-open it multiple times & restart my pc, could anyone help

#

I tried waiting like 20min before

rich adder
#

or it could be some editor script doing something its not supposed to 😛

queen lodge
#

library folder?

summer stump
swift crag
#

yep, that's what I'd do

#

It contains imported data produced from your assets

#

If it gets mangled, Unity can start having a very bad time

queen lodge
#

I can't locate the library folder

verbal dome
#

Open your project folder in the file explorer

#

Not in unity

#

Close unity btw

#

Oh actuallyit might not be there

#

If you havent loaded the project yet

queen adder
rich adder
faint sluice
#

Look at programming this way, when you first learn about probability in school, you don't immediately start exploring something like stockmarket

summer stump
queen adder
#

I want to do something special for my first game.

#

Does the Junior Programmer course last 12 weeks?

rare basin
#

how can we know? it all depends on you

swift crag
#

you keep asking how to do it and we're all telling you to just do it

gleaming wagon
#

Why is my "Score" not being deducted correctly? In fact, its not being deducted at all?

#

I set my dragonprice

#

that is 100% not the issue

rich adder
#

also ur setting the text to dragon price so it not changing

gleaming wagon
frank needle
#

Is it coming back with the “not enough” log? Or is the whole thing not being executed?

gleaming wagon
#

no it works, but the price isnt changing

#

i can show you

rich adder
queen adder
#

can some one help me with my code? I need to show checkpoints in sequence

eternal falconBOT
gleaming wagon
#

btw its all a bit of mess cuz its for a game jam and i only have like 2 days left

rare basin
#

so what's wrong here

rich adder
swift crag
queen adder
swift crag
frank needle
#

As a test, can you make it so instead of taking away the dragon price can you take away a set number? Just to see if it’s the variables fault or not

swift crag
gleaming wagon
#

just its not deducting points

rare basin
#

in the code you provided

frank needle
rare basin
#

so why would it change

queen adder
frank needle
gleaming wagon
rare basin
#

wdym

#

you are not changing the score text

gleaming wagon
#

like its changing in the clip I sent

rare basin
#

not via the code you sent

rich adder
#

show

gleaming wagon
#

ah I see

#

Here is the other script

rich adder
eternal falconBOT
rare basin
#

jezus

rich adder
#

dont use screenshots for code

#

also GPT code

#

🤮

gleaming wagon
gleaming wagon
rare basin
#

btw comments like this, are just making the code more unreadable

rich adder
swift crag
#

If you don't have time to do it right then you'd better have time to do it twice.

rich adder
swift crag
#

We're in the "twice" phase right now

rich adder
frank needle
#

What’s the twice phase?

gleaming wagon
#

So the issue is just the setting text on the script with the buy dragons right?

rare basin
#

thought it's his code at first

swift crag
#

we're now doing it twice (:

frank needle
#

Ah I see

rich adder
gleaming wagon
#

No I swear I usually try to do it myself, but I thought it was too hard and I would mess it up

rare basin
#

to copy-paste shit from chatgpt

rich adder
#

yeah AI hype train is reel

frank needle
swift crag
#

it's good for generating spam

#

unfortunately games aren't made of spam

ripe shard
#

I want copy & paste from stack overflow back

rare basin
#

but yea, nothing code related

gleaming wagon
rich adder
swift crag
#

It should just set the text based on the score every frame.

#

(and maybe set other text elements, too)

frank needle
rare basin
#

or via events

swift crag
#

It shouldn't be responsible for detecting when you gain points

rare basin
#

not neccesary every frame

swift crag
#

That's someone else's job.

gleaming wagon
rich adder
swift crag
#

eh, just setting it every frame is the simplest thing to do here

#

setting the text 100 times per second won't end the world

rare basin
#

yea, in his case that's the easiest and fastest thing to do

rich adder
#

yup

rare basin
#

instead of learning events

rich adder
#

I used to do it too 😅

rare basin
#

everyone did i guess

queen adder
# queen adder cs

some one help me with my code? I need to show checkpoints in sequence

rich adder
#

the power of events ⛈️

thorn holly
#

Are coroutines unity specific or is it available to anything that uses c#?

frank needle
rich adder
#

using IEnumerator cleverly