Forum begins after the advertisement:
[Part 10] 2 Errors I’m confused about
Home › Forums › Video Game Tutorial Series › Creating a Rogue-like Shoot-em Up in Unity › [Part 10] 2 Errors I’m confused about
- This topic has 12 replies, 3 voices, and was last updated 1 year, 1 month ago by Terence.
-
AuthorPosts
-
September 9, 2023 at 11:33 am #11906::
(1) So, for the first issue, whenever I collect XP gems, only the first collect of the type is collected. This is really confusing because before part 11, it worked perfectly.
(2) This error happens during the upgrade screen, but it appears that the onclick event is deleted before it can be used and I don’t know why. The code is the exact same(I think) and I can’t find console errors.
Help would be appreciated!
(if the answer is in part 11 I will eat my hat.)
September 9, 2023 at 7:18 pm #11907::Hi Luke, I’m taking over the project from Xavier, so bear with me if I’m not very well-informed about some parts of the codebase.
For (1), is the collision detection done using
OnTriggerEnter2D()
? If it is, you can do put something likeDebug.Log(name + " pick up triggered")
on the function to see if the function fires for the pickups that are not working. The line prints the name of the object as well, so you can tell which object is being triggered. If certain pickups are not triggering, pause the game during play and check if they have a) a collider and b) a Rigidbody2D. Those 2 are needed for collisions to register.For (2), will you be able to clip a video of this happening with something like ScreenToGif and post it on Imgur? Then you can embed it here.
September 9, 2023 at 7:24 pm #11908September 11, 2023 at 11:27 am #11910::I’ve tested out the Debug.Log solution and I think the reason is because it is destroyed before it hits the player. Still not solved.(I could be wrong on this.)
(btw u can use print() instead of debug.log)
September 11, 2023 at 5:37 pm #11911::Is there any script that is calling
Destroy()
on your GameObject? That is the only thing I can think of that is destroying your object before it hits the player.September 12, 2023 at 7:33 am #11912::The error might be in onTriggerEnter2D for this code:
<code>void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.TryGetComponent(out ICollectible collectible)) { Rigidbody2D rb = col.gameObject.GetComponent<Rigidbody2D>(); //rb.velocity = Vector2.zero; //rb.angularVelocity = 0; collectible.MoveToPlayer(); collectible.Collect(); } }</code>
Also I’ve recorded the other error, but I don’t know how to embed.
September 12, 2023 at 7:33 am #11913::The error might be in onTriggerEnter2D for this code:
<code>void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.TryGetComponent(out ICollectible collectible)) { Rigidbody2D rb = col.gameObject.GetComponent<Rigidbody2D>(); //rb.velocity = Vector2.zero; //rb.angularVelocity = 0; collectible.MoveToPlayer(); collectible.Collect(); } }</code>
Also I’ve recorded the other error here. The Error
September 12, 2023 at 7:35 am #11914::I solved the issue where you could dodge pickups using the movetoplayer function above, complicated. if that causes an error welp that’s it.
September 12, 2023 at 7:35 am #11915::I solved the issue where you could dodge pickups using the movetoplayer function above, complicated. if that causes an error welp that’s it.
September 12, 2023 at 10:00 am #11916::Nvm, the second error was because I decided to put removeUpgradeoptions after applyupgradeoptions. Fixed!
September 14, 2023 at 3:34 am #11920October 11, 2023 at 6:48 am #12065::Hi i have solution for your 1 Error if you need it. Sadly it wont let me post imagur or other images or links into reply. Can i contact you somehow outside of this forum?
October 29, 2023 at 12:31 pm #12130 -
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: