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 /
  • Help Room /
avatar image
0
Question by rosy5 · Feb 12, 2016 at 01:46 PM · shootingscorespawnpoints

How do you script an object to shoot like a comet (shooting star)?

So my main concern is being able to scatter a certain amount of gold coins onto a surface that is NOT flat, but on a sphere.
Here are a few tests I tried--

First Try : Place in a row and repeat I created the coin (I used a cylinder with a material). Once I placed the coin in the scene I duplicated the coin in one row around the sphere. After the row was completed, I duplicated the row and rotated it a few times. Every time I rotated a row of coins it would always appear in an oval shape. IN PLAY MODE: the player runs around in the scene and ALL the coins were above the player and it appeared like Christmas lights, but player could not reach them.

Second Try: use spawnpoints I made the coin as a prefab and used an instantiate function, the function works and the coins spawn, but the score stopped updating to the screen and was not disappearing when the player collided. The coin stretches and looks flat while rotating.

Third Try: At Runtime have the coin shoot to the spawnpoints Here is my third effort, since the coins refuse to stay on the surface of the sphere, I figured I can shoot the coins to there position and when the player hits the coins it will hide. However, my code says it has no errors but nothing is happening. I figured a shooting script would work. Would a raycast work if i were to calculate the distance between the coin and spawnpoint? I have tried OnCollisionEnter--nothing, I also tried the "Sphere overlay" within the physics -- i forgot the name. What I want the code to is this:

Puesdo Code: at start the coins position moves towards random spawnpoints BUT gold coin per spawnpoint

if(there is a cold piece in the spawnpoint) go to another one

if(the coin position and the spawnpoint position are the same) the coin rotates

if(the player comes in contact with the coin) the coins worth (10 points) is added to the player's score score is updated coin object hides

This is what i Have so far: using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI;

public class coinTurns : MonoBehaviour { //ref to the object cion public GameObject coin; //list of the spawnpoints for the coins public List spawnpoints; //ref to the planet public GameObject planet;

 // Reference in the inspector UI_Generic.cs that is attached 
 // to your UIHandler
    public UI_Generic myUI_generic;
 public ObjRefs obj;

 void Start()
 {

     FlyTowards();
 }

 void Scatter()
 {
     for(int i = 0; i < spawnpoints.Count; i++)
     {
         Instantiate(coin, spawnpoints[i].transform.position, spawnpoints[i].transform.rotation);
     }
 }
 public void FlyTowards()
 {
     Scatter();
     for (int i = 0; i < spawnpoints.Count; i++)
     {
         foreach (Transform point in spawnpoints)
         {
             //point = spawnpoints[i].transform.position;
             coin.transform.position = Vector3.MoveTowards(coin.transform.position, point.transform.position, 50.0f);
         }
     }
 }
 void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject == coin) 
     {
         coin.transform.LookAt(planet.transform.position);
         Physics.OverlapSphere(planet.transform.position, 300f);
     }
     if (collision.gameObject == obj.cappyPlayer)
     {
         obj.Score (10);
         obj.UpdateScore();
     }
 }
 void OnCollisionExit(Collision collision)
 {
     if(collision.gameObject == obj.cappyPlayer)
         coin.SetActive(false);
 }
 void Update ()
 {
     //rotates the coins 
     transform.Rotate(transform.right, 50 * Time.deltaTime);    
 }

}

Comment
Add comment
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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Help With Score C# Error CS0131 1 Answer

Spawn Object on Set Score 0 Answers

Increasing score when wall reaches end of screen,Trying to get score to increase when a wall reaches the end of the screen 0 Answers

How to spawn trigger boxes? 0 Answers

(17,37): error CS0841: A local variable `spawnPointIndex' cannot be used before it is declared 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