#💻┃code-beginner
1 messages · Page 170 of 1
if (realAge is int)
``` ?
you can check and cast at the same time
anyone know how can i put the same color on the background?
You can give an identifier after that and just use that new variable inside the if
React tranform. 3 dots on the right. Reset?
Change the background color of the camera
switch(age)
{
case int x:
//do int things
break;
case float y:
//do float things
break;
}
you almost never need to use the actual System.Type object for type checking something
Son of a bitch they Cunningham's Law'd both of us
nor that u need to check for type
user input always must be checked and sterialized
Amount of crashes I had when I worked with user imput not being checked is a lot
how?
tbf type checking the input this way is incorrect anyway 🤷♂️
can't cast a string to a numeric type
Im pretty sure compiler gonna complain
@ebon robin i think i need to find a way to prevent the attack animations from playing when the enemy is moving
wont best way be adding a variable that saves the gamestate and then check it?
Environment tab
Like make attack bool variable and have if (attack) return;
what?
in the camera
in the camera
i'll try somethings after dinner. Thx
Oh right, on a non-URP project it's just right there. In URP it's in Environment but it's still there
thank you my man
how do i fix my code so when i look at a game object and click e it rotates/spins my thorw and change size ones work?
You can use raycasting to find out when you are looking at an object:
https://docs.unity3d.com/Manual/CameraRays.html
i have that part working
is it 3d or 2d?
3d
float angle = rotationSpeed * Time.deltaTime;
transform.rotation *= Quaternion.AngleAxis(angle, Vector3.forward);
This is spat out by chatgpt. Looks somewhat legit
its for school so they having me do stuff weridly
a prefab can do close to anything a gameobject can
i been trying to put what they want me to do then work off that
my script is still broken can i get som ehelp
yeye i actually did it from the playercontrollerscript in the end @tepid summit but it was not working cause i didn't put a capital letter on "IsDashing" parameter in my script
it was like animator.SetBool("isDashing") instead of ("IsDashing")
they told me to? what should i do instead
Better yet when you named a variable and instantly forgot it
Just name it something else
oh yeah
it's not an error, but it's an annoying warning
yeah
they can tell whatever calling rigidbody rigidbody even compiler complains
ah i just dont pay attion to it unless its red
Yes, let me just get in contact with my spy network to break into your machine and post the code and the error that I cannot see
so i couldnt fix them if i tried
i was seeing if anyone was available first
jesus
Its just calling things what they are next time you will try to call Rigidbody you will call your variable
It's incredibly rude to come to a help forum and expect people to commit to solving your problem before you've even said what it is
with chatgpt today its quite convinent
You can have no idea what u want and feed wall of text to it
And it might spit it out
i never expected someone to commit to fixing my issue
iwas asking
its a perspective thing
If it knows the code bad it hallucinates tho
I worked with Paradox script and it constantly messed up
until it just straight up invents a new function that doesn't exist and then you post the question here and swear up and down the function exists because the spambot told you it did and you don't understand any of the code anyway because you let the chat robot do it for you
Yeah it loves doing that
mate if you're asking for help before even providing any info about the issue, then yes, you are in fact asking someone to commit to helping you
Its a tool
you can tell chat gpt that 2 + 2 is 5 and it'll say that you're correct and apologize for the inconvenient
true
whelp gpt might be on to something but it dosnt follow the rule i have to use
I remember feeding it 2 lists of names, I was trying to filter out list of mods I had repeated to update a collection.
It couldnt do it...
Ive spent 20 minutes telling him REMOVE repeated entries
It just spat me filtered list...
let me open the project
nice
Tho it instantly gave me pyton code to filter them myself
yeah
Its getting lazy
because python is usually simple/easy
i'd say that gpt can give you a structure but most of the times you need to adjust it
what isnt tho
Before it was much better
At some point it got really bad
like you feed him part of function it calls something wrong in it and gives you back THE SAME function
{
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity))
{
if (Input.GetMouseButtonDown(0))
{
Destroy(RaycastHit.transform.gameObject ; GameObject);
}
}
}```
love that
Destroy(RaycastHit.transform.gameObject ; GameObject);
what fresh hell is this
one time i got it to make a pretty ok terrain generator
dude
there are beginner c# courses pinned in this channel. you should do them instead of wasting your time not understanding how to write code
read the channel name
Lmao wtat
of course my codes gonna be bad
Like what language is that even
also what happened to "that's not my issue anymore"
the error changed
yeah because you didn't know how to correctly do the thing you were trying to do
Because this is pure nonsense
seriously, go through some basic c# courses and maybe you'll actually have a chance at succeeding when attempting to do it yourself (again)
i tired relaying on other scrpits to kinda guide me and im some how back at the smae spot
even chatgpt cant fix that
what u event want to do with this?
Normally hits are counted with OnTrigger or
with function
they want to destroy a gameobject hit by a raycast
what is raycast?
im working on the rotation one
so i have my raycast code so when i look at object i can interact with E and it can do things if i make scripts for it like i have that kick it accros room and one to change size i still need roataion and 2 more
changed the function entirely
public GameObject Tile;
void FixedUpdate()
{
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity))
{
if (Input.GetMouseButtonDown(0))
{
if(hit.transform.tag == "tiles")
{
Tile = hit.gameObject;
}
else
{
Tile = null;
}
}
}
}```
this is what i got
What is this code supposed to do? like real question
the instruction i was given and my error and raycast
Vector3.left is not a function
then how do i fix it cause it say left right up forward down backwards are all not viable so i tried .one and it also said the error
none of those are methods. those are all properties. what are you expecting them to do?
None of those are functions. Those are values
string name = "Bob";
int length = name.Length;
Since 'B' is at the index of 0, shouldn't i put name.Length-1?
cuz u know, "Bob" length would be 3 letters, while 'b' at the end is at the index of 2.
for what
This is just assigning two variables
Typewritter effect, just an example here
again, your non-unity related c# learning questions belong in the c# discord.
This might be unity related tho, how can u know
historical data
not sure tbh the end goal is so when i look at game object with my raycast code and click e the raycast code tells the other code to run and rn i have it set to spin and my object wont spin cause this error i have my course instruction if that helps
Leave something to us people who more or less know C# but are dealing with unity and bored
because i'm not a fucking moron and know you are going through some c# courses
thats basic C# code, thats simple code u can run standalone.. theres nothing Unity related to it
woldnt it be easier to detect hit in other object script?
that doesn't answer the question i asked. what are you expecting Vector3.left or Vector3.one or whatever to do. why are you trying to use it like a method
While this is true, if i want to add a textbox into my game, with typewritter effect, this would be exactly how i'd do it
But, like, what were you expecting this function to do
Now, when I sync the script with the game object after rendering the line, I get this error. Can anyone help me with this?
it eould but they want it "neat and clean" and i would rather do it my way but they would take that as an option
Make sure that there are no compile errors and tha the file name and class name match
what you mean by neat an clean?
Make sure that there are no compile errors and that the script name and class name match
ya, why not be clever, and add a text field to the code.. and then ask ur almost unity related questions 😄
spin a gameobject along the vertical axis kinda like spintop
what makes you think Vector3.left would do anything at all related to that?
those are my instruction
So, why not look for a function that rotates an object, instead of just making one up
idk im still trying to learn tbh
so you just guessed? or was it code given to you by an AI? we're trying to understand the thought process behind the choice to write that
Vector3.left is just a Vector.. (1,0,0);
i honestly just kinda mushed my other scripts that were simaler and changed few thing and thought it would work
atleast ur honest
its what ive done this whole course
Or you could use Google and actually learn something instead of just trusting the spam generator
Im just dealing with background rn
ya but i dont think it follows my rules/ instructions
And I dont understand vectors really well
it is against server rules to answer questions using AI generated responses
oh sorry didnt know
tysm ill see what i can do or come up with to use it
its one of those first fundamental things u learn, shouldnt be hard to find a solution that works
wait what did you thought it was?
ya, thats all it tells u
to name it that..
then u can do w/e u want inside of
as long as it rotates an object b/c of a player interaction
and those are also just examples it says
lol
please learn how C# works
🤦♂️ god i hate this course thanks
what is even that course?
highschool game-dev
mastery coding | unity 1
We got thrown from 2d to 3d back to 2d
there ya go, its a course written up by his professor, its not an online course
I have a suspition it was written long ago
I had a teacher that reused same exam for like 12 years
its new this year my professor didnt make it
sometimes its feasible
tbh he dosnt do much
like mathmatics dont change much.. so why make a new exam/
I mean everyone had a copy of it
ohh, lol
yeah
let me buy a copy of that exam u took last year pal
For last 12 years XD
How to save scene in play mode. I edited few things and want to save it on place they are
u copy the values of the things u changed and paste them in when ur not in playmode 😄
There are add-ons for doing that. It's not something Unity provides.
I dont think thats possible to copy
well, Cinemachine has some code for remembering vcam modifications
ya all changes in playmode revert back to defualt when u quit
yea some components keep their values
but not most
Yeah it makes sence, but when you want to change something :C
i keep a notepad next to me to jot down new values for that exact reason
best method ive found so far.
Yeah I know that I just moved a lot of things
ohh well gl 😄
Actually its a completely generic attribute that works on any MonoBehaviour
wait, whats the attribute?
Im still torn of adding to our package but we use cinemachine for every project so….
ive looked actually in the four corners of the universe
i went to the 3rd page oif google
well i tried my way and idk why thats not vaild
ur class doesn't have a variable called objectTransform
and update() is wrong.. its actually Update()
transform.Rotate <-- this would rotate the transform thats attached to the script
but if u want to use objectTransform u need to declare and assign it
... ight ill try againg ty
what?
G ty il let you know if it works
Where did clouds go??
idk click them in the hiearchy and find out
They are in the scene.
Thats the same thing but one is in Game other is scene
they jsut gone?
i know.. CLICK THE OBJECT in the hiearchy and look at the gizmos in teh scene (while the game is playing)
it'll have a gizmo on top of em (itll show where it is)
lol it spins but not when i interact with it it dose right off start
Because you made it just spin al time I belive
yeah your toogle turnin does nithing in that code
you need
if(IsTurning) your code
ohh ya its in update not a if isturning true
hover over the scene view and press F with ur object selected
if you want you can make something like this
it will snap to it.. and then you'll atleast know where it is
using if and if else do i need to end on an else? or can i just use if else
@terse yacht the assignment actually says to use Player interaction.. so u need more than just spinning.. u need to check for inputs (from the player) and then make hte thing spin
private IEnumerator rotate()
{
while (true)
{
while (isRotating)
{
//rotate object
}
}
}
ya ik thats what i been tempting i have my raycast code so when i look at object and tap E it runs the code it works for my throwing and change size
thatll work iguses
i just need to fin out how to make my if statement be ran when the interaction happens cause i looked at my other ones i have and tbh i dont have a single clue even how they do run
hey everyone, could someone help me please? I'm making a character controller with the input system and I'm having some troubles with interactions.
When I press E it seems that the button sends multiple actions.
Here in the video you can see that 3 cubes get created instead of 1 and I get damaged three times instead of one too
I think the problem is within this code
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class Iteractor : MonoBehaviour
{
public GameObject cam;
public float reachDistance = 8.0f;
public LayerMask layerMask;
private PlayerUI playerUI;
private void Start()
{
playerUI = GetComponent<PlayerUI>();
playerUI.UpdateText(string.Empty);
}
public void OnInteract(InputAction.CallbackContext context)
{
Interact();
}
private void Update()
{
playerUI.UpdateText(string.Empty);
}
public void Interact()
{
playerUI.UpdateText(string.Empty);
Ray ray = new Ray();
ray.direction = cam.transform.TransformDirection(Vector3.forward);
ray.origin = cam.transform.position;
RaycastHit hit;
if (Physics.Raycast(ray, out hit, reachDistance, layerMask))
{
hit.collider.gameObject.GetComponent<IUseable>().BaseUse();
if (hit.collider.gameObject.GetComponent<IUseable>() != null)
playerUI.UpdateText(hit.collider.gameObject.GetComponent<IUseable>().promptMessage);
}
Debug.DrawRay(ray.origin, ray.direction, Color.red);
}
}```
or ya its the way its set up in the input manager
its set up like this
You can make discord read that code as C# by just writing it like this
/``C#
Code
```
oh oke thx
not at all
!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.
this is what i meant
not sure how to get to this menu as i dont use that system, but that thread should point u the right way
Yeah its same as C# of CS to mark code as C sharp
u can set the key to be a single press if u want..
oh I'm going to try it then, I did try before but I think I did something wrong
if u can assign them in the inspector
private with [SerializeField] is preferred
public GameObject ^ that
or
when making code for onclick on a button should i put the code in start() or update()
but u'll know whether or not u need public or private variables
Neither... It needs to be its own function.
im so lost idk how in any way my other two scripts even interact on E with raycast
I mean its app as asigment so I dont think it really matters that its not protected
stg going to lose it
so outside both of them
tried and still doesnt work 😔
I need to create a jumpscare, like when both of the hitboxes collide, the video appears and when the video ends the lvl restart, im new and this is taking me a lot of time and im not able to do it, can somene give me a hand please? (I want that when the enemy catches u, the video appears like a jumpscare and then restart the scene)
Ping me if u know how to do it, because im lost
Break it down into steps and tell us where you're stuck at
Which part are you struggling with specifically? You've listed 4 different problems here
just the part where the hitbox collide and the video appears to restart the level
the video part is easy, use a video player, and play a clip
I had a breakdown and i deleted the script because i couldnt even do it with the help of ChatGPT, so thats why I said I was lost, xd
That again is multiple problems in 1. Break it down further
First try to detect collision, then do something based on that collision.
Then learn to play video. Then learn how to know when the video ends
restart deletes all object so be sure you do it after video finishes
he can start coruitine with wait time as of video leight
is the game 2d or 3d?
3D
Using GPT when you don't know what you're doing is the worst choice possible
the video player probably has a property like isPlaying();
Yeah, i checked that
I tried isPlaying once and for some reason it didnt work as intended. So I just went with corutine with
yeild return new WaitInSeconds(effect.leight)
Something similar
This is a code channel, maybe you want #archived-lighting or something else
im still stuck idk how the other scripts even work with the interact raycast code and i need to find out how so i can link my spinning one to it
put this script onto ur enemy (and make sure both have a collider component too)
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Player"))
{
// play video
}
}
and give the player the "Player" tag through this https://docs.unity3d.com/uploads/Main/tag-dropdown.png
Hello guys I have a problem with animations. I have an Idle Animation and a running animation. When i stop running, the sprite looks like the last frame of the run but the idle animation continues. Can i send a video her to show that?
can i do that? its circled and grey so im not sure if its meant to be called something specific..
but like surely you can name it anything you want
It's gray because nothing is using it
For some reason my visual studio cant detect unity Update, Start, etc
So probably correct but same issue
so once i put some code in it it'll change?
no
If that code uses that function
im so lost idk how in any way my other two scripts even interact on E with raycast
#💻┃code-beginner message
#💻┃code-beginner message
i posted yesterday on how to use events.. the same thing would kinda apply to ur event.. in the script doing the check it would have the event.. u fire that event off when u click or w/e and then in ur other scripts they'd be subscribed to that event.. and when the event goes offf anything listening will act on it
I was able to found the script, this is what i had, and it didnt work
heres probably the problem.. u set the game to be over and the time to be zero.. as soon as u collide
u would want to wait for the video to be over.. b4 u did any of that
The characters eyes glitching around. The Idle Animation dont have a bigger eye to blink so i dont even know how it can blink xD
but the thing is, nothing happened when the collider of the enemy and the collider of the player collide, the game just keep running like usual
then ur collision isnt working correctly.. and u shoulda stopped there and figured out that problem. b4 u added in all the other nonsense
but ChatGPT be like that
they do apply to what im doing but i just cant grasp how my change size and my throw scripts can be use with the interact raycast beside when in unity you drag the code to he raycast and then select what event to happen but my issue still resides with when i start my game objects are spinning instead of when i tell them by looking at them and pressing E @rocky canyon
figure out ur collision first..
u have OnTriggerEnter... use OnCollisionEnter
if u dont have any triggers
if he's using triggers its fine. but if not yea OnCollision.. walking thru https://unity.huh.how/physics-messages will cover any scenario
and remove the Time.timeScale part and everything works
that might be the problem, ill try change the things ur both telling me, ill report back if it works
they do apply to what im doing but i just cant grasp how my change size and my throw scripts can be use with the interact raycast beside when in unity you drag the code to he raycast and then select what event to happen but my issue still resides with when i start my game objects are spinning instead of when i tell them by looking at them and pressing E @rocky canyon
wrap ur stuff in a boolean... if(youShouldRotate){//rotateCode}
in the event u can toggle it on.. youShouldRotate = true;
its probably easier just to use WASD keys, (Input.GetAxis) and rotate based on the input ur giving.. but idk
i do most likely not correctly
ya ik i want to so be casue this is ticking me off but i have to use the ray cast
u declare it as a float elsewehre.. like in the header of ur script
Like this @cosmic quail ?
just to say ur gonna be using one..
bool isTurning = false;
yea but idk if the video player part is correct, ur gonna have to test it and see what happens
okay
ur overcomplicating everything at once.... i'd recommend doing things one at a time.. make a script that detects a raycast on ur click or w/e
get that working first.. and then add the event..
then make sure the event is working..
then.....
also its recommended to use interfaces for this sort of thing instead of having to do GetComponent
u have like 8 scripts all jumbled together.. makes anyone trying to debug with u difficult
i do have some that work i just dont understand them
then work on understanding them
how do i test if my button for quitting the game works?
instead of adding to and removing stuff... watch some material on Events first..
until u feel u understand it completely
then return
building off of a system u never understood is bound to end badly
click it
click it
put a log in the method it calls. or add a line that changes EditorApplication.isPlaying to false so it actually quits the game in the editor. if you do the second one make sure to wrap it in preprocessor directives
well i do i just dont understand how they connect ot the ray cast ik when i done making them i can go to unity and attach the code to the ray cast then play and it work i just dont understand how the turn one wont work i can attach it to the ray cast just it spins off the start instead when i look and press e
the raycast is its own thing.. u would use it to invoke the event..
when i click it the button stops changing colour when highlighted but nothing else changes
it COULD possible do anything
so figure out how the raycast works first.. and then move foward
Debug.Log
This appeared before i did nothing @cosmic quail
replace Collider with Collision
!ide you don't have intellisense working for some reason
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
the error is telling you what's wrong
i do its hard to explain what ik i understand the basic of ray cast and the get e key down and it plays i just understand how to make my spin code start on e via that ray cast instead of the start
yeah but my english is not the best and sometimes I dont understand it correctly
Have you tried reading the error
OnCollisionEnter needs a Collision parameter. Yours doesn't have that. It has something else.
yeah but my english is not the best and sometimes I dont understand it correctly*
Ray ray = Camera.main.ScreenPointToRay(pos);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, distanceOfRay))
{
// We hit something
// now check if its the thing we want to hit
// if it is invoke the event
}
else
{
// we hit nothing
}```
a simple raycast running in update would be ALL u need for the raycast.. and then the event..
u reference that script in ur main script (the one meant to be listening) and subscribe to the event
then when the raycast triggers the true condition AND the hit the right object condition.. ur event just works
now is ok, ill try it and see if it works
i could write out ur system for you. but that wouldn't be benificial to you at all.
besides just getting the assignment finished
okay so they play via an invoke event that happens on the raycast code but the other scripts do they need if (invoked) for it to do it how i want
they need to know about the script that has the original event in it
so they can subscribe to it
but shuld'nt they know what it is casue this
public class EventListenerScript : MonoBehaviour
{
private void Start()
{
ShootingScript.OnRaycastHit += HandleRaycastHit;
}
private void HandleRaycastHit()
{
// Do something when the raycast hits
Debug.Log("Raycast hit!");
}
}```
^ has ShootingScript (the raycast) -> has access to the Event (OnRaycastHit) += (calls this scripts HandleRaycastHit)
when the event gets invoked in teh raycast script.. this script will run its own respective function (that we set to be HandleRaycastHit(); )
void ShootRaycast()
{
// Raycast hit something, trigger the event
if (hit.collider != null)
{
OnRaycastHit?.Invoke();
}
}```
the raycast script would then invoke if it exists which is what the ? represents
okay i understand that but how to my other scrpits know becasue i want it to be like them and they dont do this method
this is one that works
u give them a reference to the script with the raycast and the event
where?
[SerializedField] private ShootingScript myShootingScriptReference;
in the script that needs to know about the event
Im Trying to make a Tower Defence Game and right now I have the issue that the turret doesnt shoot and recognize the Zombies spawned in spawner. I need help and im new to c#/unity
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tower : MonoBehaviour
{
public float range = 10f;
public float fireRate = 1f;
public GameObject projectilePrefab;
public Transform firePoint;
private Transform target;
private float fireCooldown = 0f;
void Update()
{
if (fireCooldown > 0)
{
fireCooldown -= Time.deltaTime;
}
if (target == null || Vector3.Distance(transform.position, target.position) > range)
{
// No target in range, find a new target
FindNewTarget();
}
if (target != null && fireCooldown <= 0)
{
// Fire at the target
Shoot();
}
}
void FindNewTarget()
{
Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, range);
float closestDistance = float.MaxValue;
foreach (Collider2D collider in colliders)
{
if (collider.CompareTag("Zombie"))
{
float distance = Vector3.Distance(transform.position, collider.transform.position);
if (distance < closestDistance)
{
closestDistance = distance;
target = collider.transform;
}
}
}
}
void Shoot()
{
fireCooldown = 1f / fireRate;
// Instantiate the projectile and set its direction
GameObject projectile = Instantiate(projectilePrefab, firePoint.position, firePoint.rotation);
// Calculate direction to the target
Vector3 direction = (target.position - firePoint.position).normalized;
// Move the projectile towards the target
Rigidbody projectileRb = projectile.GetComponent<Rigidbody>();
projectileRb.AddForce(direction * 10f, ForceMode.Impulse);
}
}
why is it when i click exit game that button stops highlighting when i hover over it but none of the other buttons stop
b/c that button is now in a different state..
but why is nothing else
its been selected and will remain selected until u either unselect it with ur code.. or click a different button
b/c u didnt click any of the other ones??
ah
same would happen to any other button u click first
no but its not the selected colour its highlighted colour
ya, selected color would be the color it is while ur holding down on it
once u release it has been selected
it would be one of those other colors farther down
I believe the "selected" color beats the "hover" color
^ trial and error for me.. i always have to play around with the buttons
Your exit button does nothing in the editor, so you're just noticing that it's now selected
^ if the scene were to change u wouldnt notice 😄
I imagine your other buttons cause something to happen that makes the button go away
b/c u couldnt continue to hover it
so you haven't noticed this before
try clicking down on a button, then moving the mouse off before you release
you should see the same behavior
^ yup yup
idk what im doing wrong its not logging it ;-;
it doesnt appear to ever be called
"0 references"
does that reference counter have any idea about unity events though
^ ohh lmao definitely then
show us the inspector for the Button component, including the "On Click" event
public void HandleUnitMovement() {
// Checks if left mouse button is clicked on the unit
if(Input.GetMouseButtonDown(0)) {
// Create a ray from the camera to the mouse position
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
// Perform a raycast to detect if the mouse is pointing to an object
if (Physics.Raycast(ray, out hit)) {
// Get the layer of the object hit by the ray
LayerMask layerHit = hit.transform.gameObject.layer;
// Check the layer value using a switch statement
switch (layerHit.value) {
case 8: // Case 8: The object belongs to layer 8 (Assumed to be units)
SelectUnit(hit.transform, Input.GetKey(KeyCode.LeftShift));
break;
default: // Default case: Deselect all units for layers other than 8
DeselectUnit();
break;
}
}
}
}
private void SelectUnit(Transform unit, bool canMultiSelect = false) { // Method to select units
if (!canMultiSelect) { // Deselect all units if multi-selection is not allowed
DeselectUnit();
}
selectedUnits.Add(unit); // Add the selected unit to the list
unit.Find("Highlight").gameObject.SetActive(true); // Activate the "Highlight" game object
Debug.Log("Highlighting Unit");
}```
purpose: when selecting unit, there should be a circle beneath the unit that indicates
problem: this circle doesn't show. the debug log doesnt appear in the console, i have a layer named Units in the 8th layer, any help would be appreciated
Unity events can reach private methods? wtf if true
They can't seem to program anything properly
@cosmic quail When the monster touches me, the lvl restart but the video is nowhere to be seen
@rocky canyon omg u should be proud i found my issue i dont need a if statement i need a public void then i named turn(bool isTurning)
well im looking on it now and its not reading my function or something, says "no function" and theres nothing to select from
then i was able to set a toggle
You must select a public method from the dropdown. Make that method public
and now is kinda works it turns via every clikc of e .25
unit.Find("Highlight").gameObject.SetActive(true); // Activate the "Highlight" game object debug this value and see if it find a "Highlight"
doExitGame is currently private. You will not see it in the list.
ahhhh
Unity won't just call random functions (:
Oh damn how do you get drop downs in dark mode?
Okay gotcha
im making a similar system
dum dum
this is 2023.2.x, which has some new UIToolkit based context menus
The path is correct but i dont know why the video is not there, may it be because Im trying it inside unity?
although apparently they might not be sticking around because of some glitchiness? i dunno
Nice 👌
no you should be proud
not sure how u want to do it.. ```cs
public void Deselect()
{
selected = false;
enabledGraphics.SetActive(false);
AudioManager.Instance.PlayClip(deselect_Clip,7.5f);
}
public void Select()
{
selected = true;
enabledGraphics.SetActive(true);
AudioManager.Instance.PlayClip(select_Clip,7.5f);
}```
but i enable and disable my selection graphics from the unit itself
can u help me with this @rocky canyon plz
i have a list.. and if the unit isnt already in that list.. i call Select();
if it is already in the list i call Deselect();
Yeah I got deselect method too i just didnt wanna fill whole screen
it takes care of its own graphics.. (b/c the graphics are already on that unit)
and its assigned in the inspector.. (this avoids any issue of having to hunt down those graphics)
you need to play the video first.. and then restart the game. probably
ok ill try
if(videoIsPlaying) <-- turn this on once the video starts...
Yeah there aint a message either
and then inside that ifstatement u can check if its finished plyaing
if it didnt find anything it still should have printed something i think
its disabled bro
how is it supposed to find it?
Yeah then I enable it by clciking it
Okay I'll try that sorry am lil new to this stuff
I kid you not I have headache now
we've all been there
I change some things, it still works but the video still doesnt show up, i think i forgot about smth but I dont know what
you need to get your !IDE configured
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
there are also several things wrong with that, but having configured tools is a requirement to get help here #854851968446365696
why?, it works perffectly, im new so i dont think I understand what u are trying to explain to me
because you do not have intellisense, error highlighting, or even proper syntax highlighting
Why should we waste our time checking your spelling when you could literally prevent those errors from ever happening by configuring your IDE
okay, so i click in Visual Studio (Installed via Unity Hub)?
Are you using Visual Studio, installed via Unity Hub?
still aint working, do u know whether it's a code error or something else
nope, installef from microsoft web
So then why would you click the one for installed via unity hub
Anyone knows a solition to this?
I've got no audio. Was there an actual question and is it related to coding?
Ah yes, my bad. The problem is that after i run it wont get back to the idle animation or infact it does but the animation is glitched. The eyes look different after the run but still are animated
what still isnt working? the Find() method wont work. b/c its inactive in the scene
I think I did it now
best thing to do is have it already assigned somewhere
idk what im doing wrong ive tried alot of things and i still cant select my script from the drop down for the onclick function
Selecting unit doesn't do anything, i set the object to active, but i saw your method in ur game it might be better
What should i change now to make the video appear before restarting the level
several things are wrong here. first, that path is not going to work outside of the editor
second, you load the scene immediately after playing the video so the video does not have time to play before the scene is destroyed
@ivory bobcat
shit
Show code, and show what comes up with you try
how do i change both of the things u just said?
it just doesnt come up in the drop down
It's still not public
you were just told this
i set it public and still same thing
Make it public, and show the dropdown
for the first, instead of loading the video like that, you should create a prefab that already has a VideoPlayer component with the correct video assigned to it, or just have it in the scene somewhere and just spawn/reference it here then call Play.
for the second, you should start a coroutine or something that waits until the video has finished playing then loads the scene
You've dragged the actual script asset -- the thing Unity uses to keep track of where your code is
like this?
UnityEvent can target any unity object
you prolly think im waffling
that's why you see such an enormous pile of options if you open the "Select" window
i should figure out where all of these empty-named objects are coming from...
that should take care of the second part
It absolutely does work. You can call any of those functions in MonoScript on this object
But you don't want to change any properties of the script file
It's so broad because UnityEvent has no real limits on what it can target. It's happy to run methods from anything
you want to access a function on an instance of the script
compare that to, say, a GameObject field
which is very particular: it wants a game object, and nothing else
ok, and now, how i do the first xd
i explained what you should do. if you do not know how to do that, then you should start with the basics by going through the pathways on the unity !learn site
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
well, ill try
stick to what?
adding the script to a game object and using that
Well, yes. Because that's what you're supposed to do
There isn't really an alternative
Right.
When you dragged the exitGame script asset from the Project window into the On Click event, you were telling Unity that you wanted to do something to the script asset.
When you add the exitGame component to a game object, you're creating an instance of the class that script contains. It's stored on the game object.
So when you dragged that game object into the On Click event, you were telling Unity you wanted to do something to that object (or that object's components)
ahhh
When you attach a component, Unity writes down the unique ID of the script asset
(which is why you can rename the class and the script file without existing components breaking)
(it only cares about that ID)
mhm
you can literally just replace it with another script's ID and the component will suddenly be another type. I've done that a few times before for...reasons
but yeah -- if you see MonoScript, you've got something wrong
I've done that for modding support. If you have a script that just has all serializable fields and no functionality whatsoever, when that prefab gets bundled into an asset bundle and read on a different project with a real script, it'll map those serialized values to the actual script
So you can create a Modding API without having to include the entire game's scripts
That's clever.
I've been thinking about how you'd actually...make a modding interface
I hadn't considered that idea at all though
Yeah I felt pretty clever when I came up with that.
Never finished the project of course but it was a pretty cool system
😅
@slender nymph I created a video player, whith the video i want, but how do i modify the script to select tha video player? And right now the video actually plays, but only the sound when i start the scene
I'm having enough fun with serialization right now
i'm not even going to think about modding..
disable Play On Awake on the VideoPlayer component. and get a reference to it
@swift crag would it be possible to add the script to the button itself and then select itself for the onclick function
just to save memory or whatever not making too many objects
if the button is active in the scene.. then why wouldn't it?
u can add as many script/ components as u want.. to any object
except a few edge-cases, which the editor just wont allow u and will show u a popup error as to why
an extra object isn't gonna matter in teh grand scheme of things
Don't worry about making too many objects.
organization may be more important
In fact, you should worry about not making enough objects!
making things neat and tidy will make your life easier
is there any way i can "optimise" it?
However, to completely contradict everything I just said:
i did this, but still doesnt play when the enemy catches u, what i need to do more?
If this is an Exit Button, it makes sense to have the "Exit Game" component on the Exit Button
😈
hello, is there any help channel? or can i ask for help here
Maybe something to do with pixel perfect if you're referring to the width of the eyes
https://blog.unity.com/games/2d-pixel-perfect-how-to-set-up-your-unity-project-for-retro-8-bits-games
and how do you play it
However, if the "Exit Game" component is used by multiple systems, then it does not belong on the exit button
explain in 5 year old terms
👍
In that case, it'd probably go on something more like a "game controller"
what do i need too add in the script to make it appear when they collide
remember how i said you need to get a reference to the VideoPlayer
what would be the best way to for example open a settings menu, would it be better to just hide all the other objects and show the new ones, or create a new scene for it?
Scene load deletes everything from previus scene
either way. the former means those objects will always be in memory, the latter means everything is loaded at the time of scene load which may mean GC spikes after the scene has been unloaded
https://www.youtube.com/watch?v=YOaYQrN1oYQ
same guy who did 2d guide kekw
Learn how to make an in-game options menu using Unity!
● Sign up for the Devdog Christmas Calender: http://bit.ly/DevdogGiveaway
● START MENU in Unity: https://youtu.be/zc8ac_qUXQY
● Ultimate Game UI: https://www.assetstore.unity3d.com/#!/content/53973?aid=1101lPGj
♥ Support Brackeys on Patreon: http://patreon.com/brackeys/
··················...
this is not true of Additive loading
Oh, I know only LoadScene atm
well yes, that's how you load a scene. but you can do so additively
would that be a big issue for a smallish scene?
you'd really just have to profile it if you have performance concerns
what does that mean?
thank you
this is additively loading..
you can see that my Master Scene always sticks around.. it loads in a Level scene and unloads the main menu
all in the same (place)
Are corutines async?
Like in Android?
yes and no. they are not async as in the technical meaning with the async modifier. but they are async as in they do not have to fully complete immediately and are evaluated at specific parts of the frame to determine if execution should continue
what happens if one corutine is called multiple times. It creates multiple instances of such running in parrarel?
yes
thats how come we can use StopCoroutine() and pass in a certain coroutine
or StopAllCoroutines() setc
and how do we find specific corutines?
u cache them b4 u start it
Oh, I see
or while u start it rather
you don't "find" them. you keep a reference to the coroutine returned by StartCoroutine if you need to stop a specific one
Yeah I got it
Do they auto cleanup when finished if they were saved in the list
or I need to run check for nulls to clean up the list
private void Start()
{
// Start the coroutine and cache the reference
myCoroutine = StartCoroutine(MyCoroutine());
}```
like so
Yeah I know that, I more or less know C# shenanigans
cool cool, never kno around here
but im not sure what u mean by needing to cleanup after they're finished.. im not that advanced
normal objects that do not inherit from UnityEngine.Object do not turn null automatically
I mean when corutine stops running but you still have the pointer to them in the list, does it delete itself or pointer becomes null adding need in cleaning them up
neither of those things happen
What does then happen? It eats memory?
because, again, normal objects do not magically become null.
c# does not have the concept of "destroyed" like unity does. if something references an object it will stay in memory until sometime after it is no longer referenced by anything when it will get garbage collected
The Coroutine object still exists, but it represents a completed coroutine.
is there a way to find out if corutine is completed?
lol, nvm there is no isRunning
probably isAlive
i dont think.. let me check.. come to think of it
how do you/
ahh, ud need to implement that
you don't. you would typically assign null to the variable holding its reference at the end of the coroutine
IEnumerator MyCoroutine()
{
isCoroutineRunning = true;
yield return new WaitForSeconds(3f);
isCoroutineRunning = false;
}```
this would work, i think
Store the coroutine and check if its null
how would you find out corutine variable from the list?
Coroutine firstCoroutine = runningCoroutines[0];
If its not first.
same way ud find any type in a list i think
Then use the index that it is
ud search thru the list using ur cached coroutine?
lol ya
It sounds odd that you have a list of coroutines and need to find a specific one
Lets imagine we have list of corutines, we have corutine 5 that has finished.
we want it removed
why would you have a list of coroutines though
Only pointer to it is the same list
Its just theory
If corutine is just another object we can temporaly hold a variable in it that consist of its position in the list
and use it to just remove itself
issue comes with other lists that now have outdated position list
if (runningCoroutines.Count > 0)
{
Coroutine firstCoroutine = runningCoroutines[0];
if (firstCoroutine != null)
{
// still running
}
else
{
runningCoroutines.RemoveAt(0);
}
}```
this thread im reading seems to imply it does go to null
after it finishes 🤔
Coroutine does not just become null though
yea.. hold up.. let me read farther
Once the coroutine is finshed, Unity will no longer hold reference internally to the Coroutine or the IEnumerator as it is done with it. However when you hold that instance in your own variable, it would stay there useless forever. Your variable can only become null when you set it to null.
In unity discussions
ohhhh thats probably what they mean ^
can u link the thread ur lookin at?
Just chilling
Hi! I really like to save coroutines into variables and then check their existence. But only recently I found out that completing a coroutine loop does not reset its variable to zero. So my questions are. Is it even correct to cache coroutines in the Coroutine = StartCoroutine() field Which of the following examples is correct? (Dont mind we...
thanks!
i need to list up some coroutines just for fun..
ive never stored more than a single reference to a coroutine
Coroutine inherits from YieldInstruction which does not inherit from anything else. neither of which have an overloaded == operator that checks against a fake null like UnityEngine.Object has so it has no way to turn null on its own like UnityEngine.Objects
kinda vague on how any of that works tbh
The vital thing to understand is that no reference "becomes null", ever
unless u manually set it to null
Destroyed Unity objects just compare true against null
Having a list of coroutines that you need to care about in general already sounds like a shit design tbh. It's not like they would be acting all on their own variables
So basically never to hold corutines in a list if you dont want to write 1000 lines to handle it
i.e. foo == null is true when foo is a destroyed Unity object.
Like this ?
There is no magic. Unity can't set your variable to null behind your back.
That doesn't turn a reference into null, that puts the value null into the variable
Realistically it's simple to manage but just like.. why would you want it.
i have soo much bad code then tbh.. where i wanted multi-action type scripts.. where if i leave a field blank it does a different behaviour
yes, there you go. now you can call Play on that instead of the one you create manually
If its simple how would u manage it xD
So technically it doesn't become null, it's just no longer referenced and will get GC'd
I did that this morning...but that was because I needed to make a "coroutine" that updates in LateUpdate
probably not the best way to do it i guess
so I just made a List<IEnumerator> and wrote a bit of logic to manage the "coroutines" myself
just pass the expected index in as a paramter to the coroutine and it can assign null to that index itself
I think it would make more sense to pass the actual coroutine reference if things are being removed from the list
Issue is that if you do that your next corutine in list will get broken cause list now is 1 space shorter after you clean up the null
How would you do that 😄
you wouldn't be able to do that though because the reference to the coroutine does not exist until StartCoroutine returns and you can't use ref params for coroutines
Here I have a leg and Im gonna pass the same leg to that leg
soo, since we're speaking on null's is this fine for its purpose? if i have a lookTarget we look at it.. if not we dont..
i wrote it this way so i could have the same script on things that look and dont look, i just leave the inspector blank for the ones that dont
you could technically pass a delegate that captures that local variable though
What do I need to change in here for that to work, because like this, it doesnt
I forgot about that part
Yea it does get tedious I guess
what doesnt work
why are u still setting ur game over b4 the video finishes?
why not set that in the coroutine?
Just use PlayTime something
in what way does this not work?
Bcs I dont know how to change that
Cant u do it with https://docs.unity3d.com/ScriptReference/WaitForEndOfFrame.html
.length probably will do
nvm it doesn't matter i dont guess.. b/c at the end of the coroutine thast when u load the new scene
When the enemy collides with player, it just restart the level, the video does not appear in the camera
like, it doesnt show up
i guess thats just a bool to keep the CollisionEnter() from starting the video over and over
yield return new WaitForSeconds(animation.lenght);
I tried that, but it was a bit inconvenient -- as the page notes, this doesn't run at all if the game view is hidden
which was annoying for testing purposes
well have you put the video player in a location where the camera can see it?
this is the way i'd do it
The while is playing didnt work for me too
i think so
lemme check
u could also put the Video somewhere out in the middle of no where, with its own camera focused on it..
swap the camera, start the film 🍿
I followed this sphere deform tutorial but instead I was using a plane, and the object shoots a ray down to the mesh to deform it, it says it hits the mesh but it doesn't deform, I'm new so idk what I need to do. This is the script attached to the grid for the deform
you need to get your !IDE configured
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
now its done, but still nothing happens, just level restart
and you are referencing the videoplayer in the scene and not perhaps a prefab?
that doesn't answer the question. that just shows you have a gameobject called VideoPlayer in the scene
well that shows that you are referencing an object called Video Player with a VideoPlayer component on it. but again, are you certain that is the one that is in the scene? ||hint: you can click it and it will highlight the object||
i have animation that is set to false but even then none of the other animations can be played even if their conditions are true, its just stuck o nthe last animation
public class EnemyCollisionHandler : MonoBehaviour
{
public string restartSceneName = "Juego";
public GameObject player;
public VideoPlayer videoPlayer;
private bool isGameOver = false;
void OnCollisionEnter(Collision other)
{
if (other.gameObject == player && !isGameOver)
{
isGameOver = true;
videoPlayer.Play(); // Play the video
StartCoroutine(WaitForVideoAndRestartCoroutine(videoPlayer));
}
}
IEnumerator WaitForVideoAndRestartCoroutine(VideoPlayer videoPlayer)
{
while (videoPlayer.isPlaying)
{
yield return null;
}
Time.timeScale = 1f;
SceneManager.LoadScene(restartSceneName);
}
}```
code seems fine,
a simple "yes" would have sufficed
show the actual video player component
this? @slender nymph
void OnCollisionEnter(Collision other)
{
if (other.gameObject == player && !isGameOver)
{
isGameOver = true;
// Play the video
videoPlayer.Play();
Debug.Log("Video started playing. Duration: " + videoPlayer.clip.length);
StartCoroutine(WaitForVideoAndRestartCoroutine(videoPlayer));
}
}
IEnumerator WaitForVideoAndRestartCoroutine(VideoPlayer videoPlayer)
{
while (videoPlayer.isPlaying)
{
Debug.Log("Video is still playing...");
yield return null;
}
Debug.Log("Video finished playing. Restarting the scene.");
Time.timeScale = 1f;
SceneManager.LoadScene(restartSceneName);
}``` heres some debug values
have u tested the video w/o the code??
I dont know whats wrong now
i didint touch that shit
well spawn camp just gave you code with some mostly useful logs. what do they print?
never said u did.. just make an observation
its in the middle of the camera
use the code i sent to see if u get any debugs
u should get all 3.. but many of the Video is still playing..
it will play on the near plane so it will be visible. that wouldn't be an option if it didn't work
ok
just checking.. im not familiar with the defaults of the video player but im learning a bit at the moment
i changed the code for the new one u gave me
and, whats it log?
error says: NullReferenceException: Object reference not set to an instance of an object
Player.PlayerManager.Update () (at Assets/_Scripts/PlayerManager.cs:17)
https://unity.huh.how/runtime-exceptions/nullreferenceexception
your InputHandler.instance is null
InputHandler.instance is null
its the same
well, i think we found a piece of the puzzle
you have 10 errors. what are they
bro's been ignoring his console this entire time
how to fix?
from the slender free asset
Okay
when i pressed run, it worked so, yeah xd
this is not from the Slenderman assets
thast from your JumpscareController script
might need glaasses
make it not be null
if ur script errors out like that it may stop running completely
and you wouldnt know if the video part even worked
also if it is loading the scene even with that OnCollisionEnter method never being called, then something else is loading it or something else is starting that coroutine
so, what do i do now
move those methods outside of whatever method they are nested in
easier terms, dont now what nested means, im not english srry
yea, OnCollision has to be outside of any functions u wrote
📃 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.
he pasted my code snippet into his update or something is my guess
ah yeah probably so no logs but the code still works because they didn't remove their own code
where's the rest of your class
like the class part
lol, well ur missing the entire class wrapper
what u talking abt?
ur class isnt a class anymore
this code isn't in a class
where is the class thing ur talking abt
you should probably learn literally the first thing about how code works instead of just smooshing random words together like a goddamn caveman
exactly my point
chill man
heres the FULL class https://hatebin.com/kzeagreuso I used a text extractor to take it from ur screenshot
u deleted all ur important stuff such as 👇
there are plenty of resources for you to learn how basic C# syntax works instead of getting a half dozen people here to write your code for you one line at a time
well tbf to him he had all of it written out. originally
okay, but chill, u didnt even interact in the whole conversation until now
https://paste.mod.gg/snzyxafmybej/1
can someone please tell me why after PlayerCrouchHit, the game wont stop playing the animatio neven if its set to false.
i have an animation event at the end of the PlayerCrouchHit that goes like this:
public void HitAnimationFalse()
{
hitWhileShielded = false;
}
hitWhileShielded has to be true to set the bool parameter for PlayerCrouchHit to true'
A tool for sharing your source code with the world!
he just made a mistake and pasted over his class header and stuff when he went to introduce the debug logs
it's probably an issue with your transitions. but also wtf why does your PlayerMovement class have any info about what animation(s) are playing
i dont use transition, i set an animation to true if its bool parameter is true
yea... ur prob right but i didnt know how to organzie and didnt know that id do next lol
well i'm not digging into all of that. use the debugger in your IDE to figure out what is happening
i used debug and it shows that hitWhileShielded is set to false correctly yet animation still plays
then its an issue with the Animator
could u elaborate
if ur code is working but the animations are not
not really.. probably a transition from clip to clip..
how do i tackle this problem
inspect ur animator as the game is playing..
u can see the transitions and stuff light up
u can figure out whats not doing what supposed to be doing
ye even when false playercrouchit lights up
but idk what to do about that
just open the animator window.. click the gameobject that has the animator and debug
thats what i did it lights up even when false
we couldn't say w/o looking thru ur animator and knowing everything that u know about ur project
then check that transition..
make sure that the conditions when it goes off are correctly set up
i play anbimation via code and not use transitiopns
ohhh, well then it has to be ur script then doesn't it?
i will try to record a clip
well yea! but i looked through it so many times
lol, its a hefty class..
yea a video would be helpful. but provide context with it.. tell us what we're seeing whats we're supposed to be seeing etc..
a clip w/o context is gonna be just as bad as that big ole class
u may have to start debugging... put debug.logs in places a little by little.. to hunt down where the code is going wrong..
also, I'd say use breakpoints but i dont know how those work.. so i wont lol
idk what a a break point is 😭
i dont have a mic so i hope doing circles with my mouse helps 😰
lol, thast what i do 😄
when following this tutorial i found that the colors of the code im writing and the code of the example are different and the suggestions are not the same.
with just legs moving
can someone helpe with this i believe it is causing issues with adding the script properly
pixel
while video loads imma try one more debvug thingie
I have set the external script editor to visualstudio but this didnt help
can someone tell me why the shadows are acting weird? and why does also do that in game? and how do i fix it?
Srry, i was doing personal things, i fixed the things u said, now its literally the same code as this one, but still doesnt work, it just restart the level, should I build it and try if it works or it wont?
!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
no but the character that only moves is legs
ok yea...with more bebugging, the animations parameter is literally false but animation is still playing
i built it, and the video is still missing @rocky canyon @slender nymph
what do the logs print
what do the logs from the script print
how can i find the script related ones
well you start by clearing the console then you go into play mode and make your code run
@slender nymph
@signal bronze
then that code is not running
there is nothing about the script in the console
again, if you do not see the logs printed to the console then your code is literally not running
I have read this page many times and not found a fix for the issue...
Intellisense makes predictions sometimes and then other times it doesnt.. but the code color lens isnt working for any color but blue...
Is this a VisulStudio issue or a unity issue?
your screenshot still shows an unconfigured IDE
are you sure you have completed all of the steps?
start by removing one of the two audio listeners so that you can actually see your logs when/if they happen
and of course you need to actually address then 100+ errors
@rocky canyon here is da vid
this is the only red error that appears
fix both of those things
and this the other yellow one
then you might even be able to see your own logs in the console
how
do you know how to read?
yes sorry
great! then literally just read what those messages say and do it
Well the logs arent lying to you for fun, at some point you had 2 audio listeners.
yeah i now
great! so we see that it thinks the video is done playing immediately. this is probably due to the player not being ready to actually start playing yet and so it hasn't actually started before you start checking if it is playing or not
start by checking the docs for the VideoPlayer and see if there is anything useful you could possibly do there
closed the tab, can u send it again
!docs
i have a strange issue where sometimes my scene will just load into itself when calling change scene. after like 2 or 3 tries it works and idk why
is it possible to transform a OnTriggerEnter into an IEnumerator?
i wanna make a canon where you only need to go on the trigger
and it shoots
just start a coroutine in OnTriggerEnter
that's what i wanna make
i didn't mean turn OnTriggerEnter into a coroutine. i said start one from it
i cant find shit, I dont understand what i have to change for it to work
oh
you didn't find anything at all in the docs about preparing it to play?
Hi, I'm trying to make a RayCast based suspension system only using the car RigidBody. Does anyone know why is the suspension acting weird and does'nt want to stay in place?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WheelSuspension : MonoBehaviour
{
public Ray tireRay;
public Transform tireTransform;
public Rigidbody carRigidBody;
public float wheelRadius = 0.5f;
public float springStrength;
public float springDamper;
public float suspensionRestDist;
void Start()
{
}
void Update()
{
tireRay = new Ray(tireTransform.position, -tireTransform.up);
Debug.DrawRay(tireRay.origin, tireRay.direction);
if(Physics.Raycast(tireRay, out RaycastHit hit, suspensionRestDist + wheelRadius))
{
Vector3 springDir = tireTransform.up;
Vector3 tireVel = carRigidBody.GetPointVelocity(tireTransform.position);
float offset = suspensionRestDist - (hit.distance - wheelRadius);
float vel = Vector3.Dot(springDir, tireVel);
float force = (offset * springStrength) - (vel * springDamper);
carRigidBody.AddForceAtPosition(springDir * force, tireTransform.position);
}
}
}
Thanks in advance
why would you look there
you obviously need to look at the info about the video player component
yes
for starters, don't add force in Update. that is going to lead to inconsistent physics
physics should be applied in FixedUpdate
Thanks, going to try that
is that because the update updates every refresh rate
and the fixed update is at a constant rate
yes, but physics simulates on a fixed loop at the same rate as FixedUpdate
you were right the essentials course is coming handy!
you didn't find anything at all that might prevent it from playing immediately and nothing about potentially preparing it to play?
Is it this one? https://learn.unity.com/learn/pathway/unity-essentials think i'm going to need to follow that one 😂
yes, I thought it was bogus at first but damn, it really explains each element in full detail rather than a YouTube video speeding it through
its in english, maybe I have it in front of my eyes but I dont understand it correctly
please tell me what it is
been trying to find this for ages but is there any way to change this so it finds an inactive instead of active object:
unit.Find("Highlight").gameObject.SetActive(true);
No
i dont understand the error here
you never yield in the coroutine, why is it a coroutine?
How can I add 90 degrees to hips.AddForce(hips.transform.forward * strafeSpeed); because my hips.transform.right is not my left and right. It's up and down
@slender nymph
ohhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
why
right gotcha thanks
Oh, thanks for the advice
Are you completely new?
is it better like this
what, i dont know what i touched but now it works @slender nymph
i think it was skip on drop
or smth
The wait is entirely pointless https://unity.huh.how/coroutines/waiting
Don’t use a coroutine for that, just use void shoot