Search Unity

Ruby’s Adventure: 2d Beginner Official Thread

Discussion in 'Community Learning & Teaching' started by katwoolley, Apr 15, 2019.

  1. slonokot

    slonokot

    Joined:
    Sep 8, 2018
    Posts:
    1
    Same here.
     
    holywiremod likes this.
  2. zoggak

    zoggak

    Joined:
    Apr 17, 2019
    Posts:
    2
    Doing this tutorial, found typo in "Sprite Animation" lession part "5. Setting animation for the main character". In "Or, we can set a condition based on our parameters. Here, if the robot’s speed becomes less than 0.1, then the State Machine will transition from Moving to Idle."
    It is about Ruby, not robot.
     
  3. sirsimonemorris

    sirsimonemorris

    Joined:
    May 30, 2019
    Posts:
    1
    Hi I am stuck on the World Interactions section of this tutorial. I created the script for HealthCollectible and RubyController but when I try to run them so I can test whether it will change the health and delete the object, it gives me an error in the console. I would share it, but I downloaded the Ruby 2D demo to compare the code from it to the code from mine, but It erased everything I did, put up the scene and erased all of my progress. I did put the code exactly as it said in the tutorial, but is said something about GetComponent not working properly.
     
  4. holywiremod

    holywiremod

    Joined:
    May 31, 2019
    Posts:
    4
    The Visual Styling - Particles Part 3 is missing the C# code for adding the Particle System to the robot's EnemyController script. The only thing I can figure out is this is required in the code:

    Code (CSharp):
    1. public class EnemyController : MonoBehaviour
    2. {
    3.        public ParticleSystem particalSystem;
    4. }
    Even though Play on Awake is ticked the Particle System does not automatically play. It seems some way of starting the Particle System is required in void Start() as well as some way to end it in void public Fix(). I'm suspecting
    https://docs.unity3d.com/ScriptReference/ParticleSystem.Play.html
    and
    https://docs.unity3d.com/ScriptReference/ParticleSystem.Stop.html
    will be needed.

    When adding Debug.Log(particalSystem.isPlaying); it always returns false.

    Please update the tutorial.
     
    Last edited: May 31, 2019
  5. Dasttann777

    Dasttann777

    Joined:
    Nov 22, 2013
    Posts:
    2
    I have also hit this exact same wall in the tutorial. How am I meant to proceed in the tutorial when I don't have required code? And i don't really want to just copy from the full example as i would love an explanation on how it works...

    Hopefully you guys can clarify soon so I can go back to learning :)
     
  6. holywiremod

    holywiremod

    Joined:
    May 31, 2019
    Posts:
    4
    I've managed to figure out what to do for The Visual Styling - Particles Part 3.

    1) Open your EnemyController script and add to the top:
    Code (CSharp):
    1. public ParticleSystem smokeEffect;
    2) Open your Robot prefab in the prefab editor.
    3) Drag the Smoke Effect prefab from the Project Window on the Robot in the Hierarchy Window ( making it a child of Robot).
    4) Click the Robot in the Hierarchy Window and drag the Smoke Effect child from the Hierarchy Window into the Smoke Effect slot on your Robot's script in the Inspector Window.
    5) Continue the rest of Part 3 from the top as normal.

    Note: You may need to edit the Smoke Effect's transform values to x = 0, y = 0 in order to see the smoke effect after it's been made a child of the Robot.

    The issue is that the first image in that tutorial is not the correct one which caused confusion. Hope that helps!
     
    Last edited: May 31, 2019
  7. Dasttann777

    Dasttann777

    Joined:
    Nov 22, 2013
    Posts:
    2
    A god among men you are, thanks heaps man, worked perfectly.
     
  8. mmdestiny

    mmdestiny

    Joined:
    May 21, 2019
    Posts:
    2
    Greatly enjoying this project. Currently wrapping up the Particle Lesson.
    One thing that's bugging me - I feel that the game will occasionally Play at a much higher FPS. Some times things suddenly move at light speed.
    Given there's not a whole lot going on and I'm running a GTX1080 and 4770K, I wouldn't expect there to be any rendering issues with something with such little going on.
    Any thoughts?
     
  9. ciavyn

    ciavyn

    Joined:
    May 28, 2019
    Posts:
    2
    Same issue here. Not sure why it won't work.


     
  10. LordMorgner

    LordMorgner

    Joined:
    May 29, 2019
    Posts:
    1
    I'm on Unity 2019.1. Can't figure out why particle system won't show up in play mode (but it does in the scene)
     
  11. mickcooke

    mickcooke

    Joined:
    Jun 3, 2019
    Posts:
    2
    Hi there enjoying working through this tutorial as a complete newb to all this have got to the world interactions and my health strawberry works fine and the damage spiky things work
    Problem is I notice if ruby goes into damage zone console shows correct update 4/5 3/5 etc If ruby then goes pick up health no problem console shows update 4/5 5/5 but if ruby goes back to damage zone console shows 2/5 and so on I can pick up health and return to 5/5 but damage will always be whatever it was last time ruby left damage zone
     
  12. mmdestiny

    mmdestiny

    Joined:
    May 21, 2019
    Posts:
    2
    Check the Z transform. Particle systems sometimes get created at a negative z. It should be at 0, or it'll be rendered behind everything.

    Also for those where their smoke isn't stopping, check that in the robot prefab's public particle system slot, you dragged in the CHILD PARTICLE SYSTEM, NOT the particle system prefab. This is a little hard to tell from the tutorial, but the video shows this.
     
    Last edited: Jun 3, 2019
    Chaosylum and Cute_Poops like this.
  13. mickcooke

    mickcooke

    Joined:
    Jun 3, 2019
    Posts:
    2
    Found it! I missed the curly brace between the two if statements in the health collectible script Damn those curly braces
     
  14. AzDraconis

    AzDraconis

    Joined:
    Jun 2, 2019
    Posts:
    1
    Also regarding the particle system:
    In 4. Creativity time, i figured out that for "run once if..."-effects you have to disable "play on awake" (or they wil be played already one time when starting the scene), then needing an additional "effectName.Play();" in addition to instantiation (or they won't play at all).
    As the tutorial encourages you to experiment with those effects, i think some more hints or even an example might be useful at that point.
     
  15. PhantomFox128

    PhantomFox128

    Joined:
    May 22, 2019
    Posts:
    15
    Hi all. Got a few questions here.

    I'm currently stuck on tutorial 8: World Interactions - Damage Zones and Enemies. My code for the robot is exactly as the tutorial's but my robot doesn't move vertically, only horizontally. I'm assuming it's because the timer in the code isn't working properly, but I have no clue how to fix it.

    Also, I don't know if this was done on purpose, but the robot's speed by default is zero and needs to be changed in the Inspector. Shouldn't the default speed be set in the script or does that not matter?

    While I'm at it, the code in the Collectibles tutorial that prevents Ruby from picking up health items if her health is at max keeps giving me an error to the point where I just deleted it so I could move on. No idea how to fix that either.

    I'm using Unity 2019.1.5f1, BTW.
     
    Last edited: Jun 12, 2019
  16. Explorer_Niels

    Explorer_Niels

    Joined:
    Jun 4, 2019
    Posts:
    2
    Hi, I encoutered a roadbumb right at the second tutorial. "Solved" it, but maybe someone can tell me what I did wrong. Or fix the tutorial. :)

    At the second step of the second tutorial you are asked to right click and save an image of Ruby and drag and drop her in the project folder. This is supposed to be a PNG file (as is seen in the image in the tutorial), but i got a WEBP file, which Unity doesn't accept.

    First I tried to convert it using MS Paint, but this lost the transparancy. So I ended up downloading IrfanView (also had to download an extra plugin so it could open WebP) and was finally able to convert it properly. All in all cost me an hour mucking about.

    Maybe the website converted all images to WebP and didn't realize that this would "break" the tutorial?
     
    skim434 likes this.
  17. RavenZaiyo

    RavenZaiyo

    Joined:
    Jun 15, 2019
    Posts:
    1
    I'm using this project to learn code, and so far I thought I was doing fine, but not only am I completely stumped as to what went wrong, but I'm not seeing anyone else who had the same problem on here.

    I'm on the Damage and Enemies chapter, step one. I have a CS0101 error: The namespace '<global namespace>' already contains a definition for 'DamageZone'.

    I literally did exactly as the tutorial says. It told me what to name the script, it gave me what exactly to put in it. I tried doing it over, going over it with again piece by piece, but I really don't know why it wont work?? What am I missing???
     
  18. Bozbacca

    Bozbacca

    Joined:
    Oct 23, 2014
    Posts:
    3
    I had this too. Simply delete the resolution after .png and it'll save as a PNG - this worked for me using Google Chrome.
     
  19. Bozbacca

    Bozbacca

    Joined:
    Oct 23, 2014
    Posts:
    3
    I'm having an issue with this script during lesson 5. I had the movement working perfectly but the changes with Look Direction broke Player control. I've uploaded the script for reference, there's nothing wrong with the compiling but it no longer allows me to change character position.
     

    Attached Files:

  20. tengisandluigi

    tengisandluigi

    Joined:
    Jun 18, 2019
    Posts:
    2
    Thank you bro! I've been trying to debug that for hours!
     
    GeekyMonkey likes this.
  21. Bozbacca

    Bozbacca

    Joined:
    Oct 23, 2014
    Posts:
    3
    OK so I managed to figure out what was going wrong. Somehow managed to "Apply Root Motion" in the Animator function unclicking it fixed movement.
     
  22. Explorer_Niels

    Explorer_Niels

    Joined:
    Jun 4, 2019
    Posts:
    2
    It sounds like you accidentally created multiple versions of the class "DamageZone". Check that you replaced the auto-generated script with the script from the tutorial instead of adding to it. You could also search your code for the text "DamageZone"; you should find it only once. If you find more, you should remove the duplicate.
     
  23. Cute_Poops

    Cute_Poops

    Joined:
    Dec 14, 2018
    Posts:
    2
    I've been getting the same error message:

    NullReferenceException: Object reference not set to an instance of an object
    UIHealthBar.Start () (at Assets/Scripts/UIHealthBar.cs:26

    I'm unsure what to do. I plan to check the complete project scripts and see if I'm missing something.

    Edit: The only difference between my script and the reference script is void Start is void OnEnable. I tried changing this, but the error persists. I'm about ready to pull my hair out. My code is:

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

    public class UIHealthBar : MonoBehaviour
    {
    //static and public (can be called in any script as "UIHealthBar.instance" can't be changed
    public static UIHealthBar instance { get; private set; }

    //Healbar mask variable
    public Image mask;
    //original health bar size
    float originalSize;

    //called as soon as object created. store this (this object) in static instance
    void Awake()
    {
    instance = this;
    }

    // Start is called before the first frame update
    void Start()
    {
    //gets size on screen
    originalSize = mask.rectTransform.rect.width;
    }

    //called when value is between 0 and 1
    public void SetValue(float value)
    {
    //change size of mask which changes health bar fill state
    mask.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, originalSize * value);
    }
    }

    Excuse the heavy documentation. I plan to use these scripts later as reference.
     
    Last edited: Jun 19, 2019
  24. tengisandluigi

    tengisandluigi

    Joined:
    Jun 18, 2019
    Posts:
    2
    Remember to add the script component to the health bar image in inspector.
     
    Cute_Poops likes this.
  25. Argo2014

    Argo2014

    Joined:
    Jun 20, 2019
    Posts:
    5
    Thanks so much!!! was stuck on this for awhile, would be helpful to include this fix in the tutorial if you don't see your particles.
     
  26. Codesmite

    Codesmite

    Joined:
    Jun 19, 2019
    Posts:
    1
    I had this error as well but it was because I hadn't added

    Code (CSharp):
    1. animator = GetComponent<Animator>();
    to the start function in RubyController.cs.
     
  27. Argo2014

    Argo2014

    Joined:
    Jun 20, 2019
    Posts:
    5
    So i'm down to the creative part for the Particle Tutorial have the particle setup how i'd like it to display when the Player is hurt, having some trouble with the Instantiating part of the Particle System in the RubyController Script i've declared it at the beginning of the class, made a prefab of the Particle System a child of Ruby and linked it to the Script variable. The Tutorial suggests to destroy the object as soon as the particle system plays out so ive set up the object to do that, but i'm having trouble with the instantiating code. if the particle system is not a child of Ruby object it will play the particle but only on one position of the map nowhere near Ruby. If I link the child version nothing shows. I'm really new to Unity and this part of the Tutorial seems to throw you to the wolves. I feel like i'm missing a position parameter for the Instantiate code but can't seem to code it right, Thank you immensely for any help.


    Code (CSharp):
    1.  
    2.     public void ChangeHealth(int amount)
    3.     {
    4.         if (amount < 0)
    5.         {
    6.             if (isInvincible)
    7.                 return;
    8.             isInvincible = true;
    9.             invincibleTimer = timeInvincible;
    10.             Instantiate(hurtEffect);
    11.         }
     
  28. Ydwin

    Ydwin

    Joined:
    Jun 22, 2019
    Posts:
    1
    Hi, I have a weird problem with Unity and the game's speed. I use Unity with a Laptop and when I am on Battery, the game is running much faster than usual. The characters are moving way too fast and on a greater distance.
    The Time.deltaTime doesn't seem to change anything.
    Any idea ?
    Edit : The same thing seems to happen when I maximize the game, excepts that it is getting slower.
     
    Last edited: Jun 22, 2019
  29. juuustin

    juuustin

    Joined:
    Jun 22, 2019
    Posts:
    5
    very useful! Thank you very much!
     
  30. juuustin

    juuustin

    Joined:
    Jun 22, 2019
    Posts:
    5
    for 10:
    World Interactions - Projectile, my cop won't disappear, how can I debug?
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Projectile : MonoBehaviour
    6. {
    7.     Rigidbody2D rigidbody2d;
    8.  
    9.     // Start is called before the first frame update
    10.     void Awake()
    11.     {
    12.         rigidbody2d = GetComponent<Rigidbody2D>();
    13.     }
    14.  
    15.     // Update is called once per frame
    16.     void Update()
    17.     {
    18.  
    19.         void OnCollisionEnter2D(Collision2D other)
    20.         {
    21.             //we also add a debug log to know what the projectile touch
    22.             Debug.Log("Projectile Collision with " + other.gameObject);
    23.             Destroy(gameObject);
    24.         }
    25.     }
    26.  
    27.     public void Launch(Vector2 direction, float force)
    28.     {
    29.         rigidbody2d.AddForce(direction * force);
    30.     }
    31.  
    32. }
    33.  
     
  31. tasnimrushi10

    tasnimrushi10

    Joined:
    Jun 23, 2019
    Posts:
    8
    Ruby.png material is not getting downloaded. What is the problem
     
  32. Valjuin

    Valjuin

    Joined:
    May 22, 2019
    Posts:
    27
    Right click on image in tutorial and save to your computer.
     
  33. Cute_Poops

    Cute_Poops

    Joined:
    Dec 14, 2018
    Posts:
    2
    Thanks. I ended up just restarting the whole tutorial from the beginning. I think that was likely my problem. That, or forgetting to drag the mask over. Either way, I appreciate the help!
     
  34. Quintavius

    Quintavius

    Joined:
    May 31, 2019
    Posts:
    14
    I'm having an issue where in the Sprite Animation lesson, I am failry sure I've followed all the steps properly but when i try to run the scene, the robot always plays the running right animation. Please send feedback with ideas to troubleshoot, the issue kind of stops me from progressing so id appreciate feedback asap
     
  35. Quintavius

    Quintavius

    Joined:
    May 31, 2019
    Posts:
    14
    Also when looking at the animation in the prefab the collision box seems to be way below the robot sprite, any clues on how to fix that
     
  36. Quintavius

    Quintavius

    Joined:
    May 31, 2019
    Posts:
    14
    Nope I solved it im a stupid, i solved it. My animation parameters for moving were called "MoveX" and "MoveY" when my code was trying to send it to "Move X" and "Move Y"
     
  37. sspgamestudios

    sspgamestudios

    Joined:
    Jun 22, 2019
    Posts:
    2
    Hey Oliver, this problem has nothing to do with the code itself... I was actually scratching my head at the same issue until a few minutes ago.

    The real problem here is how you added the particle effect to the public script inside unity.

    https://connect-prd-cdn.unity.com/2...1-4a90-9514-322e1b0a8eb1_image6.gif._gif_.mp4

    You have to follow the video (attach the particle effect in the Inspector of your Robot Prefab)

    I hope this helps!
     
  38. unity_JMbB7PYMs02-fQ

    unity_JMbB7PYMs02-fQ

    Joined:
    Jun 23, 2019
    Posts:
    2
    I actually did it like this and it s still not working for me.
     
  39. unity_JMbB7PYMs02-fQ

    unity_JMbB7PYMs02-fQ

    Joined:
    Jun 23, 2019
    Posts:
    2
    Did you do the further step? Where you actually put the animations to the animator? If you don t do that it just walking to the right.
     
  40. sspgamestudios

    sspgamestudios

    Joined:
    Jun 22, 2019
    Posts:
    2
    When I try to add the UIHealthBar Script to the health bar image it gives me this error:

    Can't add script component 'UIHealthbar' because the script class cannot be found. Make sure there are no compile errors and the the file name and class name match.

    This is my UIHealthbar script:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class UIHealthBar : MonoBehaviour
    7. {
    8.     public static UIHealthBar instance { get; private set; }
    9.     public Image mask;
    10.     float originalSize;
    11.  
    12.     void Start()
    13.     {
    14.         originalSize = mask.rectTransform.rect.width;
    15.     }
    16.  
    17.     public void SetValue(float value)
    18.     {
    19.         mask.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, originalSize * value);
    20.     }
    21. }
     
  41. Quintavius

    Quintavius

    Joined:
    May 31, 2019
    Posts:
    14
    So many people have talked on here about issues with the particle tutorial, but after just trying to add the particles to my robot nothing appeared, I checked the Z axis and fixed it so that it wasn't behind everything else but it still didn't show up, please help.
     
  42. Quintavius

    Quintavius

    Joined:
    May 31, 2019
    Posts:
    14
    AAAAAND of course it was something so simple, I checked the z axis in the prefab but it didnt change the one in the scene, smoke is appearing now!
     
  43. Quintavius

    Quintavius

    Joined:
    May 31, 2019
    Posts:
    14
    Has anyone found a solution to this, not even destroying the particle will get rid of it in the scene? Does it have something to do with being a child of the Robot parent? no idea
     
  44. Quintavius

    Quintavius

    Joined:
    May 31, 2019
    Posts:
    14
    Something weird to note is when i change my Fix function to look like this: ...
    public void Fix()
    {
    broken = false;
    rigidbody2d.simulated = false;
    SmokeEffect.Stop();
    animator.SetTrigger("Fixed");
    }
    ...aka putting the smoke effect in front of the animator trigger, the animator will not trigger, leaving the robot walking in place with smoke still pouring out of his head. When the SmokeEffect.Stop(); command is below the animator command, like this:
    public void Fix()
    {
    broken = false;
    rigidbody2d.simulated = false;
    animator.SetTrigger("Fixed");
    SmokeEffect.Stop();
    }
    ...then the animator changes the animation of the robot so it dances, but the smoke effect still remains. Still its weird that the order of the code in the function changes whether or not the animator works, just wondering if that info will help anyone out when trying to fix the problem of the smoke staying behind.
     
  45. Quintavius

    Quintavius

    Joined:
    May 31, 2019
    Posts:
    14
    Nevermind, i am yet again saved by my complete lack of free time, I had put the prefab of the smoke particle in the robot Smoke Effect Particle System. When i dragged in the child smoke effect into it, suddenly the robot was able to dance and stop smoking after we fixed him. Hope this helps finally
     
  46. Bentobbs

    Bentobbs

    Joined:
    Jun 11, 2019
    Posts:
    2
    Hey guys, I really enjoyed this tutorial so far, but now I am stuck at the projectile chapter step 2. The console shows 6 errors.
    1: For the Projectile script: CS0106: The modifier 'public' is not valid for this item – "public void Launch(Vector2 direction, float force)"
    The other 5 for RubyController.cs for this line of code "if(Input.GetKeyDown(KeyCode.C))" at the end of the Update function
    2: CS1519: Invalid token 'if' in class, struct …
    3: CS8124: Tuple must contain at least two elements
    4: CS1026: ) expected
    5: CS8124: Tuple must contain at least two elements
    6: CS1519: Invalid token ')' in class, struct …

    The CogBullet projectile is a Prefab with the right script attached + Box Collider + Rigidbody + 0 Gravity Scale. It is also in the slot of the RubyController.

    Can anybody tell me why 'public' is a problem here and why this "if(…" line of code causes so many errors?
    I hope I provided you with enough info to get to a conclusion and would really appreciate any help!
     

    Attached Files:

  47. GregKelly7

    GregKelly7

    Joined:
    Jun 26, 2019
    Posts:
    6
    Hello, I am a complete noob and am struggling with steps 13 to 15 of World Interactions - Collectables:

    https://learn.unity.com/tutorial/wo...66dbedbc2a0021b1bc7c#5ce51081edbc2a004e805e64

    Specifically, I am having trouble making the changes to the RubyController script, and HealthCollectible script.

    Below is my code prior to step 13, (which works). If someone could help me with the code changes needed for steps 13 - 15, that would be so awesome :)

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class RubyController : MonoBehaviour
    6. {
    7.  
    8.     public float speed = 3.0f;
    9.  
    10.     public int maxHealth = 5;
    11.  
    12.     int currentHealth;
    13.  
    14.     Rigidbody2D rigidbody2d;
    15.  
    16.     // Start is called before the first frame update
    17.     void Start()
    18.     {
    19.         rigidbody2d = GetComponent<Rigidbody2D>();
    20.  
    21.         currentHealth = maxHealth;
    22.     }
    23.  
    24.     // Update is called once per frame
    25.     void Update()
    26.     {
    27.         float horizontal = Input.GetAxis("Horizontal");
    28.         float vertical = Input.GetAxis("Vertical");
    29.  
    30.         Vector2 position = rigidbody2d.position;
    31.         position.x = position.x + speed * horizontal * Time.deltaTime;
    32.         position.y = position.y + speed * vertical * Time.deltaTime;
    33.  
    34.         rigidbody2d.MovePosition(position);
    35.     }
    36.  
    37.     public void ChangeHealth(int amount)
    38.     {
    39.         currentHealth = Mathf.Clamp(currentHealth + amount, 0, maxHealth);
    40.         Debug.Log(currentHealth + "/" + maxHealth);
    41.  
    42.     }
    43. }
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class HealthCollectible : MonoBehaviour
    6. {
    7.     void OnTriggerEnter2D(Collider2D other)
    8.     {
    9.         RubyController controller = other.GetComponent<RubyController>();
    10.  
    11.         if (controller != null)
    12.         {
    13.             controller.ChangeHealth(1);
    14.             Destroy(gameObject);
    15.         }
    16.     }
    17. }
     
  48. Valjuin

    Valjuin

    Joined:
    May 22, 2019
    Posts:
    27
    Projectile script: You have put the public void Launch function inside the Update function. These should be two separate functions.

    RubyController script: if(Input.GetKeyDown(KeyCode.C)) should be within the Update function.
     
  49. Valjuin

    Valjuin

    Joined:
    May 22, 2019
    Posts:
    27
    Step 13 is:

    - an explanation of what needs to be done;
    - how you could achieve it; but
    - why, in this case, it won’t work.

    If you change your script as shown in this step to check it out, you need to change it back again and then carry on to Step 14.
     
  50. Valjuin

    Valjuin

    Joined:
    May 22, 2019
    Posts:
    27
    You are missing the void Awake() function.