Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Aug 09, 2019 at 03:02 PM by Beginner_at_Unity for the following reason:

Issue solved by forum and by tutorial. App is working as expected.

avatar image
0
Question by Beginner_at_Unity · Aug 01, 2019 at 12:38 PM · missingbomb

Ninja fruit - code correct but bomb missing

Updated: I have reviewed part of the tutorial but still cannot get the bomb to appear when play is clicked. To avoid long unnecessary stories, I am putting a screenshot of what the tutorial show and what I have. The codes (scripts) have been left out as I won't know what you experts want to check. You can request for the entire project if you have time. I have fixed 2019.2.0 so that although error messages appear on the status, it doesn't affect the app at all. I've tested other apps and successfully created the .apk installation files and everything works well. Please see the screenshot of the bomb - shown in white box and my screen where the fruit spawner has the correct items filled. What do i need to check or edit?

alt text alt text

fruit-ninja-bomb-spawning-my-screen.jpg (98.3 kB)
fruit-ninja-bomb-spawning-tutorial-screen.jpg (100.2 kB)
Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image xxmariofer · Aug 09, 2019 at 09:44 AM 1
Share

share the errors appearing and the spawner code, if you are sure the code is fine then the issue is with the errors, even if you play the game if there are errors app may not work as expected

avatar image Kennai · Aug 09, 2019 at 10:17 AM 0
Share

Hello, @JulianHSC ! In what script bomb is missing? Check that attribute in inspector. If it is filled, then I suggest you to set break point at line, where bomb is missing and debug it. If in debug mode that value is really empty, then you clear it somewhere in code maybe?

avatar image Beginner_at_Unity Kennai · Aug 09, 2019 at 10:31 AM 0
Share

I don't know how to use debug. I'm still quite new to Unity. I would be happier if someone can just check what's wrong with the code OR if the player is the problem.

avatar image xxmariofer Beginner_at_Unity · Aug 09, 2019 at 10:39 AM 0
Share

add to all of the methods Debug.Log("$$anonymous$$ethod name"); changing the method name for the actual method name, like Debug.Log("StartSpawning"); and tell us if all are getting printed right, share the errors that appear in the console

Show more comments
avatar image Beginner_at_Unity · Aug 09, 2019 at 10:30 AM 0
Share
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class FruitSpawner : $$anonymous$$onoBehaviour
 {
     public GameObject fruit;
     public GameObject bomb2;
     public float maxX;
 
     // Start is called before the first frame update
     void Start()
     {
         Invoke("StartSpawning", 1f);
 
     }
 
     // Update is called once per frame
     void Update()
     {
 
     }
 
     public void StartSpawning()
     {
         InvokeRepeating("SpawnFruitGroups", 1, 6f);
 
     }
 
     public void StopSpawning()
     {
 
         CancelInvoke("SpawnFruitGroups");
         StopCoroutine("SpawnFruit");
 
     }
 
     void SpawnBomb()
     {
         float Rand = Random.Range(-maxX, maxX);
         Vector3 pos = new Vector3(Rand, transform.position.y, 0);
         GameObject b = Instantiate(fruit, pos, Quaternion.identity) as GameObject;
         b.GetComponent<Rigidbody2D>().AddForce(new Vector2(0, 15f), Force$$anonymous$$ode2D.Impulse);
         b.GetComponent<Rigidbody2D>().AddTorque(Random.Range(-50f, 50f));
 
     }
 
     public void SpawnFruitGroups()
     {
         StartCoroutine("SpawnFruit");
 
         if (Random.Range(0,6) > 4)
         {
             SpawnBomb();
 
         }
 
     }
 
     IEnumerator SpawnFruit()
     {
 
         for (int i = 0; i < 5; i++)
         {
 
             float Rand = Random.Range(-maxX, maxX);
             Vector3 pos = new Vector3(Rand, transform.position.y, 0);
             GameObject f = Instantiate(fruit, pos, Quaternion.identity) as GameObject;
             f.GetComponent<Rigidbody2D>().AddForce(new Vector2(0, 15f), Force$$anonymous$$ode2D.Impulse);
             f.GetComponent<Rigidbody2D>().AddTorque(Random.Range(-50f, 50f));
             yield return new WaitForSeconds(0.5f);
 
         }
     }
 
 }

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by Kennai · Aug 09, 2019 at 12:24 PM

in function SpawnBomb you spawn fruit,not bomb.

 GameObject b = Instantiate(fruit, pos, Quaternion.identity) as GameObject;

replace fruit with bomb2.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image xxmariofer · Aug 09, 2019 at 01:11 PM 0
Share

his issue is most likely this " I have fixed 2019.2.0 so that although error messages appear on the status, it doesn't affect the app at all" in the screenshot he shared not even bombs and fruits get iinstantiated. the errors are most likely affecting the gameplay

avatar image Beginner_at_Unity · Aug 09, 2019 at 02:34 PM 1
Share

Thank you. Your code worked. But i still had to play around with the object in prefab and outside. Now both my fruit and bomb does show. However, the bomb rarely appears. But still your code at least solved it. Earlier on, the bomb just refused to appear. But now I'm wondering : is there a way to make the bomb appear more often - i mean without adding much code to it?

avatar image Kennai Beginner_at_Unity · Aug 09, 2019 at 02:52 PM 0
Share

look at function SpawnFruitGroups
there is line if (Random.Range(0,6) > 4)
so it generates random value between 0..5 and if it is greater than 4 - it creates bomb.
if you want increase appearing - just decrease value 4. like that: if (Random.Range(0,6) > 2)

avatar image Beginner_at_Unity Kennai · Aug 09, 2019 at 03:01 PM 1
Share

Yes, I just checked the tutorial again and that's the answer. Thanks for your great help. This case has been pending for a few weeks / months. I think you solved the biggest problem I had in the entire course. Now I can take a short vacation before continuing my course.

Show more comments

Follow this Question

Answers Answers and Comments

109 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Standalond built for Windows doesn't include text assets 0 Answers

The 3 mono scripts that come with the First Person Controller asset are missing! 1 Answer

Creating a Prefab and Keeping Original Objects Script Information 0 Answers

Checking to see if a Public transform is (missing) 1 Answer

Door Missing 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges