Can someone help me with my scrip i can't get it to work im trying create primitive and non-primitive objects.
using UnityEngine; using System.Collections;
public class LoopsAndArrays1 : MonoBehaviour { private Vector3 randomPosition; private Vector3 offset; public static GameObject CreatePrimitive(PrimitiveType type);
// Use this for initialization
void Start ()
{
// Create a Cylinder
GameObject cylinder = GameObject = CreatePrimitive (PrimitiveType.Cylinder);
// Origin via Script
cylinder.transform.position = new Vector3(0, 2, 0);
// Dimensions of Cylinder
float height = cylinder.GetComponent<Renderer>().bounds.size.y;
Debug.Log ("Cylinder Height = " + height);
float width = cylinder.GetComponent<Renderer>().bounds.size.x;
Debug.Log ("Cylinder Width (Diameter) = " + width);
Debug.Log ("Cylinder Dimensions = " + cylinder.GetComponent<Renderer> ().bounds.size);
//Generate a Random Position --> output to file (2 & 3)
Vector3 randomPosition = new Vector3(
Random.Range(-10, 10),
Random.Range(-10, 10),
Random.Range(-10,10));
}
// Create a cube at a random position.
GameObject cube = GameObject = CreatePrimitive (PrimitiveType.Cube);
//Cube generated in a random position.
cube.transform.position = randomPosition
GameObject (Cube); = myGameObject;
offset = new Vector3 (2, 2, 2);
// A row of Cubes along the x-axis
for(int i=0; i>5; ++i);
// create a cube
GameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
Vector3 position = offset + new Vector3 ( i*(myCube.GetComponent<Renderer>)
0,
0);
}
Ok that´s better. So what´s the problem what is the error message? I did not rly see anything wrong, although i have not made many (none) primitives myself. Do you have to use GameObject.CreatePrimitive
?
You could also use Instantiate(aGameObject, transform.position, transform.rotation)
You can modify the position and rotation easily. If you rly want to create primitives then post the error message below. Or is there no error but it does not do anyting?
sorry for the if i have not clarified it more better but this is what im trying to do 1. Create a cylinder at the origin with a script 2. Find its dimensions via script 3. Generate a random position where 0 < x, y, z < 10 4. Output the results of steps 2 and 3 to a file 5. Create a cube in a scene via script, at the random position in step 2 above 6. Use loops to place a specified number of cubes along the x-axis, starting at the origin 7. Use loops to place a specified number of spheres along the y-axis, starting at the origin 8. Use loops to place a specified number of cylinders along the z-axis, starting at the origin 9. Use arrays to specify 5 different ‘non primitive’ game objects 10. Place these non-primitive game objects in random locations (as in step 3) on the x-z plane
So you have a plan, but you do not know how to code a part of it? Sadly I am not the best coder myself, but maybe someone else can help you. If that´s your problem.
good luck to you!
Answer by DonkeyMalonkey · Jul 18, 2016 at 06:22 AM
You should also write what exactly you want to do. I may be able to help you but i am not going to guess what you want to do by reading your script.
Your answer
![](https://koobas.hobune.stream/wayback/20220612085031im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Error CS1525: Unexpected symbol `;', expecting `)', or `,' 1 Answer
Error Unexpected Symbol ';' expecting ')' or ',' 1 Answer
error CS1525: Unexpected symbol `offsetX' 1 Answer
Why do I have errors on all of my private declarations and on my void update? 1 Answer
My "if" statement doesn't work? 2 Answers