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 junkdog8 · Dec 12, 2014 at 12:05 AM · debug

Having some problems with randomization

Hey guys, I am trying to add some more randomization in to this procedurally generated fractal script and it is pitching some fits that i cannot seem to fix.

here is the script using UnityEngine; using System.Collections;

 public class Fractal : MonoBehaviour
 {
     public Mesh mesh;
     public Material material;
 
     private int depth;
 
     public int maxDepth;
 
     public float childScale;
 
     private Material[] materials;
 
     private float _nr = Random.Range(-80f, -100f);
 
     private float _r = Random.Range(80f, 100f);
 
     private Color RandomColour()
     {
         float r = Random.value;
         float g = Random.value;
         float b = Random.value;
         
         return new Color(r, g, b);
     }
     
     private void InitializeMaterials ()
     {
 
         materials = new Material[maxDepth + 1];
         for (int i = 0; i <= maxDepth; i++)
         {
             materials[i] = new Material(material);
             material.color = RandomColour();
         }
     }
     
     private void Start ()
     {
         if (materials == null)
         {
             InitializeMaterials();
         }
 
         gameObject.AddComponent<MeshFilter>().mesh = mesh;
         gameObject.AddComponent<MeshRenderer>().material = materials[depth];
         gameObject.AddComponent<Material>
         if (depth < maxDepth)
         {
             StartCoroutine(CreateChildren());
         }
     }
     private static Vector3[] childDirections =
     {
         Vector3.up,
         Vector3.right,
         Vector3.left,
         Vector3.forward,
         Vector3.back;
     }
     
     private static Quaternion[] childOrientations =
     {
         Quaternion.identity,
         Quaternion.Euler(0f, 0f, _nr),
         Quaternion.Euler(0f, 0f, _r),
         Quaternion.Euler(_r, 0f, 0f),
         Quaternion.Euler(_nr, 0f, 0f);
     }
     
     private IEnumerator CreateChildren ()
     {
         for (int i = 0; i < childDirections.Length; i++)
         {
             yield return new WaitForSeconds(Random.Range(0.1f, 0.5f));
             new GameObject("Fractal Child").AddComponent<Fractal>().Initialize(this, i);
         }
     }
     
     private void Initialize (Fractal parent, int childIndex)
     {
         mesh = parent.mesh;
         material = parent.material;
         maxDepth = parent.maxDepth;
         depth = parent.depth + 1;
         childScale = parent.childScale;
         transform.parent = parent.transform;
         transform.localScale = Vector3.one * childScale;
         transform.localPosition = childDirections[childIndex] * (0.5f + 0.5f * childScale);
         transform.localRotation = childOrientations[childIndex];
     }
 }

and the errors that i am getting are Assets/Fractal Stuff/Fractal.cs(51,18): error CS1525: Unexpected symbol if' Assets/Fractal Stuff/Fractal.cs(62,29): error CS1525: Unexpected symbol ;', expecting ,', or }'

Assets/Fractal Stuff/Fractal.cs(65,15): error CS8025: Parsing error

i have a feeling it is something stupid i missed but i cannot seem to find it so any help would be appreciated

Comment
Add comment · Show 10
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 VesuvianPrime · Dec 11, 2014 at 08:11 PM 0
Share

You have a simple syntax problem:

alt text

You need to put the semi-colon after your array declaration.

avatar image junkdog8 · Dec 11, 2014 at 10:54 PM 0
Share
 ok so now my errors are
 
 Assets/Fractal Stuff/Fractal.cs(51,18): error CS1525: Unexpected symbol `if'
 
 
 Assets/Fractal Stuff/Fractal.cs(56,34): error CS0116: A namespace can only contain types and namespace declarations
 
 
 Assets/Fractal Stuff/Fractal.cs(71,46): error CS1525: Unexpected symbol `;', expecting `,', or `}'
 
 and
 
 Assets/Fractal Stuff/Fractal.cs(74,15): error CS8025: Parsing error
 
avatar image richyrich · Dec 12, 2014 at 12:10 AM 0
Share

Just checking... following Vesuvian's advice, your code should look as follows:

 private static Vector3[] childDirections =
 {
     Vector3.up,
     Vector3.right,
     Vector3.left,
     Vector3.forward,
     Vector3.back
 };
 
 private static Quaternion[] childOrientations =
 {
     Quaternion.identity,
     Quaternion.Euler(0f, 0f, _nr),
     Quaternion.Euler(0f, 0f, _r),
     Quaternion.Euler(_r, 0f, 0f),
     Quaternion.Euler(_nr, 0f, 0f)
 };

avatar image junkdog8 · Dec 12, 2014 at 12:26 AM 0
Share

it does now, but all that did was add more errors...

the errors are now

     Assets/Fractal Stuff/Fractal.cs(51,18): error CS1525: Unexpected symbol `if'
     
     Assets/Fractal Stuff/Fractal.cs(56,34): error CS0116: A namespace can only contain types and namespace declarations
     
     Assets/Fractal Stuff/Fractal.cs(65,37): error CS0116: A namespace can only contain types and namespace declarations
     
     Assets/Fractal Stuff/Fractal.cs(74,29): error CS0116: A namespace can only contain types and namespace declarations
     
     Assets/Fractal Stuff/Fractal.cs(83,22): error CS0116: A namespace can only contain types and namespace declarations
     
     Assets/Fractal Stuff/Fractal.cs(95,1): error CS8025: Parsing error
     
 
avatar image MidgardDev · Dec 12, 2014 at 12:45 AM 0
Share

Show us the line 51 in Fractal.cs

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by SnotE101 · Dec 12, 2014 at 01:59 AM

Line 47 gameObject.AddComponent should be gameObject.AddComponent();

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
avatar image
0

Answer by junkdog8 · Dec 12, 2014 at 07:42 PM

figured it out here is the finished script if anyone wants to try it out...

 using UnityEngine;
 using System.Collections;
 
 public class Fractal : MonoBehaviour
 {
     public Mesh[] meshes;
 
     public Material material;
     
     public int maxDepth;
     
     private int depth;
 
     public float childScale;
 
     public float maxRotationSpeed;
     
     private float rotationSpeed;
 
     public float spawnProbability;
 
     private Material[,] materials;
 
     public float maxTwist;
     
     private void InitializeMaterials ()
     {
         materials = new Material[maxDepth + 1, 2];
         for (int i = 0; i <= maxDepth; i++)
         {
             float t = i / (maxDepth - 1f);
             t *= t;
             materials[i, 0] = new Material(material);
             materials[i, 0].color = Color.Lerp(Color.white, Color.yellow, t);
             materials[i, 1] = new Material(material);
             materials[i, 1].color = Color.Lerp(Color.white, Color.cyan, t);
         }
         materials[maxDepth, 0].color = Color.magenta;
         materials[maxDepth, 1].color = Color.red;
     }
     
     private void Start ()
     {
         rotationSpeed = Random.Range(-maxRotationSpeed, maxRotationSpeed);
         transform.Rotate(Random.Range(-maxTwist, maxTwist), 0f, 0f);
         if (materials == null) {
             InitializeMaterials();
         }
         gameObject.AddComponent<MeshFilter>().mesh = meshes[Random.Range(0, meshes.Length)];
         gameObject.AddComponent<MeshRenderer>().material = materials[depth, Random.Range(0, 2)];
         if (depth < maxDepth) {
             StartCoroutine(CreateChildren());
         }
     }
 
     private static Vector3[] childDirections =
     {
         Vector3.up,
         Vector3.right,
         Vector3.left,
         Vector3.forward,
         Vector3.back
     };
     
     private static Quaternion[] childOrientations =
     {
         Quaternion.identity,
         Quaternion.Euler(0f, 0f, -90f),
         Quaternion.Euler(0f, 0f, 90f),
         Quaternion.Euler(90f, 0f, 0f),
         Quaternion.Euler(-90f, 0f, 0f)
     };
     
     private IEnumerator CreateChildren ()
     {
         for (int i = 0; i < childDirections.Length; i++)
         {
             if (Random.value < spawnProbability)
             {
                 yield return new WaitForSeconds(Random.Range(0.1f, 0.5f));
                 new GameObject("Fractal Child").AddComponent<Fractal>().Initialize(this, i);
             }
         }
     }
     
     private void Initialize (Fractal parent, int childIndex)
     {
         meshes = parent.meshes;
         materials = parent.materials;
         maxDepth = parent.maxDepth;
         depth = parent.depth + 1;
         childScale = parent.childScale;
         spawnProbability = parent.spawnProbability;
         maxRotationSpeed = parent.maxRotationSpeed;
         maxTwist = parent.maxTwist;
         transform.parent = parent.transform;
         transform.localScale = Vector3.one * childScale;
         transform.localPosition = childDirections[childIndex] * (0.5f + 0.5f * childScale);
         transform.localRotation = childOrientations[childIndex];
     }
 
     private void Update ()
     {
         transform.Rotate(0f, rotationSpeed * Time.deltaTime, 0f);
     }
 }

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I debug a Linux crash? 1 Answer

Generic Debug Message 1 Answer

How do I keep Debug.Log in archive/release iOS builds? 0 Answers

Android Debug USB 7 Answers

Debug.Log() remove callstack ? 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