Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 kasazwix · Jan 11, 2015 at 06:08 PM · instantiatedirectioncubediffuse

Change the direction of the Cube instantiate

Hi , How can I change the direction of where the cubes are instantiated ? with this script just goes in the direction (up) and (down) the cube instantiate , I want that must go only (forward) the cube Instantiate


 using UnityEngine;
 using System.Collections;
 
 
 public class InfiniteCubes: MonoBehaviour 
 {
     
     #region Emission System
     public         GameObject     cube                ;
     public         float         life        = 1        ;
     public        float        spawnSpeed    = 1        ;
     private        float        timer                ;
     #endregion
 
 
     #region Start
     public void Start()
     {
         if (cube == null)
         {
             var generateCube = GameObject.CreatePrimitive (PrimitiveType.Cube);
             generateCube.GetComponent<Renderer>().material = new Material (Shader.Find("Diffuse"));
             cube = generateCube;
         }
     }
     #endregion
 
 
     #region Update
     public void Update()
     { 
         timer += 1 * Time.deltaTime;
 
         if(timer >= spawnSpeed)
         {
             GameObject cubeClone;
             cubeClone = Instantiate(cube, transform.position, transform.rotation) as GameObject;
             cube.transform.parent = this.transform;
             Destroy(cubeClone, life);
             timer = 0;
         }
 
     }
     #endregion 
 
 }
Comment
Add comment · Show 4
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 Mmmpies · Jan 11, 2015 at 08:23 PM 0
Share

Do you mean you want change the position along a certain rotation that the clones instantiate?

It's just you're saying forward so it's not clear if you want just the rotation to change or you want to move along a certain rotation and instantiate 1 after another, like this but in a single line not a square of them:

InstantiaedObjects

instantiated.png (255.9 kB)
avatar image kasazwix · Jan 11, 2015 at 08:33 PM 0
Share

the position of the instantiated cubes and than i do not want the rotation

avatar image AwesumeOne · Jan 12, 2015 at 05:33 AM 0
Share

When you say forward, do you mean the rotation?

avatar image kasazwix · Jan 12, 2015 at 04:33 PM 0
Share

rotation? no

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by tanoshimi · Jan 11, 2015 at 07:55 PM

Rotation is the third parameter you pass to Instantiate.

e.g.

 cubeClone = Instantiate(cube, transform.position, Quaternion.identity) as GameObject;



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 tanoshimi · Jan 11, 2015 at 08:24 PM 0
Share

What goes up and down? Can you post a screenshot?

avatar image kasazwix · Jan 11, 2015 at 08:33 PM 0
Share

the cubes instantiated , goes up and down

avatar image kasazwix · Jan 11, 2015 at 09:02 PM 0
Share

I want that the cubes instantiated , must go only in the position (forward) and not (up) and (down)

avatar image kasazwix · Jan 11, 2015 at 09:20 PM 0
Share

I want to instantiate the cubes as if they were the bullets of a gun

avatar image kasazwix · Jan 12, 2015 at 12:05 PM 0
Share

I want to create an automatic cannon that shoots cubes , in the forward position

avatar image
0

Answer by Mmmpies · Jan 11, 2015 at 08:45 PM

OK this is the script that I used for instantiating those, it creates an array but you just need something more simple.

 using UnityEngine;
 using System.Collections;
 
 public class testScript : MonoBehaviour {
     
     public GameObject Prefab;
     public float timer = 0f;
     public float time_of_spawn = 0f;
     public int Xn;
     public int Zn;
 
     private bool spawn = true;
     
     void Update() {
         //timer += Time.deltaTime;
 
         if (spawn) 
         {
             spawn = false;
             for (int x = 0; x < Xn; x++)
             {
                 for (int z = 0; z < Zn; z++)
                 {
                     Instantiate(Prefab, new Vector3 (100 + x,  0.5f, 100 + z), Quaternion.identity);
                     //timer = 0f;
                 }
             }
         }
     }
 }

It's based on a question someone else asked so there are some bit's you don't need.

Look at the "new Vector3" I create in the Instantiate command, you only need x or z if you only need a line of Objects.

If you struggling let me know and I'll try and fit it in with your script.

EDIT:

I've re-read this question. It's still not obvious if this is a correct answer. Do you want a line of instantiated objects or do you want to instantiate and move the object forward? Just answer line or move.

Oh and stop posting random text to keep this at the top of the list, it's more likely to make people ignore the post.

EDIT 2:

Then ignore all that. You want to add a rigidbody to the bullet prefab and apply force to it, I do this for arrows:

 rigidbody.AddForce(transform.TransformDirection (Vector3.right) * (_force / 5));

just play with the (_force / 5) bit, change that so it's just a number, a low number will fall to the floor quickly so just increase it till it works for your game. Depending on the way your bullet is you may want Vector3.right or Vector3.left or Vector3.forward, well you get the point.

Also search for instantiate bullet on here there will be lots and lots of examples.

Comment
Add comment · Show 4 · 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 kasazwix · Jan 11, 2015 at 09:19 PM 0
Share

I want to instantiate the cubes as if they were the bullets of a gun , in the forward position

avatar image Mmmpies · Jan 11, 2015 at 11:24 PM 0
Share

Do you want the bullets to not fall to the ground?

Or do you want the bullets not to be affected by gravity?

I think there's a bit of language issue here, that's O$$anonymous$$ what language is do you speak normally?

PS very late where I am so may not get back to you until tomorrow.

avatar image kasazwix · Jan 11, 2015 at 11:30 PM 0
Share

$$anonymous$$ust not fall to the ground , and Yes I want that must be affected by gravity

avatar image kasazwix · Jan 12, 2015 at 12:05 PM 0
Share

I want to create an automatic cannon that shoots cubes , in the forward position

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Instantiating prefabs, when there is nothing 2 Answers

Adding Imperfections? 1 Answer

Instantiate object at position, moving in a direction? 1 Answer

(C#) How does one position instantiated objects locally, not to the world? 1 Answer

Placing static prefabs on click 2 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