Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 /
avatar image
0
Question by Dollar-Fish · Jul 29, 2015 at 11:44 AM · unity 2dgameobjectsspawningvector2create

Spawn GameObject Above and Below GameObject

I want to have it so when he shoots and hits a fruit, it will spawn a split picture of the fruit above the watermelon and below it. It will destroy the fruit, but I want the split picture to spawn where ever the fruit is because the fruit falls and you try to hit the fruit. So to kinda sum it up, I want it to spawn an object above and below where ever the watermelon is when I shoot. Thank you in advance.

alt text

UnityEngine; using System.Collections;

public class attackTrigger : MonoBehaviour {

 public GameObject watermelon;
 public GameObject strawberry;
 public GameObject grape;
 public GameObject banana;
 public GameObject orange;
 public GameObject tomato;
 public GameObject pineapple;
 public GameObject apple;
 public GameObject blueberry;
 public GameObject raspberries;
 public GameObject pear;
 public GameObject blackberries;
 public GameObject lemon;

 public GameObject watermelon_split;
 public GameObject strawberry_split;
 public GameObject grapes;
 public GameObject banana_split1;
 public GameObject banana_split2;
 public GameObject orange_split;
 public GameObject pineapple_split;
 public GameObject apple_split;
 public GameObject blueberry_split;
 public GameObject raspberry;
 public GameObject pear_split;
 public GameObject blackberry;
 public GameObject lemon_split;

 public AudioSource score;
 public AudioSource hit1;
 public AudioSource hit2;
 public AudioSource hit3;
 public AudioSource hit4;
 public AudioSource hit5;

 private gameMaster gm;
 private spawnFruit spawnfruit;

 public int number = 0;


 void Start()
 {
     gm = GameObject.FindGameObjectWithTag("GameMaster").GetComponent<gameMaster>();
     spawnfruit = GameObject.Find("spawnFruit").GetComponent<spawnFruit>();
 }

 void randomHit()
 {
     number = Random.Range (1,6);

     if(number == 1)
     {
         hit1.Play ();
     }
     if(number == 2)
     {
         hit2.Play ();
     }
     if(number == 3)
     {
         hit3.Play ();
     }
     if(number == 4)
     {
         hit4.Play ();
     }
     if(number == 5)
     {
         hit5.Play ();
     }
 }
 void OnTriggerEnter2D(Collider2D col) 
 {         
     if(col.isTrigger != true && col.CompareTag("watermelon")) 
     {
         score.Play ();
         gm.points += 1;
         Invoke("randomHit", 0f);
         Destroy(col.gameObject);
     }
     if(col.isTrigger != true && col.CompareTag("strawberry")) 
     {
         score.Play ();
         gm.points += 1;
         Invoke("randomHit", 0f);
         Destroy(col.gameObject);
     }
     if(col.isTrigger != true && col.CompareTag("grapes")) 
     {
         score.Play ();
         gm.points += 1;
         Invoke("randomHit", 0f);
         Destroy(col.gameObject);
     }
     if(col.isTrigger != true && col.CompareTag("banana")) 
     {
         score.Play ();
         gm.points += 1;
         Invoke("randomHit", 0f);
         Destroy(col.gameObject);
     }
     if(col.isTrigger != true && col.CompareTag("orange")) 
     {
         score.Play ();
         gm.points += 1;
         Invoke("randomHit", 0f);
         Destroy(col.gameObject);
     }
     if(col.isTrigger != true && col.CompareTag("tomato")) 
     {
         spawnfruit.fruitHit = true;
     }
     if(col.isTrigger != true && col.CompareTag("pineapple")) 
     {
         score.Play ();
         gm.points += 1;
         Invoke("randomHit", 0f);
         Destroy(col.gameObject);
     }
     if(col.isTrigger != true && col.CompareTag("apple")) 
     {
         score.Play ();
         gm.points += 1;
         Invoke("randomHit", 0f);
         Destroy(col.gameObject);
     }
     if(col.isTrigger != true && col.CompareTag("blueberry")) 
     {
         score.Play ();
         gm.points += 1;
         Invoke("randomHit", 0f);
         Destroy(col.gameObject);
     }
     if(col.isTrigger != true && col.CompareTag("raspberries")) 
     {
         score.Play ();
         gm.points += 1;
         Invoke("randomHit", 0f);
         Destroy(col.gameObject);
     }
     if(col.isTrigger != true && col.CompareTag("pear")) 
     {
         score.Play ();
         gm.points += 1;
         Invoke("randomHit", 0f);
         Destroy(col.gameObject);
     }
     if(col.isTrigger != true && col.CompareTag("blackberries")) 
     {
         score.Play ();
         gm.points += 1;
         Invoke("randomHit", 0f);
         Destroy(col.gameObject);
     }
     if(col.isTrigger != true && col.CompareTag("lemon")) 
     {
         score.Play ();
         gm.points += 1;
         Invoke("randomHit", 0f);
         Destroy(col.gameObject);
     }
 }
 

}

capturefr.png (15.2 kB)
Comment
Add comment · Show 2
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 Dollar-Fish · Jul 30, 2015 at 07:58 PM 0
Share

Can I make this work?

avatar image maccabbe · Jul 30, 2015 at 08:43 PM 0
Share

If you are just starting out with Unity we suggest checking out the Learn section, as there exists several tutorials, documentation and live training sessions.

http://unity3d.com/learn

If you need to learn about program$$anonymous$$g then please go through the scripting tutorials.

https://unity3d.com/learn/tutorials/topics/scripting

Specifically, instantiating new objects is covered in part 24 "Instantiate".

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Spawn A Set Amount of Objects at Set Location 1 Answer

How to make Mobile Touch Controls work when pressing the left and right side of the screen 1 Answer

Filling array with children of multiple undefined gameobjects? 1 Answer

How do I instantiate a class Object, then store it in an Array of Class Objects in C#? 1 Answer

destroy prefabs when they hit the player 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