Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Unity Ruby’s Adventure: 2d Beginner Official Thread

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

  1. katwoolley

    katwoolley

    Unity Technologies

    Joined:
    Jan 18, 2018
    Posts:
    15
    2DBeginner_AssetStore_SocialMedia.png

    Alongside our brand new Learn platform, Unity’s Learn Content team have released a new 2D beginner project. This project is a great way to introduce you to beginner code, tilemapper, sprites, collectibles, quest controllers and more, all wrapped up in this RPG style game tutorial.

    Step by step, use the 2D assets provided to help Ruby fix her robot friends. The written lessons have editor screenshots and gifs to help you learn how to re-create the game.
    For the first time we’ve released two versions of our project. You can find the tutorial project where you build the game from scratch, but also the completed project where you can see how we’ve made the demo level and play the game in the editor.


    Find the tutorial on the Unity Learn site here

    Download the Tutorial Project here

    Download the Complete Project here

     
    Last edited: Apr 15, 2019
    Gametyme, Aesthorian and GeekyMonkey like this.
  2. anthonyirwin82

    anthonyirwin82

    Joined:
    Jun 21, 2017
    Posts:
    2
    Hi,

    I am going through this tutorial and really liking it so far.

    I have found a bug in Part 9 Sprite Animation.

    In section 5 Setting animation for the main character you have the following bug in the Update() method:

    Code (CSharp):
    1. // The following is a bug the parameter is actually "Look X" and "Look Y"
    2. animator.SetFloat("Move X", lookDirection.x);
    3. animator.SetFloat("Move Y", lookDirection.y);
    It should actually be the following:

    Code (CSharp):
    1. animator.SetFloat("Look X", lookDirection.x);
    2. animator.SetFloat("Look Y", lookDirection.y);
    Anyway just thought I would point that out as some new users may not be able to easily debug the problem.

    Thanks for the learning tutorials, really great way to get started with Unity.

    Regards,
    Anthony
     
  3. anthonyirwin82

    anthonyirwin82

    Joined:
    Jun 21, 2017
    Posts:
    2
    Found another bug in part 10 World interactions - Projectiles in Section 2 Launching the projectiles

    Code (CSharp):
    1. void Launch()
    2. {
    3.     GameObject projectileObject = Instantiate(projectilePrefab, rigidbody2d.position + Vector2.up * 0.5f, Quaternion.identity);
    4.  
    5.     Projectile projectile = projectileObject.GetComponent<Projectile>();
    6.     projectile.Launch(lookDirection, 300);
    7.  
    8.     // This should be "Launch" also you are not using ascii double quotes so copy and paste has a special “ instead of the asicii " one so visual studio gets upset.
    9.     animator.SetTrigger(“Lauch”);
    10. }
    Regards,
    Anthony
     
  4. MRNXGBRL

    MRNXGBRL

    Joined:
    Apr 13, 2019
    Posts:
    1
    @katwoolley Regarding World Interactions - Collectibles part 1 - character Health. The bottom exercise solution code to 'expose speed' by adding 'public' results in a compiler error? (newb here just starting out)

    Fixed it ! further on down the chapter, don't know how exactly, maybe i just forgot to put in that closing bracket, like the Console kept reminding me a couple of times? I'll probably have to read and go over this chapter a couple of times more over before i truly grasp this beginner C# stuff.tx!
     
    Last edited: May 3, 2019
    katwoolley likes this.
  5. rbagao

    rbagao

    Joined:
    Feb 13, 2016
    Posts:
    19
    Would like to ask if this game has mobile controls or pc only? thanks
     
  6. VGSammich

    VGSammich

    Joined:
    Apr 26, 2019
    Posts:
    1
    Found what may be another issue?
    In chapter 16 Build, Run, Distribute after having completed it and testing the finished build, my player character and enemy characters are moving way too fast. I'm guessing their movement speed is tied to the refresh rate or framerate, but it shouldn't be as Time.deltaTime is incorporated in their scripts and it runs as expected in the Unity Editor.

    This tutorial has been my first time using Unity, so I'm kind of at a roadblock. Any help would be appreciated!

    edit: I have found that running on the default build's ultra-medium settings causes the movements to be too fast, while low-very low cause them to be too slow. I can also replicate this issue in the editor by switching the Quality setting's Vsync to Every Second V Blank. I have also checked to see if my GPU drivers were causing any interference but have determined that it is not. Any help still would be appreciated as this is is something I'd like to resolve in the event I encounter it again in different projects.

    edit2: After no luck, I'm just going to assume it has something to do with unity tying my movement script to some part with my monitor's refresh rate of 144hz. At this time I don't have any other means to determine what may be the cause so if anyone has had or read of any similiar issues please let me know ;P
     
    Last edited: May 16, 2019
  7. AdventurousDrake

    AdventurousDrake

    Joined:
    Mar 18, 2015
    Posts:
    21
    Chapter 12 - 3 Particle System in code.
    Code and tutorial parts missing?

    The tutorial jumps directly to dragging the particle system in to a slot that hasn't been created yet. Even if I create a public variable for for the smoke effect it still doesn't work when I press play in the editor. Maybe I missed something, but after re-reading that section lots of times, I still cannot get it to work. Any help would be greatly appreciated.
     
  8. katwoolley

    katwoolley

    Unity Technologies

    Joined:
    Jan 18, 2018
    Posts:
    15
    This project has been created to be used within the Unity editor on Windows or Mac only.
     
  9. TallGuyD

    TallGuyD

    Joined:
    Apr 12, 2019
    Posts:
    3
    Hey, I'm not having any luck with the Ruby Tutorial for beginners. I'm not sure why it's just not working form me. But I have been trying to figure it out for a while and I'm only on the second part. The image I've posted has my script and the errors the console is showing me. Thanks to anyone who can offer a suggestion.
     

    Attached Files:

  10. TallGuyD

    TallGuyD

    Joined:
    Apr 12, 2019
    Posts:
    3
    I have opened unity ver. 2018.3 and repeated the process. It worked correctly, unlike in unity ver. 2019.1.
     
  11. RobotDoc2

    RobotDoc2

    Joined:
    Oct 7, 2018
    Posts:
    4
    2019 breaks a lot of the 2D tutorials. Stick with 2018.3 and you'll save yourself a lot of aggravation.
     
    TallGuyD likes this.
  12. TallGuyD

    TallGuyD

    Joined:
    Apr 12, 2019
    Posts:
    3
    Thank you for the tip.
     
    RobotDoc2 likes this.
  13. RobotDoc2

    RobotDoc2

    Joined:
    Oct 7, 2018
    Posts:
    4
     
    TallGuyD likes this.
  14. darksilence

    darksilence

    Joined:
    Oct 16, 2014
    Posts:
    10
    Its not that, it seems he somehow managed to add duplicate of RubyController.c# to project and when he started clean it solved the problem.
     
  15. darksilence

    darksilence

    Joined:
    Oct 16, 2014
    Posts:
    10
    Was camehere just to write that. But in someway it was good debugging exercise for me, had to write lots of test cases to find what is wrong and eventhough i know how to do it in theory first time i actually put the effort and done that :) So i am glad of the bug for some reason.
     
  16. apo0o0o

    apo0o0o

    Joined:
    Apr 19, 2019
    Posts:
    1
    i'm stuck at that point :-(

    I saw the bug @anthonyirwin82 has shown on the first answer.
    I changed
    animator.SetFloat("Look X", lookDirection.x);
    animator.SetFloat("Look Y", lookDirection.y);

    but I keep on getting error:
    NullReferenceException: Object reference not set to an instance of an object RubyController.Update () (at Assets/Scripts/RubyController.cs:51)

    I commented out the three line:
    //animator.SetFloat("Look X", lookDirection.x);
    //animator.SetFloat("Look Y", lookDirection.y);
    //animator.SetFloat("Speed", move.magnitude);


    and the game can run
    I've also debugged the 3 variable:

    Debug.Log(lookDirection.x + "/" + lookDirection.y);
    Debug.Log(move.magnitude);

    and they works


    so I think the problem is that

    Animator animator;

    is not working, but is written similar to EnemyController

    someone got this problem to?









    This is my code:

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


    public class RubyController : MonoBehaviour
    {
    public float speed = 3.0f;

    public int maxHealth = 5;
    public float timeInvincible = 2.0f;

    public int health { get { return currentHealth; } }

    private int currentHealth;
    bool isInvincible;
    float invincibleTimer;

    Rigidbody2D rigidbody2d;
    Animator animator;



    // Start is called before the first frame update
    void Start()
    {
    rigidbody2d = GetComponent<Rigidbody2D>();

    currentHealth = maxHealth;
    }


    // Update is called once per frame
    void Update()
    {
    float horizontal = Input.GetAxis("Horizontal");
    float vertical = Input.GetAxis("Vertical");

    Vector2 move = new Vector2(horizontal, vertical);

    Vector2 lookDirection = new Vector2(1, 0);

    if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
    {
    lookDirection.Set(move.x, move.y);
    lookDirection.Normalize();

    }

    //Debug.Log(lookDirection.x + "/" + lookDirection.y);
    //Debug.Log(move.magnitude);
    animator.SetFloat("Look X", lookDirection.x);
    animator.SetFloat("Look Y", lookDirection.y);
    animator.SetFloat("Speed", move.magnitude);

    Vector2 position = rigidbody2d.position;

    position = position + move * speed * Time.deltaTime;

    rigidbody2d.MovePosition(position);

    if (isInvincible)
    {
    invincibleTimer -= Time.deltaTime;
    if (invincibleTimer < 0)
    isInvincible = false;
    }
    }

    public void ChangeHealth(int amount)
    {
    if (amount < 0)
    {
    if (isInvincible)
    return;

    isInvincible = true;
    invincibleTimer = timeInvincible;
    }

    currentHealth = Mathf.Clamp(currentHealth + amount, 0, maxHealth);

    Debug.Log(currentHealth + "/" + maxHealth);
    }
    }




    thanks
     
  17. Natzely

    Natzely

    Joined:
    Sep 9, 2017
    Posts:
    1
    I hope some one can help with this, it's driving me nuts. I'm trying to make my star particle look identical to the example at the top of the Visual Styling - Particles tutorial page, but I can't seem to adjust the particle system to achieve this. Can anyone tell me what the settings are for that? Mine doesn't look anywhere near as smooth.

    Here are my settings:
     
    MrFunky likes this.
  18. Psyche_

    Psyche_

    Joined:
    May 2, 2018
    Posts:
    10
    Hey,
    I don't see anything wrong with the script at first sight, make sure you are using the right Animator controller in the editor and that you have the same parameters. You get a nullreference exception when those 3 lines are linked and not when you comment them, so I am guessing they can't find the parameters you are wanting to access.
     
  19. Psyche_

    Psyche_

    Joined:
    May 2, 2018
    Posts:
    10
    1. I believe there is a small bug here in CH12PT3 - duplicate image. First one should be fixed if I'm not mistaken.

    duplicateimage.png
     
    Last edited: May 15, 2019
  20. unity_vPTkf-uNWV_3JQ

    unity_vPTkf-uNWV_3JQ

    Joined:
    May 15, 2019
    Posts:
    1
    I actually have the same problem as you have. But I'm also not getting any smarter by looking into the references...
    for the moment i commented those three lines and can play. But Animation is missing tho. ;(
     
  21. Psyche_

    Psyche_

    Joined:
    May 2, 2018
    Posts:
    10
    Can you show your script? Make sure you are working on the Ruby Prefab and that you have assigned Ruby controller in the Animator component.
     
  22. darksilence

    darksilence

    Joined:
    Oct 16, 2014
    Posts:
    10
    Thats correct both animated gifs are same and first one is unnecessary. I finished the tutorial and compiled without any problems 1-2 days ago. But i love the facts that you need to be more and more carefull as you approach towards the end and in sound part they give you one example and let you do the rest (or ignore). Gradually less hand holding. For example in 12-3
    "And to stop the smoke when the robot gets fixed, open the EnemyController script and add a public member of type ParticleSystem called smokeEffect." And nowhere else they show it or the code or how to declare public member of ParticleSystem class. This things are really easy to do by yourself even you didnt know how to do it you acquire the skill along the way. And you can't just rush tutorial mindlessly half awake. Right after completing the project i started my own learning project and i even more appreciate they made the tutorial easy but not mindless. Since there is tens of immediate problems i started face and instead of completely stuck i am progressing (very slowly though)
     
  23. WalkerOfTheSky

    WalkerOfTheSky

    Joined:
    May 9, 2019
    Posts:
    1
    Hi there,

    I have an annoying problem which I don't know how to debug. I hope someone can point me in the right direction.

    I noticed it in chapter 10 when implementing the projectile to fix the robot, but I think I made some mistake during the animation chapter which I can't seem to find

    When I press play to start the game my robot, instead of starting to walk in the right direction, appears a little on top of its starting location leaving its box collider at its original starting location.
    I think it's easier to understand by looking at the screenshots. The first one I took before I press start and the second screenshot is the first frame after pressing start. After that the robot walks perfectly but the box collider, while moving with the robot, always stays underneath the robot. So basically to repair it I have to shoot below the robot instead of right at it.


    01.png

    02_firstFrameAfterPlay.png


    I'm using Unity Version 2019.1.2f1

    Thanks in advance.
     

    Attached Files:

    NatalieW15 likes this.
  24. GeekyMonkey

    GeekyMonkey

    Joined:
    Feb 9, 2013
    Posts:
    13
    You need to initialize your "animator" variable in the Start() function, just as you do for the "rigidbody2d" variable.
     
    NatalieW15 likes this.
  25. GeekyMonkey

    GeekyMonkey

    Joined:
    Feb 9, 2013
    Posts:
    13
    I think your problem is actually in the pivot points of your sprites. Look at each frame of the robot spritesheet and make sure all of them have the pivot at bottom center. Then adjust your box collider position.
     
    NatalieW15 likes this.
  26. benfarrantsmith

    benfarrantsmith

    Joined:
    May 15, 2019
    Posts:
    4

    I need help with the beginning of step 2, in part 10.

    Let’s start by creating a public variable in our RubyController script that we will call projectilePrefab. We’ll make it a GameObject type because that’s what prefabs are; GameObjects saved as assets. Because we’ve made it public, it appears in our Editor as a slot where we can assign any GameObject.

    ^^This Bit^^

    How do I do it?

    Thanks.
     
  27. darksilence

    darksilence

    Joined:
    Oct 16, 2014
    Posts:
    10
    public GameObject projectilePrefab;

    You should consider starting from beginning of the tutorial since it seems you missed even most basic things.
     
  28. mr_noodler

    mr_noodler

    Joined:
    May 11, 2019
    Posts:
    6
    Hello,

    I'm having a problem with the Damage received from enemies, particularly the line void OnCollisionEnter2D(Collision2D other) is not being called during gameplay. Any ideas as to why this is happening?

    I have followed the tutorial in setting up the character as a sprite with a Rigidbody 2D and a Box Collider 2D.and I am using Unity 2019.1.2f1 Personal.

    Is there something that I am missing? Please see my source below:

    //////////////////Code/////////////////

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

    public class EnemyController : MonoBehaviour
    {
    public float speed = 3.0f;
    public bool vertical;
    public float changeTime = 3.0f;

    Rigidbody2D rigidbody2D;
    float timer;
    int direction = 1;

    // Start is called before the first frame update
    void Start()
    {
    rigidbody2D = GetComponent<Rigidbody2D>();
    timer = changeTime;
    }

    // Update is called once per frame
    void Update()
    {

    timer -= Time.deltaTime;

    if (timer < 0)
    {
    direction = -direction;
    timer = changeTime;
    }


    Vector2 position = rigidbody2D.position;

    if (vertical)
    {
    position.y = position.y + Time.deltaTime * speed * direction;
    }
    else
    {
    position.x = position.x + Time.deltaTime * speed * direction;
    }

    rigidbody2D.MovePosition(position);

    void OnCollisionEnter2D(Collision2D other)
    {
    Debug.Log("first");

    RubyController player = other.gameObject.GetComponent<RubyController>();
    Debug.Log("got here");

    if (player != null)
    {
    player.ChangeHealth(-1);
    }
    }
    }
    }
     
  29. mr_noodler

    mr_noodler

    Joined:
    May 11, 2019
    Posts:
    6
    I completely figured out my own problem!! I put the 'void OnCollisionEnter2D(Collision2D other) into the 'void Update' method. So to fix my problem I put it outside the void Update method and everything works fine now.
     
    NatalieW15 and katwoolley like this.
  30. SynolBAKA

    SynolBAKA

    Joined:
    May 20, 2019
    Posts:
    3
    Found a few bugs in 9. Sprite Animation. Seems a few others are finding them also so I'll post the solutions here.

    First, the collision box on the animations is well below where it is on the actual Robot object. Not sure if it is because I resized the Robot, but someone above posted the same issue.

    The fix is to open the Robot prefab and then to open the Animation screen (ctrl+6). Click the Play button to get the animation running and then in the inspector you can move the collision box to the right spot. There seems to be an independent collision box for animations and objects, a pretty strange way to do it.


    Second, when you go into detail on which code to enter into RubyController you skip the part that should go into the Start function.

    The fix is to add animator = gameObject.GetComponent<Animator>(); into the Start() function just the way you did with the EnemyController script in the first part.



    Hope this helps some other people.
     
  31. benfarrantsmith

    benfarrantsmith

    Joined:
    May 15, 2019
    Posts:
    4
    Thanks, I am a casual, don't worry.
     
  32. changlihan4595

    changlihan4595

    Joined:
    May 19, 2019
    Posts:
    2
    In 12th tutorial visual styling- particle step 4. How could I make get hit effect and health collection effect working properly? I created prefabs for both get hit effect and health collection effect, and also did the same stuff as I did for smoke effect on robots and also folliowing
    • Disable Looping and set the Stop Action to Destroy.

    • Set the Rate over Time to 0, to not generate any particles over time.

    • Set a burst of 20 particles at time 0.0
    and use Instantiate(hitEffect) and Instantiate(healthCollectionEffect) in RubyController script.

    I uploaded the script, could somebody tell me how to make hitEffect correctly triggered.
     

    Attached Files:

  33. manas16

    manas16

    Joined:
    May 4, 2019
    Posts:
    2
    Thank You so much , Second point helped me
     
  34. mr_noodler

    mr_noodler

    Joined:
    May 11, 2019
    Posts:
    6
    Is there a reason that my smoke effect is not rendering properly? It disappears in the prefab view sometimes and also disappears completely in game mode.
     
    trainoasis likes this.
  35. firahs

    firahs

    Joined:
    May 1, 2019
    Posts:
    3
    For those getting the null pointer exception on the ruby script during the animation lesson

    Make sure

    animator = GetComponent<Animator>();

    is in RubyController's start method
     
    stephenkim79 and Hino_Dev like this.
  36. firahs

    firahs

    Joined:
    May 1, 2019
    Posts:
    3
    I spent about an hour on this...make sure the Z component of the Smoke effect's transform is 0 and not -41
     
  37. AdamDanielKing

    AdamDanielKing

    Joined:
    May 20, 2019
    Posts:
    3
     
  38. AdamDanielKing

    AdamDanielKing

    Joined:
    May 20, 2019
    Posts:
    3
    Thank you so much for this. When you're a total novice at unity, the smallest detail can make you lose the plot! You'd think the people making this tutorial would get it right in the first place !
     
    stephenkim79 likes this.
  39. UnityGuillaume

    UnityGuillaume

    Unity Technologies

    Joined:
    Mar 16, 2015
    Posts:
    122
    For the First problem, it's because the pivot is different : when the robot is imported in the previous lesson, the pivot is set automatically to the centre of the sprite, but the provided animation frames (used to create the animation) have their pivot at the bottom (like we did for your player one in Lesson 5 - Decorating the world).
    And the collider position is defined in relation to the pivot. So the collider set in lesson 8 won't be in the right place with the new pivot (hence why it look like the object & the animation have different collider: it's just that before you start playing the animation, it's the sprite you imported from the previous lesson, with the wrong pivot, that is use.).

    Thanks for the feedback, we will make sure to add in lesson 8 a bit about moving the pivot to the bottom like we did for the player to avoid that confusion!

    As for the Second one, the tutorial do say
    " Just like for the robot, add an Animator variable and, in the Start function, use GetComponent to retrieve the Animator and store it in that variable."
    but it's probably too easy to miss. What would make it cleared to you? Would adding a code block with the actual line again would make it easier?


    It's probably because when you Instantiate a prefab, it is put at the position saved in the prefab, so it will be somwhere in the world, and you want to play the effect at Ruby's position.

    Two solution for that :

    - use the version of the Instantiate function that take 2 more parameter that is the position and rotiation given to the new copy
    Instantiate(hitEffect, transform.position, Quaternion.identity)
    (don't worry about Quaternion.identity, just remember that as "no rotation).

    - retrieve the copy that instanciate create and place it at the right position

    ParticleSystem newHitEffect = Instantiate(hitEffect);
    newHitEffect.transform.position = transform.position


    I'll make sure we add this information to the tutorial too! Thank you for your feedback!
     
  40. Mad_Mark97

    Mad_Mark97

    Joined:
    Mar 20, 2019
    Posts:
    2
    hi,
    i am stuck at a point where i press (c) in play mode and the projectile would successfully instantiated but it does not move and i get a (
    NullReferenceException: Object reference not set to an instance of an object)
    and as it shown the problem is in this code :
    Code (CSharp):
    1.     void Launch()
    2.     {
    3.         GameObject projectileObject = Instantiate(projectilePrefab, rb2d.position + Vector2.up * 0.5f, Quaternion.identity);
    4.         Projectile projectile = projectileObject.gameObject.GetComponent<Projectile>();
    5.         projectile.Launch(lookDirection, 300);
    6.         animator.SetTrigger("Launch");
    7.     }
    8.  
    please notice that i have already made a public GameObject as (projectilePrefab) and also already changed the start to awake function in Projectile Script
    thanks
     
  41. GeekyMonkey

    GeekyMonkey

    Joined:
    Feb 9, 2013
    Posts:
    13
    You don't say which line the exception occurs on. Since the prefab instance appears, we can sssume line 3 above is OK.

    If the error is on line 5 then it could be one of two things: The prefab doesn't have a "Projectile" component on it, or the lookDirection variable isn't set.

    If the error is on line 6, then your object's "animator" variable hasn't been initialized in your Start function.
     
    Mad_Mark97 likes this.
  42. Mad_Mark97

    Mad_Mark97

    Joined:
    Mar 20, 2019
    Posts:
    2
    i just checked the projectile prefab and didn't found the script so this was the cause of the Error
    thank u for helping me
     
  43. SynolBAKA

    SynolBAKA

    Joined:
    May 20, 2019
    Posts:
    3
    I just went back and had another look, you're right. That's what I get for going through all that reading and coding in a single day. I completely missed it! Sorry about that.

    As for the first issue, I think adding the part you mentioned would be great. For someone who had never used Pivots before it wouldn't hurt to get a friendly reminder :)

    Got all the way through the tutorial though, thanks for making it. Was fun and I learned a lot.
     
  44. mr_noodler

    mr_noodler

    Joined:
    May 11, 2019
    Posts:
    6
    Thanks so much firahs! It's always some teenie tiny detail lol!
     
  45. mr_noodler

    mr_noodler

    Joined:
    May 11, 2019
    Posts:
    6
    However, I'm still not seeing the smoke effect render for some reason...
     
  46. mr_noodler

    mr_noodler

    Joined:
    May 11, 2019
    Posts:
    6
    In the visual styling : UI lessons I am getting a console message for a NullReferenceException on the 'originalSize = mask.rectTransform.rect.width;' line. I suspect that 'public Image mask' & 'float originalSize' are not initialized to anything and simply pointing nowhere.

    Should those values be initialized? The UI health bar is not working as a result of this.
     
    thathurtabit and Cute_Poops like this.
  47. changlihan4595

    changlihan4595

    Joined:
    May 19, 2019
    Posts:
    2
    I'll make sure we add this information to the tutorial too! Thank you for your feedback![/QUOTE]

    Hi, thanks for your reply, and I tried these two solutions, and unfortunately both of them are not working. And I guess the main problem is not about the position. Probably last time I didn't state the issue clearly enough. This time I will take hitEffect for example, here is what I did:
    Disable Looping and set the Stop Action to Destroy.
    Set the Rate over Time to 0, to not generate any particles over time.
    Set a burst of 20 particles at time 0.0
    call
    Instantiate(hitEffect, transform.position, Quaternion.identity)
    in RubyController script when amount <0 in ChangeHealth function.
    And when I played the Game, the hitEffect shows up immediately and it appear only once above Ruby's head(where I set it like the way I set smokeEffect above robot's head). And When I step on the DamageZone, it will not show up and the console will give me error message
    "MissingReferenceException: The object of type 'ParticleSystem' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    UnityEngine.Object.Instantiate[T] (T original) (at C:/buildslave/unity/build/Runtime/Export/Scripting/UnityEngineObject.bindings.cs:266)
    RubyController.ChangeHealth (System.Int32 amount) (at Assets/Scripts/RubyController.cs:101)
    DamageZone.OnTriggerStay2D (UnityEngine.Collider2D other) (at Assets/Scripts/DamageZone.cs:15)
    ".
    Apparently it shouldn't suppose to work that, and there are also some other experiment with hitEffect which I did try to solve the issue. Hope they will give you more infomation.
    1. I tried to use triggers, and nothing changed(not fully sure).
    2. I unchecked play on awake option of hitEffect, and there is no hitEffect shows up at the beginning and when I step on damageZone, there is no hitEffect shows up as well. But in the Hierarchy window, there are some clones of hitEffect, and never vanishes.
     
    Last edited: May 25, 2019
  48. SynolBAKA

    SynolBAKA

    Joined:
    May 20, 2019
    Posts:
    3
    Just checked mine and I have this unchecked as well. I'm not sure if this is going to help but it seems like you're missing a line of code (based on what you said you did). Here is my code from the RubyController:


    Code (CSharp):
    1. GameObject playerHit = Instantiate(hitEffect, rigidbody2d.position + Vector2.up * 0.5f, Quaternion.identity);
    2. playerHit.GetComponent<ParticleSystem>().Play();
     
    Nakhum likes this.
  49. OliverHearn

    OliverHearn

    Joined:
    May 24, 2019
    Posts:
    1
    As a complete noob to programming and Unity, this tutorial has been amazing. I've managed to problem solve my own mistakes so far, but i'm now stuck on the particles tutorial.

    Despite adding:

    smokeEffect.Stop();

    within the Fix function, the smoke effect won't stop after hitting with the projectile.
    I dragged the smoke prefab to the inspector slot.

    This is my enemy code:

    Code (CSharp):
    1. public class BotController : MonoBehaviour
    2. {
    3.     public float speed = 3.0f;
    4.     public bool vertical;
    5.     public float changeTime = 3.0f;
    6.     public ParticleSystem smokeEffect;
    7.     Animator animator;
    8.     bool broken = true;
    9.  
    10.     Rigidbody2D rigidbody2D;
    11.     float timer;
    12.     int direction = 1;
    13.  
    14.     // Start is called before the first frame update
    15.     void Start()
    16.     {
    17.         rigidbody2D = GetComponent<Rigidbody2D>();
    18.         timer = changeTime;
    19.         animator = GetComponent<Animator>();
    20.     }
    21.  
    22.     // Update is called once per frame
    23.     void Update()
    24.     {
    25.         timer -= Time.deltaTime;
    26.  
    27.         if(!broken)
    28.         {
    29.             return;
    30.         }
    31.  
    32.         if (timer < 0)
    33.         {
    34.             direction = -direction;
    35.             timer = changeTime;
    36.         }
    37.         Vector2 position = rigidbody2D.position;
    38.  
    39.         if (vertical)
    40.         {
    41.             position.y = position.y + Time.deltaTime * speed * direction;
    42.             animator.SetFloat("Move X", 0);
    43.             animator.SetFloat("Move Y", direction);
    44.         }
    45.         else
    46.         {
    47.             position.x = position.x + Time.deltaTime * speed * direction;
    48.             animator.SetFloat("Move X", direction);
    49.             animator.SetFloat("Move Y", 0);
    50.         }
    51.  
    52.        rigidbody2D.MovePosition(position);
    53.     }
    54.     private void OnCollisionEnter2D(Collision2D other)
    55.     {
    56.         RubyController player = other.gameObject.GetComponent<RubyController>();
    57.  
    58.         if (player != null)
    59.         {
    60.             player.ChangeHealth(-1);
    61.         }
    62.     }
    63.  
    64.     public void Fix()
    65.     {
    66.         broken = false;
    67.         rigidbody2D.simulated = false;
    68.         animator.SetTrigger("Fixed");
    69.         smokeEffect.Stop();
    70.     }
    71. }
    I appreciate any help, thank you!
     
    zach0330 and ciavyn like this.
  50. Taylor_Chiu

    Taylor_Chiu

    Joined:
    May 27, 2019
    Posts:
    8
    I have just finished learning this project, great tutorial.
    But after I built the game I found a bug, that is if I run the game in full-screen, both ruby and robots moved extremely slow. But if I run the game with "windowed" ticked, they move normally.
    I thought maybe I'd made some mistake in my code, so I downloaded the complete project from unity store. Turns out the same problem happened again.
    I have tried different resolution, none of them matter. Its just about full-screen or not.
    I tried replacing the moving code
    Code (CSharp):
    1. position = position + move * speed * Time.deltaTime;
    with
    Code (CSharp):
    1. position = position + move * speed;
    ruby move speed depends on the frame rate now, just like the tutorial warned about, but she's not affected by full-screen anymore. So maybe there's some problem about checking Time.deltaTime when the game is full-screen?
     
    CarMarc likes this.