#💻┃code-beginner
1 messages · Page 605 of 1
The whole idea is that a trigger can display a ui element (already got this figured out) and then from there you can hit a key to progress it? in a way between multiple diffrent ui elements you have sorted (like flipping through a book or comic in a way? or like going through dialouge) and then just hiding the element when done, if that makes sense??
I dont know what keywords id have to search up or any better way to look for this, and it seems so simple but I have been stressing over figuring this out for weeks at this point
Well, what do you have so far?
It should be pretty easy to implement with an array/list of ui objects that you want to display and some timer in update.
I have a UI element that shows up on trigger enter for little interaction spots
one second let me figure out the format for sending code
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 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.
oh yay!
thank you
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class pleasefuckingwork : MonoBehaviour
{
public GameObject tool;
void OnTriggerEnter(Collider hit)
{
tool.SetActive(true);
}
void OnTriggerExit(Collider hit)
{
tool.SetActive(false);
}
}
its nothing special but it does the job
I will admit I am much more of a visuals guy so coding and everything is so completely new to me
My idea was that i could make an alternative version of this code that calls the hiding of the ui to the end of my ui sequence ?
I have a kind of similar system in my game for reading these mini books but thats set to button presses
From the image you shared earlier, you want to scroll between the different ui objects on key press and then disable it, no?
mhm!
The simplest way you can do it is have all the UI objects under a single parent that has a UI script. When you enter the trigger, activate the object with the script. Then in the script update query input and if the desired key was pressed, activate the next child object(or an object in a list). When there is no next UI object, just disable the root object.
ooo
ok, let me see if i can do this
thank you so much for the advice and direction!
I was wondering if this implementation of AStar looks like it's behaving correctly? There's only the grid existing on screen, and nothing beneath.
My current understanding is that the heuristic does not change based on if there's obstacles or not since it's "blind" in a sense
pink is obstacle and cyan is the steps of the algorithm; yellow is the final path taken
yes
How do i check if certain colliders touch each other? Whenever im using OnTriggerEnter/Exit/Stay it works for all colliders on the gameobject or all colliders in parent/children
I have a sword with a collider, and an enemy with 3 colliders:
ColliderR- Collider Trigger for player range detection
ColliderP- Collider for Physics
ColliderH- Collider Trigger for a Hitbox (This is what the Sword should be able to hit)
However, all of them are working, which is not what i want. This is the script on the Sword im currently using with an Interface:
private void OnTriggerEnter2D(Collider2D other)
{
if (SwordCollider.IsTouching(other) && other.CompareTag("Enemy"))
{
IDamageable damageable = other.GetComponent<IDamageable>();
if (damageable != null)
{
damageable.TakeDamage(1);
}
}
}
```
The sword script also basically has an Attack() function which dissables/enables the script whenever the player attacks.
Ive tried to put the colliders as Variable fields in the Inspector, but using something like: ``` if(other == ColliderH) ``` did not seem to work.
So how can i detect if SwordCollider is touching any, but only one, of the colliders?
What am i doing wrong?
Could be a composite collider problem? Usually I try to keep stuff separated when doing multiple trigger colliders, making sure I have a rigidbody for each collider *collider for each game object, sorry!
Rather, the sword itself wouldn't have an RB, only colliders. Make a gameobject for each hitbox of the sword and stick a collider on that. The enemy will do the OnColliderEnter methods and check what hitboxes of the sword had made contact
I think that's what I do? Just woke up ;p
This is really good advice! Thank you! However isnt it quite expensive to have more RBs?
And do you think there is a way to access them trough code or is it done just trough the inspector
You only need 1 rb, and that would be on the enemy. This is assuming your weapon is moved not with physics
oh okay
because the enemy is the one who reacts to the sword hitboxes. The sword shouldnt care what enemy it hits
but for the most part, to use these trigger collider methods, at least one rigidbody must be present. But, you can set the rigidbody as kinematic if you don't need the physics.
techically all this collider stuff is physics related, but you're just using it for intersection detection
and the object that does have the rb on them will be the one who receives the callback for when there is an intersection.
And, if you do want the sword to actually care what it hits for like deflection purposes, you can always let the enemy reply back to the sword to tell it that it had made contact.
one of many ways to do it
should i be getting errors?
absolutely you should. you haven't declared most of the variables you are using and you've got a bunch of things misspelled
where's the tutorial you're following
FIRST PERSON MOVEMENT in 10 MINUTES - Unity Tutorial
In this video I'm going to show you how to code full first person rigidbody movement. You can use this character controller as final movement for your game or build things like dashing, wallrunning or sliding on top of it.
If this tutorial has helped you in any way, I would really appreciate...
its this one
im guessing its this bit
How do I get the X,Y coordinates of a mouse click? I'm getting weird inconsistencies with ScreenToWorldPoint. I am making a 2D game and I am trying to determine the int X,Y coordinates of where the player clicks on something. All of my interactable objects (dungeons, monsters, player, etc.) are stored in Vector3 lists:
public static List<Vector3> dungeonPositions = new List<Vector3>();
Using dungeons for an example, I currently get the clickedPosition and then round the X,Y into a new Vector3 which I use to compare to all dungeon positions. I do this because when I'm generating the dungeons, they're using int X,Y coordinates and the ScreenToWorldPoint gives a float.
if (Input.GetMouseButtonDown(0))
{
bool withinInteractionRange = false;
Vector3 clickedPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
int pOne = Mathf.RoundToInt(clickedPosition.x);
int pTwo = Mathf.RoundToInt(clickedPosition.y);
position = new Vector3(pOne, pTwo);
BoardManager.CheckInteractionRange();
foreach (Vector3 dungeon in Dungeons.dungeonPositions)
{
if (dungeon == position)
{
InfoGUI.EnableInfoGUI(position, "dungeon", withinInteractionRange);
}
}
}
This seems to work sometimes but about 3/4ths of the time it doesn't do anything. I am guessing the issue is where I'm converting the clickedPosition into individual integers but I'm not sure. Does anyone have any suggestions for how best to accomplish this? Thanks!
you probably want to floor X and Y from the mouse position to get the actual coordinate space that was clicked rather than just the nearest coordinate (which could be the next grid space over), but also unless each of the objects in that list only has a size of 1,1 (in grid space, not scale) then what you are doing won't work.
consider using something like the event system IPointer interfaces for detecting clicks on the individual objects instead of checking against every single object on the map for each and every click
Thanks for the reply. I'm fairly certain everything on each grid is set to 1,1 - I'll attach a screenshot of the Structures grid I have. For IPointer interfaces, I'm not sure that would work because I'm not generating any new game objects at run time. Everything on the game board is currently stored in lists that I iterate through and work with across all of my scripts, updating the individual tiles on each grid via coordinates when I need to.
Ah, I misunderstood what you meant about grid space not scale. I guess I'm not sure where to check what the grid size is? I have left them all on whatever their default is I guess.
what is the best way to find another gameobject in the scene trough code?
i was specifically referring to the actual objects. if they are not each 1 unit wide and 1 unit tall then what you were doing would break down immediately even if it were almost correct
Highly depends on what you're trying to do
Where can I check that? On the sprite itself?
i want to set the parent of my camera to follow a gameobject in my player
look at it in your scene. however as i've already pointed out, that is pointless because there are far better ways to determine what you've clicked on
is using findbyname good solution or not stabel?
transform.parent
if the parent changes then do that
allright
use a better way to get a reference than any of the Find methods
but if its always the same then u can save some power by getting a reference
its for using in multiplayer
that doesnt rly explain
Thanks, I'll look further into those docs. I'm using the lists because there is a lot of data attached to everything and it allows me to manage it. Coming from a programming background, it made sense to me to use them to manage the tiles as well.
so i have my player object and a camera object and when i join server i need to have a ref to the camera object
You technically can, but it's not an optimal solution by any means
allright thats what i thought
Is the camera ever used without the player being present?
not really
Then you don't need to find anything at all, just add it to the prefab
still cant pass reference
Unparent it later if you need to
can u
Assuming you only have 1 camera in the scene .. Camera.main
allright i thought that wasnt a good solution to add camera to player
i need to have the parent and the camera
what
Camera.main.transform.parent
thank you
I'm literally just trying to make a pinball table but never done 3d before. Should be easy for a 3d expert 🙂
Any idea why my flipper keeps snapping back to 45 degrees rotation on the X axis?
public Rigidbody rigidBody;
public Quaternion defaultRotation;
public Vector3 targetRot;
void Start()
{
if (flipperType == FlipperType.LEFT)
{
FlipperController.instance.OnLeftFlipperActivated += ActivateFlipper;
FlipperController.instance.OnLeftFlipperDeactivated += DeactivateFlipper;
}
else
{
FlipperController.instance.OnRightFlipperActivated += ActivateFlipper;
FlipperController.instance.OnRightFlipperDeactivated += DeactivateFlipper;
}
//defaultRotation = rigidBody.rotation;
}
// Update is called once per frame
void Update()
{
}
private void FixedUpdate()
{
rigidBody.MoveRotation(Quaternion.Euler(0, targetRot.y, 0));
}
public void ActivateFlipper(float angle, float flipTime)
{
float a = Mathf.LerpAngle(rigidBody.rotation.y, angle, flipTime * Time.deltaTime);
targetRot = new Vector3(rigidBody.rotation.x, a, rigidBody.rotation.z);
}
public void DeactivateFlipper(float angle, float flipTime)
{
float a = Mathf.LerpAngle(rigidBody.rotation.y, defaultRotation.y, flipTime * Time.deltaTime);
targetRot = new Vector3(rigidBody.rotation.x, 0, rigidBody.rotation.z);
}
public enum FlipperType { LEFT, RIGHT };
}```
This is how the flipper is set up
Rigidbody.rotation is a Quaternion, but you are treating it as euler angles apparently
Quaternion.x/y/z dont make sense here
oh yeah good catch, similarly you're using lerp angle on two quaternions... does that even work
I mean, you got the idea of rotating on the y, and that's all you need to do really if it's only rotating one axis.
Ye. Personally I would just pivot the flipper in a position and have two y values it could possibly be at so I only need to lerp a float.
I think I really need to learn what a quaternion actually is
Go experience the explorable videos: https://eater.net/quaternions
Ben Eater's channel: https://www.youtube.com/user/eaterbc
Help fund future projects: https://www.patreon.com/3blue1brown
An equally valuable form of support is to simply share some of the videos.
Special thanks to these supporters: http://3b1b.co/quaternion-explorable-thanks
Pre...
took another swing at this using what I understand but not dice
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
public class KeypressManager: MonoBehaviour
{
public GameObject dialouge01;
public GameObject dialouge02;
public GameObject parent;
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown("enter"))
{
dialouge01.SetActive(true);
}
if (dialouge01.activeSelf) {
if (Input.GetKeyDown("enter"))
{
dialouge02.SetActive(true);
dialouge01.SetActive(false);
}
}
if (dialouge02.activeSelf)
{
if (Input.GetKeyDown("enter"))
{
dialouge02.SetActive(false);
parent.SetActive(false);
}
}
}
}
doing this feels so deceptively simple and just I really am trying
looks alr
i suppose you slowed it a bit for showcase
If i want a class to inherit from multiple things, such as this:
public partial class Enemy : Poolable<Enemy>, Damageable<Enemy>
{
//...
}
How can i best go about doing it? As it cannot have multiple base classes
based purely on name alone Poolable<T> and Damageable<T> seem like they should probably be interfaces, but you've not really provided enough context to know for sure
Those definitely sound like interface names. You can only derive from one class, but you can derive from multiple interfaces . . .
I see, i made them abstract as i wanted to provide default implementations for them, so i thought that was best. As far as i know i cant define variables in an interface so im not sure how to go about it otherwise
you can have properties in interfaces. what is the actual purpose of these and why do you need both
public abstract class Damageable<T> where T : MonoBehaviour
{
public float Health { get; private set; }
public virtual bool Damage(float damage)
{
Health -= damage;
if(Health < 0)
{
Die();
return true;
}
return false;
}
protected abstract void Die();
}```
example
I'd make IPoolable an interface for the Enemy to inherit implement
Then, you need to rethink your architecture. You shouldn't have a big inheritance chain . . .
This should be a separate MonoBehaviour class that you attach to the enemy GameObject . . .
private void Update()
{
if(...Down...)
{
dialogues[current].SetActive(false);
current++;
if(current >= dialogues.Count)
{
enabled = false;
return;
}
dialogues[current].SetActive(true);
}
}```
yeah honestly that should be its own component and the Die method should just be a UnityEvent that you can subscribe to in the inspector from your separate Enemy component
there's also 0 reason that should be generic
here's an idea too
public abstract class ObjectPool<T> where T : MonoBehaviour {} //Can also make this a monobehaviour class / singleton to child the enemy instances
public class EnemyPool<Enemy> {}```
In Unity, it's best to create separate components that when added to a GameObject, provide it functionality, which ultimately, builds that object . . .
I see, is something like this fine though?
[DefaultExecutionOrder(-1)] // Ensures singletons can always be accessed by prioritising their execution
public abstract class Singleton<T> : MonoBehaviour where T : MonoBehaviour
{
private static T instance;
public static T Instance
{
get
{
if (instance == null)
{
T[] instances = FindObjectsByType<T>(FindObjectsSortMode.None);
if (instances.Length > 1) Debug.LogWarning($"Multiple instances of {instance.name} exist");
if (instances.Length != 0) instance = instances[0];
else Debug.LogWarning("Singleton is attempting to be accessed, when none exist");
}
return instance;
}
}
}```
This was the first time i used this kind of format, so i just replicated, i feel like it makes sense here
im sorry to be a bother, could i ask for a bit of a clarification on the down or how to properly set up this script?
im sorry
I see what you mean how it makes sense for damaging and stuff to be in seperate monobehaviours though
You'd just ask. The down within the if statement is me being lazy and not wanting to type it all out (I'm on mobile)
Dialogues would be a list of type Dialogue.
Or GameObject or whatever you're needing more than one of.
public List<GameObject> dialogues;//to be populated from the inspector etc```
The Singleton looks fine, but it's incomplete. You never assign it (in Awake) or check if one already exists, and if there is none, you should load it from your assets and return that instance . . .
I'm assuming you know about lists and have imported the directives (using collection etc)
I don't understand the object search. You just check if theinstance is null or not
well the idea was that these would already exist on game start and that was just ensuring a single one exists when other scripts try to access it, i think i got help from someone here ages ago for it.
not atall
well i was doing that as a check for only one instance existing in the scene, but i get its not necessary really
public abstract class Singleton<T> : MonoBehaviour where T : MonoBehaviour
{
public static T Instance { get; private set; }
protected virtual void Awake()
{
if (Instance == null)
{
Instance = this as T;
}
else if (Instance != this)
{
Destroy(this); //Or destroy gameobject depending how you do your managers
}
}
}
public abstract class PersistentSingleton<T> : Singleton<T> where T : MonoBehaviour
{
protected override void Awake()
{
base.Awake();
DontDestroyOnLoad(gameObject);
}
}```
```cs
public class GameManager: PersistentSingleton<GameManager>```
There, toss that into every project
Alright, thanks. With regards to my damageable, how would i want to go about overriding behaviour if i made it a separate monobehaviour script as suggested, without repeating code?
public interface IDamageable
{
public int Health { get; }
public void DoDamage(int damageAmount);
public void DoHeal(int healAmount);
}```
Place this at the top using System.Collections.Generic; to allow yourself usage of Lists.
Create the public List field like my prior example above.
Populate the list with your dialogues. For example, if you had three dialogues, they would be at index 0, 1 and 2 of the list.
The code would run in Update and evaluate if said button was pressed (the statement where I've neglected to complete since you've already done so yourself in your original code posted).
Next you would disabled the current dialogue (assuming the current one is enabled when this script had become enabled). You'd increment the counter (current) by one and evaluate if it's less than the maximum amount of dialogues. If greater than or equal to the maximum count, you'd disable this script to prevent further execution at later times and stop executing the remainder of this Update function with a return call.
If the current index hasn't exceeded the series of dialogues to be presented you'd enable the next one etc.
In anything that uses that interface, DoDamage would take away health though, so wouldn't that just lead to unecessary repeated code? Or is that just the case and theres no good way around it?
Thank you so much, I will try my best to follow along
Depends, do you think every single object will have the same method logic? If a player takes damage, wouldnt they also invoke say invincibility frames, but not enemies?
Each object that implements the method will have it's own logic. Yes, some of them will be the same (trivial), but not every object . . .
I suppose that's a fair point, thanks
I tried to make my turret aim at the player with the following method, but when the player gets too close to it, the turret doesn't aim like the game is 2D. Is there a way to fix this issue?
private void LookAt()
{
Vector3 targetDir = GameObject.FindWithTag("Player").transform.position - gun.transform.position;
float step = rotationSpeed * Time.deltaTime;
Vector3 newDir = Vector3.RotateTowards(gun.transform.forward, targetDir, step, 0.0f);
gun.transform.rotation = Quaternion.LookRotation(newDir);
//gun.transform.rotation = Quaternion.Euler(gun.transform.rotation.eulerAngles.x, 90, 0);
}
public interface IDamageable
{
public HealthComponent HealthComponent { get; }
}```
Not saying you can't do it how you want it though. Just think with composition
Set the Y(?) value of newDir to 0 before setting the gun transform rotation
Also, stop using FindWithTag() constantly. Do it once and cache it.. there is no reason to do it every frame
Idk how I can do that, can you show me?
Ok
newDir.y = 0;
I'll try it
ok, great - I dont need to be told that, just go do it ;p
Update: Now it doesn't even look up anymore
Where did I go so wrong...
I dunno, because you haven't shown what changes you've done.
All I did was add your suggested piece of code here
If I'm missing something, please let me know
Remove that line I said to add.. and wait for someone else to help. I dont have the time to carry on.
Seems to me though you only want to be rotating on Z, but you're rotating on all three axis
Just pass in Vector3.back as the second parameter to LookRotation
Quaternion.LookRotation(newDir, Vector3.back);
the problem right now is you're not passsing in a second parameter, so the game assumes you want the global "up" direction to be the "up" direction for your rotation
Nope, it still rotates on all three axis somehow
I've made sure all of the rotations including the children are set to 0
Same issue as my initial problem
@wintry quarry
the only issue I see is the twisting
oh I didn't watch long enough
your problem then is also that the objects are not at the same z position
so you will also want dir.z = 0;
that means that the turret and player aren't on the same plane
i'm mildly unclear which plane the camera is aligned with; assuming it's the XY plane, then yeah, zero out the Z coordinates
newDir.z = 0;
gun.transform.rotation = Quaternion.LookRotation(newDir, Vector3.back);```
the commented-out code has the gun rotating on the world X axis
yeah this is assuming we're looking at the xy plane here
which is inconsistent with being aligned with the XY plane
if the camera is on the YZ plane, then zero out the X coordinate. Same idea.
you can figure out which plane the camera is on by looking at the orientation gizmo with your view aligned with the camera
here, I'm on the XY plane
...and looking in the +Z direction
actually it's probably targetDir we want to be setting z = 0 on tbh
Yeah, you can zero out both positions or the resulting direction
Same deal
The latter is easier
That was it! Thank u so much!
note that this means that the cannon is no longer aiming at the player 😉
Maybe you actually want to fix the player not being on the same Z coordinate as the cannon!
I'll make sure all of the objects' z coordinates are at zero next time
@swift crag Btw, it's the xy plane in my case
yeah, that's the typical setup for a 2D game
i was just unsure because of that commented-out line at the end
Now to figure out how to clamp their rotations to prevent the turrets from looking down
Quite a few ways to do that. The most obvious, to me, is to use Quaternion.RotateTowards
That lets you move from one rotation to another by at most a certain amount
Are you talking about maxDegreesDelta?
Yeah
so Quaterion.RotateTowards(Quaternion.identity, targetRotation, 90) produces a rotation that is at most 90 degrees away from the identity rotation
"identity" meaning the rotation that does nothing
transform.localPosition += Vector3.zero;
transform.localRotation *= Quaternion.identity;
transform.localScale *= Vector3.one;
all three of these do nothing
How do I Reference or just use a variable from another script?
Judging by this picture your !ide is not configured. Configure it.
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
• :question: Other/None
Use serialized fields or something else to get a reference to that instance of the script, then just say ClassName.variable. Make sure the variable is declared as public
dont declare variables as public, its poor encapsulation
In that case, use a getter/setter method
Yes, use them. Getter/ Setter is a property though - not a method
Inside is method
it might decompile to a method, I dunno, but in your C# class.. it's not a method, hence why theyre called properties
Well I mean it depends on how you write it
Properties actually make a get and set function but it's hidden from you
If you use reflection you can find these methods and the backing field
Or just use dnspy
Looking back at my code, I honestly don't know how to change this line of code to clamp the x-axis rotation, because the maxDegreesDelta is already taken by "step"
Vector3 newDir = Vector3.RotateTowards(gun.transform.forward, targetDir, step, 0.0f);
eulerAngles
I’d say set the rotation in Euler angles and do the math yourself
It’ll give you more control, including clamping a specific axis
This is the only method I was able to find so far in order to make that turret aim at the player like it's a 2D game
If u can suggest a better solution, I'm all ears
aren't you only rotating on one axis?
the Z axis, in particular
Yes
Don't start from the current rotation
[SerializeField] Quaternion centerRotation;
[SerializeField] float angleLimit;
Rotate from centerRotation towards the desired rotation by at most angleLimit
where centerRotation is the rotation that makes the cannon point straight up
Upon closer inspection, I found something weird with the object's rotation
also, this is Vector3.RotateTowards, not Quaternion.RotateTowards
You can certainly achieve the same thing with it, though
You'd just store a neutral direction that you rotate away from
The object is apparently rotating in the x-axis instead of z-axis, and depending on where it's pointing, the y and z rotation snaps to 90 and -90 degrees when it's looking right and vice versa when it's looking left
note that you're looking at local rotations in the inspector
if you rotate an object around the world Z axis, its local X rotation might change (depending on how its parent is rotated)
also note that looking at Euler angles can be misleading
there are many ways to represent the same orientation
If the cannon is visibly doing the right thing, that's all that matters
So the z rotation is correct, but doesn't display it the same way in the inspector as it's using euler angles
because the inspector is showing the rotation relative to its parent
I am trying to learn this engine i never used anything of this before i am trying to use the tutorial but i dont under stand this can anyone help?
Anyone know how i can resolve this error? My script name matches the class name and it inherits from monobehavior, but it just refuses to recognise it
Do you have any compile errors?
I've made sure the parent's rotation is zero on all axis
You probably need to go into the "FPS" folder, but I'm just guessing here
Not as far as i know, rider isnt picking anything up
make sure you haven't skipped a step
You must have zero errors in your entire project
Check the console.
Even if i delete all the code from the script it still does it
that leaves the second reason: euler angles aren't unique
There's nothing in the console
hm, at that point: right click the script asset and click "Reimport". Does anything change?
also make sure that you don't have multiple MonoBehaviour classes defined in the same script file
Nope
It's just one class as well
can you currently enter play mode?
Yep it works fine
Peculiar.
I'd sanity check by making a new MonoBehaviour script asset and seeing if that works
If that fails, I'd see if a full reimport fixes it. Assets > Reimport All
Doesn't seem to work either
this'll take a hot minute
Alright ill try that
the more violent version of this is to close the project, delete the Library folder, and reopen the project
the Library contains data generated by Unity -- a big chunk of which is the asset database
that's what you're clearing with Reimport All
Oh i see okay
As for why the local X axis is changing here -- the Y rotation affects the meaning of the X and Z rotations
(and the X rotation affects the meaning of the Z rotation)
When you only have a direction, there are many possible rotations that point you in that direction
which could cause unwanted spinning of the barrel
I see that you were originally not passing a second argument to LookRotation
Are you doing that now?
Hello o3o
I have a question I will place in a thread if I can
If the second argument was Vector3.back, yes
Okay it worked ty
Okay, that's good
That'll keep the barrel's "up" direction -- the green arrow -- facing towards the camera
How do I find the turret's local quaternion rotation? Because I want to find its center rotation and I don't trust the rotation values in the inspector anymore
I'm talking about this one
which direction does the barrel point when its local rotation is zero?
You actually want to be working with local rotations here. If the entire cannon body tilts to the side, that should change the field of view of the cannon
So, your code will look like this:
[SerializeField] Quaternion restRotation;
[SerializeField] float angleLimit;
void Aim() {
Quaternion goalRotation = ... // do the existing calculation
Quaternion localGoalRotation = Quaternion.Inverse(transform.parent.rotation) * goalRotation;
Quaternion limitedRotation = Quaternion.RotateTowards(restRotation, localGoalRotation, angleLimit);
transform.localRotation = limitedRotation;
}
Get the barrel rotated to the neutral position, then right click the "Rotation" property and copy the quaternion. You can then paste it into the restRotation field.
I wish there was a convenient Transform method to go between local and world rotations
goalRotation is a world-space rotation. The second line converts to a local-space rotation.
Here are the cannon's rotations in the inspector just to be sure
Rotate the barrel so that it's in the "center" position
then copy its local rotation
that's your reference point
the cannon will rotate away from that reference point until it reaches the angle limit
hii can anyone help me
i have two jumps, when i jump once it the ball only moves 2 pixels above the ground and it sticks back to the ground coz the gravityon air brought it back down, the ball jumps nicely when on air so the gravityscale on air os not the problem, but there is something happening between that first jump that makes the ball only jump 2 pixels idky
perhaps you have code that sets your vertical velocity to zero when you're grounded
and the ground check is wrongly saying "yes" when you're moving upwards
@swift crag I hope I did everything right
void Aim()
{
Vector3 targetDir = GameObject.FindWithTag("Player").transform.position - gun.transform.position;
float step = rotationSpeed * Time.deltaTime;
Vector3 newDir = Vector3.RotateTowards(gun.transform.forward, targetDir, step, 0.0f);
newDir.z = 0;
Quaternion goalRotation = Quaternion.LookRotation(newDir, Vector3.back);
Quaternion localGoalRotation = Quaternion.Inverse(transform.parent.rotation) * goalRotation;
Quaternion limitedRotation = Quaternion.RotateTowards(restRotation, localGoalRotation, angleLimit);
transform.localRotation = limitedRotation;
}
That seems right. Just make sure that the green arrow on the barrel is pointing towards the camera in the rest position
(make sure your scene view is in "Local" mode, not "Global", here)
Otherwise, the barrel will try to spin around its long axis!
Should I attach the script to the barrel or its parent?
As-written, it needs to go on the barrel
If you want to be able to put it on another object, you need to add a Transform field
(and then rotate that target)
basically, any use of your own transform property would be replaced by that field
nice (:
You should be able to rotate the entire cannon body and have it still work right
Thx a million!
here is my playercontroller script
can you share that on a paste site? !code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 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.
I need to get to work so I'm out of here for now, but someone else can probably help you with that
I mean... a functioin called "StickToSurface" with m_Rigidbody.linearVelocity = Vector2.zero; // Stop all movement
seems pretty suspicious.
@swift crag Btw, the cannon ur talking about is actually a mortar
I just suck at designing it to make it look like one
because i want it to stick to surface when im not movind, it kept rolling
Im tryna recreate this feature man
How are you gonna stick to a rotating triangle by setting your velocity to 0?
the approach is misguided
aand anyway it's responsible for your inability to properly move off the surface
How would you approach it
Probably without rigidbodies
wouldn't you use something like a joint ?
parent the player to the object it contacts
but yeah with RB you would use joints and break them when the player jumps again
but it won't be exact and clean
because physics isn't
test it out, if dynamic gives you problems, maybe use transforms or kinematic parenting
Parent the object everytime the ball jumps on a surface
only when necessary I suppose, idk the full mechanics of the game
Really wont that cause unintended issues like the object jumping with the ball
when you jump you break the connection
only put it on while its a moving / rotating surface I guess
I just want my ball to jump and stick to an object
No I understand that part, but idk also movement and stuff to consider, like are you able to move while its rotating or you're supposed to stay stil ?
the former complicates this even further
i have a character 3d model any website or some tool to just auto rig it and apply animations?
Mixamo com
So what do you think i do
tbh I have no idea, haven't experimented too much with 2D.. You can try joints at least for sticking, maybe you can figure out a way for movement
Af'noon all.......sooooo, I'm trying to get the pixel colour values of an image but ran into a bit of a roadblock.
Here's my full code at the moment
https://hastebin.com/share/liradisati.csharp
The part that I'm struggling with at the moment is where I assign the colour value of the current pixel in my loop
newDepthMapData.valueAtPosition = depthMapValues[ ];
This line specifically, I don't really know what this should be if honest, and the Unity docs have been no help so far.
Idea of the script is that it reads each pixel in turn and creates/adds the data (current position and pixel colour value) to the DepthMapData class and then adds the new class to the list for future processing etc.
Chances are that I've done many things wrong with how I've written in all, but at the moment it's just for prototyping purposes.
Would anyone be able to point me in the right direction please?
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
I believe depthMapValues should be a straight array of pixels, top left to bottom right, in order. So, to get the position x,y from a 1D array this way, you would get the position at index (x * width) + y
Ah excellent, thank you. Yeah I was very confused as to what went in there. lol. Will give this a go 🙂
Fun fact - this is actually how 2D arrays are stored in memory. There's not actually multidimensional arrays, just syntactic sugar that does this math for you.
Aah, fair enough. 🙂
And dangit, I was declaring valueAtPosition as a float, and not a Color32. lol.
cant seem to add avatar for animator why?
Do you have an Avatar asset in the project?
you try drag n drop
you have to create the avatar first in the Model import
but it's not expanded so I can't see
i want to animate character with the downloaded anims i did create an animator window
my player keeps doing this weird teleporting thing
oh ok
what could that mean
correct channel indeed
thanks for reminding me
- No it's not the correct channel
- That's a link to a message
so, wont you like help me?
https://docs.unity3d.com/Manual/class-FBXImporter.html
its under RIG
help you with what? you haven't posted a question. Just a statement with no further info
so make it not teleport
We can't really answer any more detail than that since you haven't posted any code
I mean without script at least or seeing setup, what do you expect?
public class Player : MonoBehaviour
{
private Vector3 motion;
public Rigidbody rb;
public float speed;
void Update()
{
motion = Vector3.zero;
if (Input.GetKey(KeyCode.W))
{
motion += new Vector3(0, 0, 1);
}
if (Input.GetKey(KeyCode.S))
{
motion += new Vector3(0, 0, -1);
}
if (Input.GetKey(KeyCode.A))
{
motion += new Vector3(-1, 0, 0);
}
if (Input.GetKey(KeyCode.D))
{
motion += new Vector3(1, 0, 0);
}
motion.Normalize();
rb.velocity = motion * speed * Time.deltaTime;
}
}
you're in code channel and haven't even posted the code with question
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 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.
rb.velocity = motion * speed * Time.deltaTime; using deltaTime for velocity is wrong and the source of your problem
lemme try
also might want to be moving in FixedUpdate
THX
it worked
you use deltaTime to convert "X per second" into "X"
Hmm. Okay, so everything is now working......sort of. lol. I'm grabbing the correct data from my image and it's all being added to the list correctly, which is cool.
But, I'm getting an index out of range error, and I'm not entirely sure why.
https://hastebin.com/share/ehaqaniwen.csharp
I'm sure there's a better way to do this tbh, as it is going to result in a crapload of entries in the list (80,000 ish before the index things craps it out and if my maths is right, it should be 147,456, which I'll then have to search through on a frame by frame basis, which I imagine will be very slow.
The image is 512*288 pixels.
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
on what line are you getting the error
Anyway pretty sure:
depthMapValues[(x * mapWidth) + y];```
is supposed to be:
```cs
depthMapValues[(x * mapHeight) + y];```
and the -1 should probably not be there e.g. in mapWidth-1 unless you are trying to skip the last pixel in each row/column
Color32 tempColour = depthMapValues[(x * mapWidth) + y];
generally speaking, you should have:
x * y_size * z_size + y * z_size + z
Ah okay. Yeah that's the line with the error.
incrementing x skips ahead by an entire YZ slice
And yeah, the -1 was just 'checking' with the out of range error.
in this case, you just have x and y
Fantastic, thank you. This was the issue. all fixed now 🙂
Fen's reasoning is the why!
Yeah, I'll be honest, the axes stuff in that line confuses the crap out of me. lol.
Actually, if I may impose a little further. I've figured out how to cut down on the list entries quite a bit (using an alpha channel and just ignoring anything with an alpha of 0. So that helps.
When it comes to referencing the data in the list and grabbing the colour value, I'm not 100% sure how to go about it.
My thought at the moment is to send Input.mousePosition (with a little calculation to match the size of the depthMap image) to a method that searches the list for the relevant vector2 and returns the colourValue, which will then be used to scale the bullet impact.
But, it seems like that might be really inefficient and slow.
Anyone have any thoughts?
Hello, i'm trying to make my player respawn after his death, but he isn't respawning at all. I followed all of my tutorial and there is no errors. Here is my code : https://paste.mod.gg/wgafbhcljceh/0
A tool for sharing your source code with the world!
By the looks of it, You're destroying your player (deleting it), but never actually Instantiating it again.
add some debugs and find out which logic is going wrong. If I had to guess, u didnt assign _respawnPosition and then line 40 is false
also this code is very questionable, id be pretty wary of this tutorial.
Do you get your log for player lives remaining
Ignore what I said btw. Speed reading and read it wrong. lol.
where are you calling on player death
Hey guys, what's up
If I want to do a fake collider on one tile in my tileset, how can I do that...?
wdym by "fake collider"?
Someone recommended I should make a fake collider on another server because I was having issues with wall-jumping
Like for these steps for example, it thinks these tiles are walls
Yes
It shold be trigger
I only want to wall-jump if it's 2 tiles or higher
Does your player have a Character Controller on it
I guess it's like another collider that you can add to fix bugs in the engine...?
Yes
What bugs in the engine?
Sounds completely imaginary.
and yeah what bug?
Like sometimes there can be issues with the character moving up a slope, you can add a fake collider and make it seamless
I don't know, I'm new to this stuff too, I just heard the concept a couple days ago
CharacterControllers don't like being teleported. You can either disable the controller and re-enable it, or call Physics.SyncTransforms() after the teleport to force it to update
Still not sure what you mean by "fake collider"
There is nothing in Unity called a "fake collider"
maybe what they mean is to add a simple collider that doesn't match the visual shape of the terrain?
do you want them to walk like theyre walking up a triangle or something
This is what the person shared as a solution
yeah that's just having a collider that doesn't perfectly match the visual
Okay, yes, a collider that doesn't match the visuals
I copied a script I found from youtube video regarding player collisions and movement and I noticed that some of the words werent the right colors and stuff how do I fix this
You can edit the shape of the collider for your sprites in the Sprite Editor under "Custom Physics Shape" @normal turret
Yeah that's what a fake collider is I think
!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
• :question: Other/None
whats that mean
Or I guess it goes by a different name
follow the linked instructions
it means read the bot message that the command brought up
Is it possible to do for one specific tile...?
I assign a location to it
for a specific sprite
Tiles are always individual sprites
Ok nice thank you, going to try it out
It's just sometimes the character wall jumps off of one tile and it's kind of weird
So I wanted to see a solution, going to try it out
Okay
is there a way to write logic in pixel coordinates?
public class GroundManager : MonoBehaviour
{
private Vector2 _spriteSize;
private Vector2 _gameSize;
private void Start()
{
PixelPerfectCamera pixelCam = Camera.main.GetComponent<PixelPerfectCamera>();
_gameSize = new Vector2(
pixelCam.refResolutionX, pixelCam.refResolutionY
);
// They are both the same size so it doesn't matter.
SpriteRenderer sprite = _ground[0].GetComponentInChildren<SpriteRenderer>();
_spriteSize = sprite.size / sprite.sprite.pixelsPerUnit;
}
private void FixedUpdate()
{
foreach (GameObject ground in _ground)
{
Vector2 position = ground.transform.position;
position.x -= _movementSpeed;
Debug.Log($"{ground.name}: {position}");
if (position.x < 0 - (_spriteSize.x / 2))
position.x = _gameSize.x + (_spriteSize.x / 2);
ground.transform.position = position;
}
}
}```
im trying to write somethig like this but im writing in pixel size not unit size
I did this and its still not working so either my pc is stupid or I am
no because pixel size is not constant in the world
when your game resoluition changes it will be different
If you mean something like sprite pixels rathjer than actual on-screen rendered pixels then yeah you would use e.g. the sprite pixels per unit as in that code to convert
if you have 32 PPU, for example, then 1 in-game unit = 32 "sprite pixels"
i did smth like this
Is it possible to make the cloud respond to the player's steps, so that it sinks when the player steps on it and sinks further if the player lands on it after jumping?
anything is possible
some things are just very, very annoying (:
It sounds like you have a couple of smaller problems here:
- Detecting that the player is standing on a cloud
- Detecting that the player just landed on a cloud
- Warping the shape of the cloud
this should be made through code, right? it's not about animation? like it would be dumb to make a version for each cloud depending on the the player's movement
is it a tileset cloud
you can do it by animation
yeah might be really easy
but this is simple enough to just do it all in code
hm, i'm not sure about how I'd distort the individual sprites in a tilemap
since that's one big mysterious Tilemap Renderer
Can't you mix both? Tilesets and just single GOs?
Didn't even occur to me that you can use tileset for 2D platformers ;p
well if its a tile set
like you could have 3
animations
and since the guy is big enough you wont need more
like I was thinking of implementing the same logic of the water
does it go back
to like flat
idk but i think you can have smaller tiles so like for the water one you can have the middle tile the one all the way down and the ones on the side you can have them in a different state
links are allowed
Show your Support & Get Exclusive Benefits on Patreon (Including Access to this tutorial Source Files + Code) - https://www.patreon.com/sasquatchbgames
Join our Discord Community! - https://discord.com/invite/aHjTSBz3jH
--
I had......SO much fun working on this project... Despite having to completely scrap my first approach!
We're going to use ...
what do you think if i change the script to only affect horizontal velocity so that the ball stops rolling when its on the ground instead of stopping all velocity
m_Rigidbody.linearVelocity = new Vector2(0f, m_Rigidbody.linearVelocity.y);
same problem
agian look at that rotating triangle part
that's not going to work with some hardcoded velocity hack
this is not related to your issue but fun fact: if you are on a version of unity where the velocity property is called linearVelocity then you also have access to the linearVelocityX and linearVelocityY properties to only assign a single axis instead of both
(for anyone else reading this, this only applies to rigidbody2d which they are clearly using, not rigidbody)
yea i see it brought forth anew issue of during my first jump i only jump vertically and not in an angle as intended
great game, gj
not mine, im tyrna recreate the player controller of it tho
probably a dumb question but how do i resolve this error? quick actions and refactoring isnt helping much
why are the constructors private?
You have to invoke the parent constructor there if you want to do that
forgor
and the constructor will need to be at least protected to do that
AbilityCard(string cardName, Image cardGraphic, char identifier, int damate) : base(cardName, cardGraphic, identifier, damage) {}
whats the protected keyword do?
it's like private, but inheriting classes have access too
private = only this object has access
protected = this object and inheriting objects have access
public = all objects have access
internal = only objects within this assembly have access
Man I really wish we had access to the file modifier in Unity...
this is like when science teachers tell you there are only 3 states of matter and then you find out later there are secret more evil ones
well i knew abt protected from college but the teacher never explains why things exist and only just what they are
But they were all of them deceived, for another state of matter was made
wait until you find out about file
So guys whenever I put my script with the player movement and with animation, when I put the rigid body in, it doesn’t work like it it just straight up doesn’t work like the rigid rigid body just doesn’t work
does it work though?
the animation works and the player movement works but the rigid body is like not there
That doesn't make much sense
if you have a player movement script that works without a Rigidbody what's the Rigidbody for
Sounds like you're trying to mix multiple different forms of movement
that's a no-no
and it's not gonna work
In what way does it not work
like there’s no gravity on the player and the player can’t move
Does your animation affect the transform of the object
You would need to show your code etc
no
If you disable the animator component, does it properly fall and get controlled
So then your animation affects the transform of the object
oh
You shouldn't be animating the object with the rigidbody. Your mesh should be a child object of that
That way it can be animated without affecting movement
thanks
they shouldve called it privater
Depending on the circumstances it could actually be less private than private
Lol
see also: publicer staticer, which means the value is stored on the internet
a pvp-enabled zone
where's the battle royale access modifier where objects have to fight over access to a member and only the last survivor can do so
that's just the singleton pattern where objects destroy themselves
try {
//access variable
} catch {
Destroy(this);
}
publicer jsut exposes it to the whole ass network
and then u got publicerererererer which gives the observable universe access
Im tryinh to make procedural wall generation for the backrooms, and stumpled accross this video(https://www.youtube.com/watch?v=wQj-l0vDQsA that describes how he generates walls. At around 3:13 he slightly explains it but i have no clue how to actually do it. Could someone help?
What's the error?
if(Input.GetButtonDown("Jump"))
{
jumpPressed = true;
}
isGrounded = groundCheck();
playerVelocity.x = moveDir * moveSpeed;
}
void FixedUpdate()
{
// Jump Logic
if(jumpPressed && isGrounded)
{
rb2d.AddForce(Vector2.up * jumpHeight, ForceMode2D.Impulse);
jumpPressed = false;
}
rb2d.linearVelocityX = playerVelocity.x;
}
How could i write this easier without the if(Input.GetButtonDown)
I had jumpPressed = Input.GetButtonDown; before then i have huge input loss.
I need to press 10 times spacebar 😄
Someone can give me a hint how to handle Input in Update and AddForce in FixedUpdate?
the drawray dont show
Is that line running?
Like that
That's how you'd do that
oh you mean as a one liner
i dont know
Neither do I, since I do not have your computer in front of me.
Do a debug log to check
now its go to up
Is the issue still the DrawRay not working? Because I didn't see you ever go check it in the scene view to see if it was visible
Dude went into outer space . . .
I assume you just need to adjust JumpForce then
It’s either a jump force issue or a jumping multiple times issue, from the looks of it. I’d do a debug log for the jump, see if it’s getting called many times or just once, if it’s many times something’s wrong with your ground detection, otherwise, your jump force is too high
the game is not running
You have to be running and in scene view
i adjust the JumpForce to 5 and now is jumps, the ray dont show
Are you in scene view and the game is running?
Because here the game is running, but you are in the game view
And here you are in the scene view, but the game is not running
Sorry, if it shows, but below where I want.
Then you probably want to start it somewhere above transform.position
yes, in the center of the stickman
The first parameter of DrawRay is where you want it to start. Give it the location you actually want it to start at
Then draw the ray above transform.position instead of at transform.position
and how i can do this (sorry I dont have a very level of english and programing on c#)
Did you make the code yourself or copy paste from somewhere else?
I make my own code
using UnityEngine;
public class MoveStickman : MonoBehaviour
{
public float Speed;
public float JumpForce;
public float DistanceToGround;
private bool TouchGround;
private Rigidbody2D rb;
private Animator animator;
private float horizontal;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
horizontal = Input.GetAxisRaw("Horizontal");
animator.SetBool("Walking", horizontal != 0.0f);
if (horizontal < 0.0f) {
transform.localScale = new Vector3(-1.0f, 1.0f, 1.0f);
} else if (horizontal > 0.0f) {
transform.localScale = new Vector3(1.0f, 1.0f, 1.0f) ;
};
Debug.DrawRay(transform.position, Vector2.down, Color.red);
if (Physics2D.Raycast(transform.position, Vector2.down, DistanceToGround)) {
TouchGround = true;
} else {
TouchGround = false;
}
if ((Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.Space)) && TouchGround) {
Jump();
};
}
private void Jump()
{
rb.AddForce(Vector2.up * JumpForce, ForceMode2D.Impulse);
}
// FixedUpdate is called at a fixed interval and is independent of frame rate
private void FixedUpdate()
{
rb.linearVelocity = new Vector2(horizontal * Speed, rb.linearVelocity.y);
}
}
it is
Add a Vector2 with some positive y value to the transform.position in the draw ray to raise it
i know this is a weird question, but how do i make an object move almost towards the mouse?
and not exactly at the mouse position
is it generally okay to check something that may be null? there's a possibility that prevPlace will be null at the point of checking. I assume that won't throw any errors, or is this problematic?
if it could possibly be null then you definitely should null check it before actually using it. however you probably should store the objects returned by those method calls in variables if you will need to use them again (like in the if statement)
Define 'almost'
What are you trying to do
If you mean that you want to slightly offset the movement direction then get the proper direction vector and rotate it by however much you want
thanks for da advice :)
HI,im getting error here
public void SelectSP(GameObject SP)
{
if (selectedSPCount < 2)
{
selectedSPBox[selectedSPCount].SetActive(true);
//set seleced SP image and text
selectedSPsImages[selectedSPCount].GetComponent<Image>().image = SP.GetComponent<Image>().image; //error
selectedSPText[selectedSPCount].text = SP.name;
SPToSelectImages[selectedSPCount] = SP;
SP.SetActive(false);
selectedSPCount++;
}
}
ArgumentException: GetComponent requires that the requested component 'Image' derives from MonoBehaviour or Component or is an interface.
Do you have a script named Image
Check your namespaces
no
Or are you importing a namespace that does?
could be System image or something by accident instead of UnityEngine.UI
hover over the Image class, if its not from UI namespace, then its wrong one
The .image shows that it's definitely the wrong class, Unity's Image doesn't have a property by that name
yeah seems like they may be using the UIElements.Image
tru true. its just .sprite
those are all the import i have
using TMPro;
using UnityEngine;
using UnityEngine.UIElements;
the last one is wrong
import UI?
note that a using directive lets you name something without fully qualifying it
it's not actually an "import" directive, where you have to include it to access something at all
using Foo.Bar;
...
var x = new Foo.Bar.Buz();
var y = new Buz();
it's just there for convenience's sake
without the using directive, I could still have written new Foo.Bar.Buz()
I just couldn't have written new Buz()
Can anyone recommend a good resource for git patterns when working with another person? Right now we’re just sharing the asset dir without packages, but idk if that’ll scale well
the unity project should be the root of the git repo (including Assets, ProjectSettings, Packages etc...)
You should use a good gitignore to leave out stuff not needed: https://github.com/github/gitignore/blob/main/Unity.gitignore
that will ignore things like the Library folder as that doesn't need to be comitted. If you leave out the other important folders your project will have serious issues...
Ty!
there is no for loop
I need someone to teach me some stuff that i got stuck in my project
I don't want you to do it for me , I want you to teach me how to do it
You can dm me for more details but basically I need to add some stuff to my quake like fps game
1 voice line system , that works like duke nukem 3d were the character says a voice line depending on the situation
2 rigging enemies , I don't know why but I'm having a hard time adding animations to my enemies in the game , if you can help that would be great
3 gun movement, simple stuff I just want the gun to move when the player Walks and when the player shoots it
These are the main issues I'm having with the project right now , I would be very happy if you could help me
My dms are open
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
hello, ive adjusted the script to where its getting the current Selected Game Object, and vertical autoscrolling when at end. this script auto scrolls since im using keyboard to scroll. I dont want the auto scroll to happen on the last button going onto the next off screen but the button before the last one, so it starts auto scrolls on the one before last .
https://pastecode.io/s/5cszboon
ive been trying to make the current selected the one before the LastCheckedGameObject but cant figure it out
i can't understand what you're talking about here
I dont want the auto scroll to happen on the last button going onto the next off screen
this in particular
is the problem that, when you switch from one menu to another, you see it smoothly scrolling back to the top of the second menu?
rather than snapping instantly to the top?
is https://symbolserver.unity3d.com/ down for anyone else or just me
Its a list of buttons and when I scroll one down from the final, the auto scroll happens. My goal is to have the auto scroll happen before going to the button off screen. I want the auto scroll to move or act when Im on 2nd to last button going onto the last, not when im on last going onto the button offscreen.
Ah, so you need the scrolling to happen sooner
Values is a list of enum values and i am trying to get a value by its name, tostring only return the type
public static SP getSPByName(string name)
{
foreach (SP i in Values)
if (name == i.ToString())
return i;
return null;
}
temp variable names are cool and all but atleast keep them consistent 
is there an issue here? looks fine to me
what is SP?
its always return null, i.ToString() return the type of the enum ,i need the value name
short for SkillPower
But what is it
an enum? A class? A struct?
also what is Values
we need more context
gimme a moment i'll get it
return null seems not correct if it's an enum
consider Enum.GetName
They probably want GetName but there's a lot of missing pieces here . . .
you give it an enum type and an enum value, and it tells you the relevant name
These are some pretty general concepts, I’d highly reccomend you learn how to do it yourself. Break it down into specific steps, do as many as you can, then google the ones you don’t know how to do or ask here
(and allocates, iirc, yummy)
public class SoulPowers
{
public static readonly SoulPowers NONE = new SoulPowers(0, null, null, null, null);
public static readonly SoulPowers Fire = new SoulPowers(1, Skills.FIRE_KNOWLEDGE, SoulPowersAttacks.FIRE_PHOENIX, SoulPowersAttacks.FIRE_RUSH, SoulPowersAttacks.FIRE_FIRE_BLAST);
public static readonly SoulPowers Ice = new SoulPowers(2, Skills.ICE_KNOWLEDGE, SoulPowersAttacks.ICE_ICICLES, SoulPowersAttacks.ICE_ICE_STARS, SoulPowersAttacks.ICE_ICEBERG);
public int SoulPowersID { get; }
public Skills SoulPowersSkill { get; }
public SoulPowersAttacks[] AttacksList { get; }
private SoulPowers(int soulPowersID, Skills soulPowersSkill, SoulPowersAttacks attack1, SoulPowersAttacks attack2, SoulPowersAttacks attack3)
{
SoulPowersID = soulPowersID;
SoulPowersSkill = soulPowersSkill;
AttacksList = new SoulPowersAttacks[] { attack1, attack2, attack3 };
}
public static IEnumerable<SoulPowers> Values
{
get
{
yield return NONE;
yield return Fire;
yield return Ice;
}
}
public static SoulPowers getSoulPowerByName(string name)
{
foreach (SoulPowers sp in Values)
if (name == sp.ToString())
return sp;
return null;
}
}
So it's a class
not an enum
Read this to properly send your code, and/or to format it . . .
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 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 want ToString() to do somethjing special, you need to implement it @honest iron
the default ToString for a class will just print the type
need to use calss because c# not support that kind of enum,if only enum in c# was easier like java
there is no need for a class
you can do this with extension methods
but either way
if you are using a class
you must implement ToString
or another function that returns the string you want
I was a little confused by how ToString was somehow producing the type name
that explains it
im used to do it in java
ok, well now you're in C#
somehow my scroll rect cant scroll to the bottom, theres always one element that is "out of window" , like u can drag the scroll to see it, but it will bounce back again
for sure
C# enums are ints with hats
is there a ContentSizeFitter on the "Content" object?
if not, add one and then set it to control the vertical axis
(go for 'preferred' size)
nope 😭
the Content object also needs a vertical layout group
set it to control child size and to not force expand children
i think i'll just use switch for that
together, these will:
- make the Content object request enough space to show all of the children
- resize the Content object based on how much space it wants
i got the layout group, but i havent added any of the fitter
make sure you set it to control child size
Force Expand will make it do...interesting stuff
most of the UI i made dont really get to use that stuff tho
and i havent checked use child scale once
That looks correct
is there a way to get sprite from assets without making pulic varible in the script?
why?
i am trying to set image(sprite) and there is too many images to add them all
i wanted to make class just for that, class the holds all the sprites and i can just get whatever i need from it
i suppose that, if you have a huge number of assets with predictable names, you could load them from a Resources folder.
but I'm unclear on why you'd want to do this, instead of just assigning the sprites directly where they're needed
i have a image that can be changed to 1 from 8 options, if i could just get the sprite from the without add it from unity i could just add it to an enum the related to this image
here an exapmle of what im tying to do
public static readonly SoulPowers Ice = new SoulPowers(XXXX,2);
playerSoulPowerImage.sprite = SoulPowers.ICON
so, for example, you might have an 8-by-100 sprite sheet
100 unique "things"
and each one has one of eight types
have you tried an array?
yes , i wanted to make a class full of arraies just for the sprites, but i need the class to be static
so i need to remove MonoBehaviour
which leads to error ; 'ObjectsImagesList' is missing the class attribute 'ExtensionOfNativeClass'!
im also looking for a better name for the classs
I have a character prefab that contains an Animator with an AnimationController attached. Multiple GameObjects are instantiated using that prefab. Does each instantiated GameObject get their own unique copy of the Animator and AnimatorController when instantiated?
I ask because when I invoke an animation through GameObject.GetComponent<Animator>().Play("...") on one of the objects, the animation is playing on all prefab objects.
A tool for sharing your source code with the world!
Yes each instantiated copy will have their own components. You can see it in the scene
Show the actual code. You're likely calling this code on every object
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 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.
thanks ill do that instead
A tool for sharing your source code with the world!
i still need help
how can i add sprites from unity
public static class ImagesClass
{
public static Sprite[] Weapons = new Sprite[8];
public static Sprite[] SoulPowers = new Sprite[5];
}
i've added the script to a gameobject
why are they static?
i want to reach the arries from everywhere in the project
whats that
makes it so you can access an instance of a class from anywhere and ideally is the only instance
https://gamedevbeginner.com/singletons-in-unity-the-right-way/
https://unity.huh.how/references/singletons
most important can make the fields regular ones that can be used in unity inspector (drag n drop) references
yes, sorry I was a little busy
from what i read do far i don't think singletom will be much useful, it will be simple to just create a Instance of the class and make it static from my main clas
i might be wrong
still not expert with that
if it wasn't useful I don't think I would've recommended it though
you can't have static variables and expect them to show up / be linked in the inspector
if you're only sharing the same asset list of images through specific classes / objects, you could also use a scriptable object too
You must've misread what singleton is then
hey, how i can make that i have to wait till an animation ends to do x thing. For example, when my enemy gets out of bullets, it has to reload, wich displays the reloading animation and then returns the bullets to it original amount. How i can archive the wait?
couple of ways actually.
Animation event, or Animation state machine methods, or good ol polling the state w/ bool
wich one would be the most simple to understand?
can you give me an example
use an animation event would be the simplest way
this is the script btw
{
if (balas > 0)
{
GameObject nuevoProyectil = Instantiate(proyectil, proyectilposition.position, Quaternion.identity);
Vector3 direccion = (objetivo.position - proyectilposition.position).normalized;
Rigidbody2D rb = nuevoProyectil.GetComponent<Rigidbody2D>();
if (rb != null)
{
rb.linearVelocity = direccion * bulletspeed; // Ajusta la velocidad según sea necesario
}
balas--;
}
else
{
//Here its the reload thing
}
}```
animation event is indeed the simplest, just has 1 major drawback is being aware of transitions could skip the key so pay attention to those
sure one sec
what do you mean transitions?
i mean cuz its 2D, and every animation in the animator i have set all transition and stuff to 0
also how many classes will be accessing these resources?
1 sec
yes I mean the animation transition between states
O H
then how i do it, cuz i need to have the transition set to zero in the animator
or so i thought
i didnt even added all the images
public class ImageClass : MonoBehaviour
{
public Sprite[] Weapons = new Sprite[8];
public Sprite[] SoulPowers = new Sprite[5];
}
there will be more
the meaning is that, for example, if your enemy's roloading aniamtion was interrupted by a hurt animation or other stuff, the reloading success event will never be triggered actually
public class ImageResources : MonoBehaviour
{
public Sprite[] Weapons = new Sprite[8];
public Sprite[] SoulPowers = new Sprite[5];
public static ImageResources Instance { get; private set; }
}```
then do the Awake Instance assignment as shown in the links I snent
you can easily access
ImageResources .Instance.Weapons
and you need other game logic to help you with that, such as a repeat reloading mechanic or sth on the enemy ai
the idea was that the reloading overrider all kind of animation, but the idea of restarting the reload doesn't sound too bad
im pretty noob in the animation part btw, that's why i rather to let it zero, as i saw that works for 2D stuff
oki, it all depends on how you design it
there is always this too
https://docs.unity3d.com/ScriptReference/StateMachineBehaviour.OnStateMachineExit.html
https://docs.unity3d.com/ScriptReference/StateMachineBehaviour.html
its not too complex
ok testing
testing what?
im testing if it works
I didn't send the whole thing you still have to assign the Instance to itself
(#💻┃code-beginner message second link shows exactly how to write it)
it was example
I'm not here to write the entire thing for you lol
btw what u meant with the state w/ bool?
well there is basically this
Animator.GetCurrentAnimatorStateInfo
which can check this https://docs.unity3d.com/2020.1/Documentation/ScriptReference/AnimatorStateInfo.IsName.html
so onceyou start a reloading coroutine or bool in update, you can wait the bool to become false again
Hello I was wondering if anyone can help me (or at least just explain to me) how to make it so you can deactivate certain game objects so its not able to be able to move when the camera isnt focused on it. I'm trying to make it so only one of my game objects moves/is able to be controlled by the player when the camera is focused on it. I have my code for my camera and code for each vehicle/player object if that would be helpful. (hopefully this makes sense)
Just enable/disable the movement scripts as needed
When you "deselect" the object, disable its movement script.
When you select the object, enable it
Animator anim;
bool reloadingAnimation;
bool reloading;
private void Update(){
if(reloading){
reloadingAnimation = anim.GetCurrentAnimatorStateInfo(0).IsName("reloadAnimState");
}
}
IEnumerator Reloading(){
//reloading
while (reloadingAnimation)
{
yield return null;
}
reloading = false;
//done reloading
}```
obv dont know ur full setup so prob missed something but roughly
oh waos, thanks a lot!
o<o
oh okay its just an example, don't just copy and paste it lol if you have questions ask them
there is obv still StartCoroutine missing and all that
you probably can do the entire thing in update but its late my brain aint brainin
ok xd i knew it i was just gonna analyze it, but thanks :3
But yeah...sorry if this sounds dumb, but how you entered into the IEnumerator?
oh, ok
you can easly call the coroutine when you start the reload process
if it needs to be in update put it behind a corutine variable or another bool
never StartCoroutine in update without those safety checks, aka start one every frame
i also have to play the animation, right?
well yeah, the name of the state is what its looking for
i mean, add the script that activates it, the currentstateinfo will not do it for me
nice
This might sound like a silly question but how exactly would i do that. Is there a example of video unity has that might help me?
I think the person who was about to help me went to sleep so im resending, ive adjusted the script to where its getting the current Selected Game Object, and vertical autoscrolling when at end. this script auto scrolls since im using keyboard to scroll. I dont want the auto scroll to happen on the last button going onto the next off screen but the button before the last one, so it starts auto scrolls on the one before last .
https://pastecode.io/s/5cszboon
Its a list of buttons and when I scroll one down from the final, the auto scroll happens. My goal is to have the auto scroll happen before going to the button off screen. I want the auto scroll to move or act when Im on 2nd to last button going onto the last, not when im on last going onto the button offscreen. basically I need the autoscroll to happen one button sooner
currentStateInfo just checks which one of those gray boxes you're in. Aka the States in animator
got it
What? Disable or enable a script?
You reference it and call .enabled = true or false on the reference
i got it to work, thanks
Sounds like maybe you need to just learn unity basics first?
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
but im still curious why is it better than creating instance of the class?
Thank you. I know very little about unity (did one full lesson about basic movement/ camera movement) Thank you though!
wdym creating instance of the class ?
putting the script on a gameobject literally IS the instance
You are still creating one instance of the class.
ImageResources sss = new ImageResources();
thats poco way of creation yes
MonoBehaviours don't work like that
when put put MonoBehaviour script on gameobject that creates the instance
then you're just setting the current one you got on that object as the static variable to hold it
holup, just analyzing
This means when the enemy dries on bullets, it will make bool reloading true and in the same time StartCoroutine(Reload())?
???
{
if (balas > 0)
{
GameObject nuevoProyectil = Instantiate(proyectil, proyectilposition.position, Quaternion.identity);
Vector3 direccion = (objetivo.position - proyectilposition.position).normalized;
Rigidbody2D rb = nuevoProyectil.GetComponent<Rigidbody2D>();
if (rb != null)
{
rb.linearVelocity = direccion * bulletspeed; // Ajusta la velocidad según sea necesario
}
balas--;
}
else
{
animator.Play("Base Layer.MortemRifleReload");
reload = true;
StartCoroutine(Reload());
}```
is this in update you need a way to stop it from calling Reload coroutine every frame
no, its on it own
what is on it own?
anyway just in case you can docs if(reload) return; animator.Play("Base Layer.MortemRifleReload"); reload = true; StartCoroutine(Reload());
just set it back to false in coroutine and ur golden
ooooooooooooooooooooooooooooooh, so i have only to make reload true. ok
Btw i have to paste this is update, right?
hey btw, this means for default, reload and reloadanimation are false, right?
you already made reload true 🤔
no but i mean, Only that, not start the coroutine, cuz the reload if state its going to do that
idk, i still need to get instance of the class whenever i want to use it, i was looking for a way to just get from it without instance(static)
what i mean is, i only have to do this in the shooting area
{
reload = true;
}```
ur literally getting the instance... its just stored in a static variable for easy access rather then grabbing the entire static class
...hey...
what diferences using booleans for ifes, and spawning methods?
spawning entire voids?
for example, what diferences this
{
bullettimer -= Time.deltaTime;
if (bullettimer <= 0)
{
bullettimer = firingspeed;
disparar();
}
}```
those are called functions / methods not voids
void is a return value for methods
from this
{
bullettimer -= Time.deltaTime;
if (bullettimer <= 0)
{
bullettimer = firingspeed;
disparar = true;
}
}```
and make it an if scenario instead of a method
bool and method have different purposes
i mean, they work completely different...but their....purposes...mmm
i mean yes, but..........
the only common thing would be assigning values
i dont understand the problem lol you aren't being clear
sorry
if its working why is not good
OCD lol
just want to make sure you know whats happening in that code and why yours wasn't fit for unity
let me rephrase it
what prevents me from making the shooting an if scenario instead of a method, and make the reload an method instead of an if scenario?
im used for xxxx.ttt here is xxx.yyy.zzz
nothing is preventing you, if you want to make it a method do so, you still need bools no matter what you choose
yeah, im sill new to unity
one belongs to the class itself, and one belongs to an Instance created from that class
with preventing i mean, with what consequences i would have
of course i can do it, but i wanna know what's optimal for scripting...its just sometimes i get anxious my scripts may be bad written ;-;
like, "i did x thing in the worst way possible"
like the informatic meme of the cow walking with it udders explaining my exact issue
Unity cannot use Static variables in the inspector, nor can you put a static class on a gameobject, the only way you'd be able to assign those images is doing a Resources.Load fill or some other gameobject with serialized fields to pass those to static class.. At that point you mind as well skip the middle man gameoject and keep them on an actual gameobject that has component to serves them, since they can be easily linked in inspector this way
What is the best way to tackle slope movement for a 2D game
Because in some games the character moves flawlessly on slopes but I'm having a lot of issues with that
optimal script is a script that does the thing you want it to do . period lol
anything else is extra unnecessary worry
as long as you know..just dont make the code unreadable to you , and possibly others that you might need help from
this is pretty vague
oh well, thanks :3
Like moving at an angle or maybe not being able to move at a max-angle
Basic slope movements, I tried before and haven't got far...I'd love to get that out of the way soon
was more talking about this
I'm having a lot of issues with that
what issues exactly? no one can help without knowing
I have these slopes for example...I want my character to move on it without sliding or slowing down...
ahh trig math here we goo
I guess "slope-bounce" also is another problem with that
Because if I run down I guess my character doesn't stick to the surface
Damn it, well I'm sin-ing off
Cosined by me
I could go on a tangent with this
might want to raycast to get the slope angle then adjust your velocity / direction accordingly
Should I keep the slope method seperate or can I do it all in the ground-check...?
Since I'm using tilesets, and it's all mostly one layer
I haven't messed with Rigidbodies based controllers fully, but for CC I had it skipping slopes and thats what I did
you're not looking for the gameobject / visuals
its just looks for colliders
Oh ok nice, kind of like a ground check or wall check
and their normal compared to Vup
pretty much
I just have to figure out the deal with slopes, I'll try working on that soon
if you have raycast for ground, use the same ray
look for hit.normal
hey, this is not an issue i have, just an interesting thing i had in mind. Its a bad idea to mess with friction? i mean, i was thinking for make the always desired "m o m e n t u m", make that when i press a button to move the player, disable it friction, making it well, speed up in slopes and etc, and when the player releases the move buttons, for 2 seconds delays then it regains it friction. It may work, or bad idea?

the issue is that for do my experiment, i practically have to make a whole new game, i just wanted to know if it was worth it
just test it in a seperate project whats the big deal?
t i m e
but sure, its not a big big deal, it just that it was pretty xd
I find it good to take a break from the same project once in a while
sounds fair
tf. someone just spammed your tag and prob got yeeted lol
seen u guys were helping someone else, thought id ask now but ive adjusted the script to where its getting the current Selected Game Object, and vertical autoscrolling when at end. this script auto scrolls since im using keyboard to scroll. I dont want the auto scroll to happen on the last button going onto the next off screen but the button before the last one, so it starts auto scrolls on the one before last .
https://pastecode.io/s/5cszboon
Its a list of buttons and when I scroll one down from the final, the auto scroll happens. My goal is to have the auto scroll happen before going to the button off screen. I want the auto scroll to move or act when Im on 2nd to last button going onto the last, not when im on last going onto the button offscreen. basically I need the autoscroll to happen one button sooner
since im not sure i have to ask
is its alright to give a single gameobject planty of scripts
generally its okay as long as you don't mind the clutter
like, player(gameobject) get scripts for movement, actions, attacks, inventory,skills, ect...
ok
tnx
wtf Im on mobile discord rn and I tried to send smth and my discord got fucked i tried closing it and it just spammed my message 100 times?!
sry for the spam tag on whoever it was, I thought I was gone forever 😭😭
probably a mobile user. there's a weird bug with mobile where messages get duplicated. the amount varies
oh nvm, i probably should've read down a little more 
/*
if (card is a DamageCard)
{
do stuff
}
*/
how would i do something like this?
card is an instance of the Card abstract class, and DamageCard inherets it
theres other card types that dont do damage, so i want to check to see if the card field contains a DamageCard
Almost exactly like that
wait is my psuedocode just like actually how you do it?? 😭
just add a variable after DamageCard to do stuff with it
if (card is DamageCard damageCard)
if (card is DamageCard dc) {
Debug.Log("Damage amount is " + dc.Damage);
}```
wdym?
Like, you should generally rely on polymorphism to get different behaviors from different subclasses
Abstract or virtual methods or properties. That sort of thing
eh, thats prob fair but im makin a gamejam game so im tryna not spend too much time on certain things, ill keep that in mind tho when i do something that needs somethin like this in the future tho
I did this in the game I'm working on currently. BUT I am not using any built in physics for the controller.
it does give a very nice and responsive control
I stop adding friction when moving and add it when not
I mean there’s def some times I use it…for example my projectile collisions loop through all the hitboxes and check if they’re an instance of player/enemy base class depending on if it’s a friendly or enemy projectile
How do they check
Oh I’m not using unity so it wouldn’t really apply
Actually that example I gave is really bad since unity handles collisions and you can get a reference to whatever you collided with
Though you’d still have to check if it’s an enemy so ig it still works
ye and unity has tags and layers which would be much faster than comparing classes
That too
the way you phrase it makes it sound like you're working with roblox ?
Java swing 😭
Its a Java library made for little pop ups like “enter your age” and such
Thought it’d be fun to make a game using it
It’s not
im about to put my head through a wall trying to implement the new action map, can anyone help me understand how im supposed to connect it to my character and c# script?
im following every tutorial and just getting nonstop errors, and even chatgpt has no idea whats going on
Makes stuff like this (except in my case obv)
generate the C# class from the asset it will be the cleanest, or use Messages mode
i did, but then i go to implement it into vector2 movements and it says it cant find my input map
show code@
i can just ask in input system though if theres a dedicated channel for that tho
i dont want to use the wrong place
sounds like a code problem. your inputs are correct looking
either that or you forgot to put a player input component on the thing you're trying to control, but you wouldn't get errors without doing that.. I think
player input component is unecessary if they generated the c# class
im doing some of this to connect it
can you explain more @nav ? then how am i supposed to implement it to my character controller? or is that even necessary?
show the actual asset inspector
thats not the asset
im sorry - im super new to this but im a coder by profession, so i just want to actually LEARN the code instead of downloading a controller
That shit is from like 1996 and it's a UI library lol
i guess im confused what you mean by the asset
thought you said you generated the class from it thats ..
click the input Actions where it says Input Action Asset, and select that
Exactly. Say you’re a hiring manager for idk Google and one of the applicants managed to make a full fledged game in Java swing without going mentally insane. That shows pure, raw, unfiltered determination.
you talking about this?
thats the asset . yes. Also lets move it to #🖱️┃input-system
Plus when I go back to unity I’ll be so grateful for it being an actual game engine
I don't know if this is the correct channel, but does anyone know why this character is in the scene and how to get rid of him?
If I had to guess, the player or one of its children is probably rendering in that sprite with a sprite renderer
Waos, looks cool
is there a way to link gameobject to an Instance(class) from the script?
Wdym by link
Like add the script to the game object as a component? Give the script a reference to the game object?
lets say that i have 10 items (Instance) i want to give every gameobject one item, and if i click that gameobject i can use this item
That's very vague
What does it mean to "give a GameObject an item"
Are you talking about attaching components?
no
Then it's very unclear what you mean
let me find another way to explin
i have skills, i create gameobject for every skill, every skill has an Instance, when i press that skill i want to see more infomation from that Instance, but to do that i need to find the Instance that belong to the skill
What do you mean “instance”
is there a way to add that Instance to the gameobject so i wont have to find it every time i want to
it's very simple, I can share the code if you want for the controller though it's not something you can just copy and paste
Instance of a diff GameObject?
List<Skill>[] Skills = new List<Skill>[5]; , Instance of skill
Okay so you have a list of the Skill base class
It's weird/confusing to me that a skill would be a GameObject, to be perfeectly honest.
im making a gameobject for every skill with the skill image
ah so they are UI elements?
the gameobject are, yes
So these are not skills. These are UI elements representing the skills int he UI.
But the skills themselves would be something else, presumably.
Why can’t the subclass skill script just be a component of the ui element
Hello everyone, im new in C# and unity, and im just trying it out for fun, and to make games for hobbie, do you have any recomendation for a starting first game as begginer like me? (btw i can do 2d or 3d art, but ill prefered 2d) (sorry for interrupting just like that)
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
if you add me I'd be interested seeing your portfolio
let me try explin what i want to do in another way
Don’t use ai, don’t use YouTube tutorials, don’t copy and paste code unless you know exactly what each line does. Use unity learn for unity specific coding basics and (id recommend) codecademy to learn general c#. Start small, try your best, and we’re here to help if you’re stuck
thanks, ill do my best
gameobj.add(s1);```
when gameobj is clicked
public void func(){
gameobj.getSkill()
}
something like that
small objection: AI is very useful for finding learning resources about the topic but don't use just the raw AI to learn the topic
Yes yes ai can explain coding concepts very well I should’ve specified
Don’t have ai generate your code
I don't mean that
Oh
I mean using AI search to find human written articles, videos, documentation related to the topics you're interested in
that way you're much more likely to actually learn from something trustworthy
Ah I see what you mean
what is skill supposed to attached to ?
does Skill do anything?
im looking for a way to attach to gameobject
Skill s1 = new Skill("name",15);
gameobj.add(s1);```
Doesn't this imply you are talking about adding components to GameObjects?