#💻┃code-beginner
1 messages · Page 177 of 1
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
👍
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
log the tag?
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
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?
Docs
Cant find anything where it sais what it accepts only of what it consists
El Manual de Unity le ayudará a aprender y usar el motor de Unity. Con el motor de Unity usted puede crear juegos 2D y 3D, aplicaciones y experiencias.
I want to get this
Yeah I have guessed it by name.
that was the manual for Unity 5.3. Make sure the version is correct in the top left, and make sure that you're either on the API or Manual in the top right depending on your needs.
Also, if you're not getting autocomplete in your IDE, you need to configure it. !ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
So annoying how Google defaults to old versions
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
tryitandsee.jpg
Yeah its still crused
are they different size sprites? The size should be relative to the grid size you've used inside of the sprite editor
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
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.
no meme pulizzu 
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!
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?
You'll have to elaborate
With a loop? The With methods return the same instance they were called on, so chaining can be done
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?
You don't need using System.Numerics
delete the numerics namespace
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😅
Thank you!
In fact the first 5 usings are grayed out, meaning they're unused and can be removed.
But how do you chain them? Like, where do you put the loop? Before that or...?
var binding = action.AddCompositeBinding("");
foreach (var thing in things)
{
binding = binding.With(thing.Axis, thing.Path);
}
ohhhhhhhh okay thank you so much, I didn't know that was possible 😄
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());
...
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?)
You named the foreach loop variable on line 21 Sentences, the same as the queue on line 7. Local variables are "closer" so it's the one that's detected first
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)
ohhhhhh,
thank you! 😘😘😘😘
More learning for me!
Have you tried to visualize the ray with Debug.DrawRay?
Also side note, you can shorten a lot of that by using transform instead of gameObject.transform and vice versa
Also just in case , your initial array "hits" doesn't change throughout entire process, so if it was 0 in "before" , it would show 0 in "after" as well
how do i instantiate cubes in a hollow rectangle pattern?
is there a known method?
Like 6 cubes that form a hollow cube?
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
Thank you!
I would maybe recommend create one in editor, the way you want it to look , copy position/rotation/scale and instantiate that way

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
can someone help me, i need to make my camera constantly face an object but i don't remember how to.
transform.LookAt
You should google it next time
Very common stuff
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)
code
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);
}
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:
var moveInput = GameManager.input.Player.Move.ReadValue<Vector2>();
Since this is a continuous input, it's reasonable to read it in FixedUpdate.
i fixed it now, thanks!
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
Is there like any pros of subscribing to an event against just reading it?
If you don't subscribe to performed, then you'd have to constantly check action.WasPressedThisFrame() in Update
using events lets you just write methods that run when the action fires
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!
the CheckSights() runs at Coroutine loop so It might be okay
why does it take me to the bottom of the line when i press enter
shouldn i be above //
like right above
here?
seems normal i think
it looks like your code editor is confused by your syntax
given the squiggle after the {
There's no object between yellow line, what's expected result?
so how do i fix it
i mean i didnt touch it
i just opened a new C# file
its the code that comes up first
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
If you hover over the red squiggle it should tell you what's wrong exactly and how to fix it
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()
{
}
}
invalid syntax.
names cannot contain the - character
Test-1 is not a valid class name
The parser has no idea what's going on at that point
yea
Syntax errors often cause errors in multiple places
imma edit the file name
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
I expected
RaycastHit[] hits has two elements (The one who run the script / and targets)
and the hitbetween has no elements
renaming the file just renames the file
very true
renaming dog.png to cat.png wouldn't turn it into a cat photo
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()
{
}
}
😛
yea true
lmao
Can someone tell me what the variable type for TMP text is?
how do i do these things
Although, it is possible for your IDE to rename the file for you and change the class name, I believe
that's a grave
lower-case tilde
Its TMPro. something but i dont know what
TextMeshProGUI i remember
ima try
TMP_Text
for the help @swift crag
TextMeshProUGUI is what you're thinking of
but yes, use TMP_Text

That covers both TextMeshPro (non-UI) and TextMeshProUGUI (UI)
that worked
learning how to code is so much more fun while doing it in unity
There are differences, but they usually don't matter, hence you usually use TMP_Text
Same, always using TMP_Text cuz of versatility
agree
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!
....this is why coffee exists 😛
zap
ty Fen, sometimes I wonder about myself
you're correct that a "delay timer" would be a bad idea
that just invites Weird Problems
hey uh, how to change TMP text, i just can't find anything on that
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
yeah thank you
you can do something like this
public TextMeshProUGUI mainClock;
mainClock.text = date.ToString("ddd")
you have to click and drag your TMP object in teh heirarchy into your script for it to work ofc
ill try both, thank you
already did that
why is this not blue?
the parser is very upset
{}?
are you actually trying to use a debugger?
you have to follow it by {}
or did you accidentally click a button
i dont really know what it is
yeah
accidently
okay, you probably did it by accident
just hit cancel
If you do enable debugging, it makes the game run a bit slower
is it inside the class?
you can turn it back off with the bug icon in the bottom right corner of the editor
its not
oh okay
put it inside the class
inside public class
exactly
Every method must be defined inside of a class.
see now it works
It says Unity message though
its working just do as normal
i'm not sure what the criteria is for coloring it
but yes, "Unity Message" means that the IDE recognizes that this is a unity message
So it detects it. Not sure why its not blue, or if its even supposed to be
i.e. a method Unity will invoke when a condition is met
it doesnt have to
only MonoBehaviour methods are blue
It's probably upset that it's an empty method
urs are yellow
OnDestroy is a Unity message for MonoBehaviours
the dots mean the IDE has a suggestion
Maybe its not blue because it is from UnityEngine.Object, not MonoBehaviour
Ah, perhaps that's it
ok i fixed it 👍
(since it's, indeed, a message for any unity object)
ur right
i tried it myself
this worked
yeah
Empty methods will still get invoked by Unity
Its still empty though?
so it's worth removing them if they aren't needed
yep
👻
What fixed the color?
oh I will write some codes now
writing fdokgfd then deleting it fixed it
oh yeah
anyone have a good yt tutorial for c# unity?
Ah ok
it might be a bit lazy in updating the colors
It's probably the syntax colorizer not being fast enough, typing more will make it react as it has to update the document
completely beginner
i would not suggest just watching youtube videos
seems like a very poor format for learning programming
but i need some basics
i dont have them
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
I'd suggest picking up the C# Players Guide
Game Maker's Toolkit's flappy bird video is a decent introducion tbh. If you insist on learning from youtube
That also works
i made a flappy bird game in unreal as my first project in that engine
But it teaches you the absolute basics
I dont recommend gamemaker c# and gml is completely different 😄
flappy bird is eternal
idc if its on yt i just wanna have a efficient way to learn and understand the basics
no, Game Maker's Toolkit
it's a youtube channel
it isn't just about the GameMaker engine
GMT is a youtube channel that focuses on Unity
And game design in general
First two
Unity and coding basics
is it bad to use legacy text??
Nothing wrong with using it, especially if you aren't planning on using Text Mesh Pro's features
ok
Though keep in mind, Unity replaced it for a reason
why
Easier to understand and has better performance
Yeah it has more settings, like character spacing, vertical alignment, shading, outline etc.
And it's not blurry when you make it big
it is NOT easier to understand
at least for me
i can't figure out how to change text
no matter where i look
i may be dumb
you probably need to know the right namespaces for each component
are you talking about the value for text?
I dont see how it is easier. It is pretty much the same as legacy + the whole font asset thing
yeah
where can i find assets like charackters? wherer do i download em
to use TMPro, you need to use using TMPro or something
In code, it's the exact same as the old one. Only the variable type change
For me the reason to use it is quality
omg really
TMP_Text instead of Text
it's the code I sent you, just change the variable and the thing you want to say is all
whats the command to change text
yeah, you need to import the package, and your code needs to be using the TMPro namespace
does it work for tmp too
Asset store is one place to look
yeah ik
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
thanks
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
yeees it works
public class Test : Monobehavior
{
public string myText;
private void Start()
{
myText.text = "yo";
}
}
whoops forgot the TMModule but you get the idea 🙂
public TextMeshProUGUI myText;
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.
If(_input.BackpackActionIsPressed)
{
playerBackpackPanel.gameObject.SetActive(!playerBackpackPanel.gameObject.activeInzheirarchy);
}
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?
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
In the block I sent everytime you use button it will toggle the state depending on if object was active
hmmm, i'll give it a shot, ty!
sorry is quala a bot?
or a real person just being somewhat sarcastic
Try to use dynamic bool more often, makes everything less messy
how can i add those show/hide arrows to my script headers?
make nested classes
Usually via nested classes i believe
lot for me to learn on vocab, not sure I'm come across a dynamic bool term yet. I'll take a look thanks
Those aren't headers. You either make a nested class or struct, or you write a custom inspector for your script
Like instead of using true/false as is
Use variables instead
im gonna search more about nested classes, but i wanted to know if i could hide/show the Movement/Jumping stuff so i can make my inspector a bit cleaner
Like
gameObject.SetActive(condition);
Instead of
if(condition)
Active
Else
Inactive
preciate the example
We Explained how yes
i would not call this a "dynamic bool"
[hideInInspector] or make it private variable, depending on your use case can work too
it's just setting foo to !foo
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
You need something that's only true once
I know I'm just weak in proper terminology 
i meant to hide them by pressing a button but i guess im gonna have to look into nested classes
dynamic has a very special (frightening) meaning, yes
Just said whatever first came to mind lol
Ahh lmaoo
if you're using the new input system, you'd use WasPressedThisFrame() instead of IsPressed()
i don't know how your input class works, so i can't say for sure
If I'm in the right context, doesn't that hardcode me for a specific type of input device. aka doesn't using WasPressedThisFrame only limited if I did something like Keyboard.current.escapeKey.wasPressedThisFrame
no, because those methods are on InputAction
Keyboard.current is just a convenient way to directly use the keyboard
WasPressedThisFrame is platform indipendent afaik
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
wait a sec, I could have sworn I tried that.... this is valid?
_input.BackpackActionIsPressed.wasPressedThisFrame
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
private void SetBackpackAction(InputAction.CallbackContext context)
{
Debug.Log(context.phase);
BackpackActionIsPressed = context.started;
BackpackActionIsReleased = context.canceled;
}
this is my input handler
yeah, you're just setting those bools to true and false
so this is invalid code
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) { ... }
ty man, i'll absorb this as well. preciate both of you!
you would need to assign a reference to the backpack action in the inspector for the input component
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;
}
}
}
It sounds like you already have a PlayerInput component on it, so you won't need to enable the action yourself
go through these pages
they'll walk you through the places you need to check
3 commandments of collision
#💻┃code-beginner message
(well, those are the commandments of a trigger message)
Same goes for collision too no? 
The rules are different. Notably, two kinematic rigidbodies won't collide
Just commandment 2 is toggled
Ah true, wait lemme go grab the 3 commandments for collision lmao
"thou shall not touch thyself"
and that's 2D!
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
can someone tell me how to access rigidbody in the class
"in the class"?
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?
yes
add a field to your class
is there a doc for rigidbody
[SerializeField] Rigidbody rb;
drag the Rigidbody component into this field in the inspector
where to put this
in your component's class
ok
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.
if it's a 2D game you can use Rigidbody2D
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;
}
}
}
wdym
I mean to log when OnCollisionExit runs.
ok ill try that
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
don't respond to performed, then
what is shootingAction?
what type is that variable?
Oh sorry, so this is the InputAction "Fire"
just an InputAction? that means you're directly configuring it in the inspector
it has nothing to do with whatever you've configured in that second screenshot: that's part of an Input Action Asset
Oh wait
My bad, that's correct. I missed the second line of Awake
I thought I had to add an interaction of some sort in the playerInput
It's okay
(you should make shootingAction private, so that it doesn't clutter the inspector)
if (shootingAction.IsPressed()) { ... }
I'll do that
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
Oh my bad, I was subscribing to performed but I forgot to undo it
So I made it so it only records exiting when u exit contact only with the specific object i want however it exited twice so i dont get the problem
Still dont know what's wrong? does some knows why?
if you're banging into a solid object and stopping, then the collision probably ends immediately
clean that code up to make it easier to read
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!
@swift crag it worked, thank you
Snas. You here?
Yup
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?
Sure, if you dont mind
I don't. It's not like it's mine.
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
Direction doesn't exist in current context. Do i have to add something?
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
maybe you forgot to copy that from tutorial
does anyone know what my problem is
no, why would we?
well im just asking
I copied everything.
No, it's not. I have suggested you to post it this way for better code readability
your readable code goes here
Oh.
You clearly didn't do it haha, basically you know where you declare variables right?
just write Vector3 _direction there
Noooope.
okay
Where the direction is?
I'm just answering. Why would we know what your problem is?
Like just add it?
you see
{
}```
right?
just after that bracket
write
Vector3 _direction;
with semicolon too i forgot
You should've shown it ?
here
Yes, I see those messages in console
look at the series of questions
and u will be able to help
Your issue is obvious. You first have to learn some basics. !learn
add space in between the underline
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
I did. Only one error now.
I think we are here to help him, not to tell him to learn? haha
what does the error say
Exactly, this channel is to help people with Unity issues. They have obvious syntax errors
not Vector3_ direction lol
11 errors.
They first should learn C# syntax.
show me what did you do lol
correct, but he is trying to figure out how to rotate
and forgot a variable
True.
You had that variable whole time?
the first error is explicitly telling you that the compiler has no clue what a Vector3_ is
OOOOOHHHHHHHHHHHHH
how can they figure out how to rotate if they're using Vector3_. I'm saying that it doesn't make sense to try to do some complicated stuff without learning the syntax first
it's just gonna slow down the process
Still 11 errors. :///
remove the previous thing i made you write
Kay.
read the error message. it explicitly tells you what the problem is.
that Vector3 _direction
you can't just see errors and give up
Wait like the code?
You've declared multiple fields with the same name.
The compiler does not enjoy this.
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?
does not work
then the prefabs use a material that is incompatible with URP
pick one and look at the shader it's using
I'm using right material
click on it to find out what shader it actually uses
So what's the problem Snas?
hover the error
what is that.
read the error
again, you must actually read the error messages
the compiler is telling you exactly what is wrong
Okay now only the direction; is an error.
bro you need some basics c#
Knowing why it error is more important than fixing something that will break again
the crazy thing is
it works in game, and scene
but prefab preview is the one that is stuck
doesn't seem to do anything
alright
I've had strange prefab preview problems in the past
Glad im not the only one
it's weirdly confusing
okay so what does the compiler say
It doesn't exist in the current context.
also compiler is designed in such way to tell you, whats wrong, not to only say, you made something wrong
The name "direction".
Yes i know.
well, did you declare a variable anywhere named direction?
did you change your
waste of time going back n forth
_direction to direction
you need basic c#
meaning, you removed underline
fix one thing, you break another and come back
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
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
you're welcome
see ya when it breaks again 
why i feel like same is going to happen lol
its the sideeffect of spoonfeeding
Im getting this error when trying to make a animation event, someone knows what is wrong? im extremely new to unity.
Maybe that was important.
Yeah.
Mhm.
because euler angles is a v3
it didnt give you an error?
yes it is
I put the underline under the directions.
It's a warning you can ignore. Select the desired function from the "Function:" dropdown
probably a third variable with the name direction 😝
thanks
lol
How in the-
okay so
you have direction and _direction
both at the same time
I'm just confused about this thing
you must have multiple Image components attached to the same object on whatever's being animated
just multiply them by 90
if you don't target an Image method, it should be fine.
this would not produce a meaningful rotation
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.
Okay i did that and my head vanished.
what?
you're using transform.eulerAngles i see
oh, you know, I just remembered
you can assign to transform.up
transform.up = _direction;
this will make the transform face that direction
why am i a bot @warm anvil
it'll align the "up" direction with the vector you give it
i dunno what the pipeline is for creating a prefab preview
I can't believe how simple reimport does nothing
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.
and reimport all does
it must have missed some other change
make sure you've saved your script file and that unity has reloaded
make sure you don't have any compile errors
looks fine to me
Did you save the class.
Bad idea Naming your function same name as a Class
i was curious if that would make Unity mad
just hover over this
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.
iirc it does complain but their ide doesnt seem configured
yeah I did but their wasn't "OpenURL() when I hovered over that
yup
can you screenshot, if possible
Fix your IDE. !ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
i just wanted the learn link thats why lmao
all good
screenshot your console window
okay, did you save the script
You have compile errors
the code will never work as-is
well. it does but you're correct too
i suppose you wouldn't see any errors if the file wasn't saved, yes!
I think there should be nothign wrong with "Application.OpenURL
That's fine.
It's the method named OpenURL
It matches the name of the type, which is forbidden
yup
oh wait there is a compile error
just change it to something else

Snas...
wassup
fix it but after that you should configure your IDE
#💻┃code-beginner message
URLOpener
I deleted the code. What do i do it won't work.
okay, i want to ask this so bad
what tutorial did you watch lol
this code was garbage
do you realize how context-free that question is?
"I deleted the code"
this could mean basically anything
"GetComponent<Transform>()" literally made me laugh 10 times
I don't know. I forgor 💀
But seriously why is it hard to rotate a block.
Or a sprite.
That code. is garbage.
It is easy to do once you understand what you're doing
It's not difficult
Yeah. How do i learn the basics.
you're trying to build an alarm clock when you don't know what a battery is
you just understand it hard way
by using !learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
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
well said, Fen
Indeed somehting like the https://learn.unity.com/pathway/junior-programmer or
https://learn.unity.com/project/beginner-gameplay-scripting
hi im looking on how to code does anybody have good youtube tutorials i cloud use?
look above
or check pins
Will i learn how to rotate a sprite there?
can you just first
you will probably not be shown how to rotate a sprite based on a direction input
You will learn enough where you understand how to use components through code
including sprite renderer and rotating objects
So yes.
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.
they're all free mate
Fine. I will try if you suggest it.
But writing code is hard i doubt i will learn anything from those tutorials.
anything in the beginning is difficult, writing code is not hard
Well, you're definitely not going to learn anything by literally not trying to learn anything
just ask bing ai to explain you lines of codes using real life examples and in simple words
that should help you
Then why are you even here?
Yes you will
If you actually do it, you cannot help but learn
thats what i do
If you've already concluded that you will never learn anything, why are you even trying?
no AI does more damage than good
I don't think you can't learn.
I think you can.
Okay. So it's easy huh? No lie?
its good for basics and as long as you dont use it to write codes for you
If you are willing to learn, yes its easy. I had no exp untill I learned it
How did you learn to code?
by DOING
How long did it take you to make your first game?
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
gonna keep hammering on this drum until you listen
just do it
go make a tiny little game with one of those courses
my first game huh 🙂 like released.. erhmm
I wish there was Unity learn when I was starting out
As a beginner I would stay the heck away from AI as much as possible
I started end of 2019 but never knew they had unity learn
Hope i'm not too late to get into coding.
just ask it to explain written codes for you it helps understand things
I used since like 2016 but only got to know about Learn when I joined this server lol
I'm an old fart, if I can learn it you can too 😮
Okay.
you can google but ai already googles and gives best answers to you
But realistically. How hard would it be to make a game like "Faith"?
how do i know if a unity tutorial is based on C#?
I would still prefer YouTube over AI
no it doesn't, sometimes it gives you nonsense with certainty
They do pretty good job explaining
like 4 years? with learning period included
you watch it ?
anything that isn't truly ancient will be using C#
"based on c#"
Unity ditched Boo and UnityScript a LONG time ago
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
for example?
when
i dont mean yt tutorials unity has tutorials on their website with code..
{
[SerializeField] Rigidbody rb;
public int jumpStrenght;
void Start()
{
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
rb.AddForce(transform.up * jumpStrenght * Time.deltaTime);
}
}
}
Oh ok yeah then for sure they will be c#
why isn't my player jumping?
too many to list..
a basic one would be that it throws you "functions" that don't exist
alright
i think this code is fine
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
but its not doing anything
Do you want to see my game?
Like what i did.
To the point it became a rule to prohibit helping AI generated code
is there something wrong
or
as I told you, I dont use it to generate codes
you should not use time.delta time on AddForce
also use ForceMode.Impulse
All because it was just simply wrong
how
Dont multiply force with deltatime. Also use Forcemode.impulse for one-shot forces like jump or dash
Ok im a sloth
how to do that
thanks
Did that deltatime come from a tutorial?
is there a list
no
of ?
just though it put it there
different force modes
Google unity and any function name and you will find the documentation
Or not just functions but anything
and theres also this sometimes ai lets you down 😄
guys this isn't a "thinking machine"
its just a regurgitation of internet info
it doesnt "think" , hence why the coding sucks
Why does a bot care about time consumption lol
Maybe it literally has a limiter on the processing power
alr lets not get carried with the off-topic
yeah
also AI stuffs is not allowed on this server #📖┃code-of-conduct
i didnt realize this was help channel I opened discord and this was the first channel i saw
sorry
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
worth a try delete Library folder and rebuild project?
or it could be some editor script doing something its not supposed to 😛
library folder?
It's the folder with the name "Library"
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
I can't locate the library folder
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
Hey question. While watching the tutorials should i add new features to my game or should i just watch it to the end and then work on the game?
you should put The Game on hold , learn more until you're comfortable with what you're doing then dedicate it to The Game
Look at programming this way, when you first learn about probability in school, you don't immediately start exploring something like stockmarket
Make each tutorial its own project
I want to do something special for my first game.
Does the Junior Programmer course last 12 weeks?
how can we know? it all depends on you
Follow an entire pathway.
you keep asking how to do it and we're all telling you to just do it
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
use Debug.Log in more useful ways
also ur setting the text to dragon price so it not changing
yeah I truied but I could'nt figure out the issue so i deleted it for easier reading when i send a screenshot
Is it coming back with the “not enough” log? Or is the whole thing not being executed?
How do you know
can some one help me with my code? I need to show checkpoints in sequence
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
here:
btw its all a bit of mess cuz its for a game jam and i only have like 2 days left
so what's wrong here
you have nothing changing the score or you're not updating the text you mean
Don't change your code when you share it. If it's too long to screenshot, just use a paste site
cs
We need to see exactly what you see.
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
no its the same as you see
this is a reasonable sanity-check, yes
the score seems to work for buying, when my score is for example 20 i cant buy the 50 dragon
just its not deducting points
you are not changing the score text
in the code you provided
I do it so much xD
so why would it change
@rare basin like this?
Truee, good catch
Can you show me how I could do that?? I dont get it
like its changing in the clip I sent
not via the code you sent
where do you change score text
show
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
jezus
ion have time 😦
btw comments like this, are just making the code more unreadable
then we have no time to fix your broken AI code
If you don't have time to do it right then you'd better have time to do it twice.
#📖┃code-of-conduct we're not here to fix broken GPT code
We're in the "twice" phase right now
no shit gpt handywork
What’s the twice phase?
So the issue is just the setting text on the script with the buy dragons right?
Ah I see
vicious cycle continues, gpt to code half the shite, doesn't understand the code..
whens something breaks here we are..
No I swear I usually try to do it myself, but I thought it was too hard and I would mess it up
yup, sadly it's common these days for begginers
to copy-paste shit from chatgpt
yeah AI hype train is reel
so you didin't try then
GPT is good for research purposes only, using it to write code isn’t gonna help you in the long run my friend
I want copy & paste from stack overflow back
the only fun thing chat-gpt4 does is the image generation
but yea, nothing code related
I will try now, sorry for wasting your time
yes but i use leonardo.ai for that
I would suggest having a component whose job is to update the text.
It should just set the text based on the score every frame.
(and maybe set other text elements, too)
Back to my human generated code I don’t understand 😩
or via events
It shouldn't be responsible for detecting when you gain points
not neccesary every frame
That's someone else's job.
Like an empty gameobject gamemanager? But with a script that sets the score to the text every frame right?
yeah events are best to keep UI disconnected and not polling every frame
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
yea, in his case that's the easiest and fastest thing to do
yup
instead of learning events
I used to do it too 😅
everyone did i guess
some one help me with my code? I need to show checkpoints in sequence
the power of events ⛈️
Are coroutines unity specific or is it available to anything that uses c#?
Add the component button text as a reference in the button, when the purchase is successful then change the button text
Unity specific
using IEnumerator cleverly