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 Jojo B · Feb 02, 2014 at 03:06 PM · c#loops

c# loops not working yet no erors

hi so ive just started learning c# and ime coming across a problem with loops where despite no erors coming up the loop dosent seem to be working if i put print in it dosent print anything out but if i put it before it dose i dont know whether its just something in c# ime un aware of but i never had this problem with Js anyway here my code its around line 40 where the problem is

using UnityEngine; using System.Collections; using System.Collections.Generic; public class MapGen : MonoBehaviour { public List<Chunk> Builders; // Create a texture and fill it with Perlin noise. // Try varying the xOrg, yOrg and scale values in the inspector // while in Play mode to see the effect they have on the noise. public int MapGenSize; // Width and height of the texture in pixels. public Transform ChunkPreFab; public int pixWidth; public int pixHeight; // The origin of the sampled area in the plane. public float xOrg; public float yOrg; // The number of cycles of the basic noise pattern that are repeated // over the width and height of the texture. public float scale = 1.0F; public Texture2D noiseTex; public Color[] pix; void Start () { // Set up the texture and a Color array to hold pixels during processing. xOrg = Random.Range(-10,10); yOrg = Random.Range(-10,10); noiseTex = new Texture2D(pixWidth, pixHeight); pix = new Color[noiseTex.width * noiseTex.height]; CreateChunks (); renderer.material.mainTexture = noiseTex; } public void CreateChunks (){ print("12"); for (int x = 0; x < MapGenSize; ++x) { // this is the part that isnt working for (int z = 0; z < MapGenSize; ++z) { print("123"); Transform clone = Instantiate(ChunkPreFab, new Vector3(x * 20, 0, z * 20), Quaternion.identity) as Transform; Builders.Add(clone.GetComponent<Chunk>()); clone.parent = transform; clone.GetComponent<Chunk>().GenScript = this; clone.GetComponent<Chunk>().BDataStore = transform.GetComponent<BlockData>(); } } CalcNoise(); } public void CalcNoise() { int y = 0; while (y < noiseTex.height) { int x = 0; while (x < noiseTex.width) { float xCoord = ((xOrg + x) / noiseTex.width) * scale; float yCoord = ((yOrg + y) / noiseTex.height) * scale; float sample = Mathf.PerlinNoise(xCoord, yCoord); pix[y * noiseTex.width + x] = new Color(sample, 0, 0); x++; } y++; } noiseTex.SetPixels(pix); noiseTex.Apply(); // Copy the pixel data to the texture and load it into the GPU. MakeMountains(); }

i thought it might be something to do with using the variables x and y multiple times in each class any help would be much aprechated

Comment
Add comment · Show 7
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 jg2115 · Feb 02, 2014 at 03:12 PM 0
Share

I thought it was x++, not ++x? can you use either?

avatar image KellyThomas · Feb 02, 2014 at 03:24 PM 0
Share

I would print the value of $$anonymous$$apGenSize before the loop, double check it is not zero.

@jg2115 both forms work here, but behavior varies subtly.

avatar image Jojo B · Feb 02, 2014 at 03:36 PM 0
Share

ye that seems to be it dont know why though its set as 10 in the inspector and theres no point at witch i change it

avatar image KellyThomas · Feb 02, 2014 at 03:43 PM 0
Share

It's public, is another script messing with it's value?

avatar image Jojo B · Feb 02, 2014 at 03:54 PM 0
Share

nope theres litraly just the decleration and the 2 loops it shouldent be changing atall its just being weird

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by KellyThomas · Feb 02, 2014 at 04:24 PM

OK if the value is different from what the inspector is showing try commenting out it's declaration.

This should achieve two things:

  1. It will generate compiler errors for every line that accesses the variable.

  2. clear the serialised value in the inspector, the when you uncommented the declaration it will start "fresh".

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

20 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

loop through a renderer 1 Answer

Renderer on object disabled after level reload 1 Answer

Illuminating a 3D object's edges OnMouseOver (script in c#)? 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