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 Sernostine · Oct 06, 2015 at 05:38 PM · instantiate

Instantiate a particle system, probably a stupid question

hey guys, new to unity and programming.

the function I want to realize is like:

click A(startpoint) , right click B(endpoint), instantiate a particle system from A to B.

its not finish, cause I know there are many logic problems here, can you guys give me some hint on how i can make this work? also,why i can't use startpoint to assign a value to flowClone.transform.position?

Thanks!

 void connection()
 {
     Vector3 startpoint;
     Vector3 endpoint;
     ParticleSystem flowClone;
     bool startpointget;
     bool endpointget;

     if (Input.GetMouseButton(0))
     {
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit))
         {
             startpoint = hit.collider.transform.position;
         }
     }

     if (Input.GetMouseButton(1))
     {
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit))
         {
            endpoint = hit.collider.transform.position;
         }
     }

     flowClone = Instantiate(flow, Vector3.zero, Quaternion.identity) as ParticleSystem;
    flowClone.transform.position = startpoint;


 }
Comment
Add comment · Show 1
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 Gilles_aerts · Oct 06, 2015 at 05:52 PM 0
Share

If you split off some of your questions I might be able to help you out a little better

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Gilles_aerts · Oct 06, 2015 at 05:51 PM

Hi , I'm not sure what your real question is , but you cannot instantiate a particle system variable ( atlas not to my knowledge) . if you want to instantiate a particleSystem you have to make a gameObject of it. so instead of initializing : particleSystem FlowClone ; make a gameObject : Public Gameobject FlowClone;

assign the particle systemPrefab to the public gameObject variable in your inspector. I was always learned that you can only instantiate gameObjects so this might do the trick.

Comment
Add comment · Show 2 · 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 Sernostine · Oct 06, 2015 at 11:49 PM 0
Share

sorry for my uncleard question.

$$anonymous$$y question can be split into several part:

1: i want instantiate a particleSystem on a position of other objects. So I use Ray to select objects, and get the position from that.(as you can see in line15). But it seems i can't assign the startpoint to flowclone.tranform.position. theres a red line under the "startpoint" in line30.

2:Is there a better logic to do this: instantiate a particle system from startpoint to endpoint.

hope i make it clear. thanks for replying.

avatar image Gilles_aerts Sernostine · Oct 07, 2015 at 06:52 AM 0
Share

alright here is what you need to do. You need to make a prefab of the particleSystem you wish to instantiate. Then you need to make a public GameObject variable in your script and name it something like myPartcleSystem or flowClone as you did earlier. so you should have ( public GameObject flowClone; )

the instantiate functions ask for 3 things( what prefab , what position, and what rotation) But looking at your code you already knew that ;)

now if you want to instantiate it on the same position as an object you just simply use his position : instantiate(flowCone,objectIwant.transform.posistion,quaternion.identity); the objectIwant is most likely another public game object in the scene. you can also use a transform variable but then you have to leave out the transform.position.

avatar image
0

Answer by Sernostine · Oct 09, 2015 at 02:22 PM

Thanks, guy!

it works. Assigning a initial value at the first is also necessary.

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

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

31 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

Related Questions

I want to Instantiate a force field - let it work for x(sec) show countdown and then make wait for a count up - but then my button doesn't seem to work anymore? 0 Answers

Add Component with Script Data 1 Answer

Create gameobject in other scene... 0 Answers

Trying to make a void run continously at a interval (changeable by variable) while finger is held on screen 0 Answers

Instantiated button prefab causes Delegation error on click and does not add OnClick Listener 0 Answers


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