• 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 Blogan · Aug 27, 2016 at 06:54 AM · scripting problem

cloud generation not working

I get these problems when I try to save my script: Assets/GenerateLandscape.cs(60,52): error CS1061: Type int' does not contain a definition for width' and no extension method width' of type int' could be found (are you missing a using directive or an assembly reference?) , Assets/GenerateLandscape.cs(60,43): error CS1501: No overload for method Range' takes 1' arguments , Assets/GenerateLandscape.cs(61,52): error CS1061: Type int' does not contain a definition for depth' and no extension method depth' of type int' could be found (are you missing a using directive or an assembly reference?) , Assets/GenerateLandscape.cs(61,43): error CS1501: No overload for method Range' takes 1' arguments. here is my code. using UnityEngine; using System.Collections;

public class Block { public int type; public bool vis;

 public Block (int t, bool v)
 {
     type = t;
     vis = v;
 }

}

public class GenerateLandscape : MonoBehaviour {

 public static int width = 128;
 public static int depth = 128;
 public static int height = 128;
 public int heightScale = 20;
 public float detailScale = 25.0f;

 public GameObject grassBlock;
 public GameObject sandBlock;
 public GameObject snowBlock;
 public GameObject cloudBlock;

 Block[,,] worldBlocks = new Block[width,height,depth];

 // Use this for initialization
 void Start ()
 {
     int seed = (int)Network.time * 10;
     for (int z = 0; z < depth; z++) 
     {
         for (int x = 0; x < width; x++) 
         {
             int y = (int) (Mathf.PerlinNoise((x+seed)/detailScale, (z+seed)/detailScale) * heightScale);
             Vector3 blockPos = new Vector3(x,y,z);

             CreateBlock(y, blockPos, true);
             while(y > 0)
             {
                 y--;
                 blockPos = new Vector3(x,y,z);
                 CreateBlock(y, blockPos, false);
             }
     
         }
     }
 
     DrawClouds (20, 100);
 }

 void DrawClouds(int numClouds, int cSize)
 {
     for (int i = 0; i < numClouds; i++) 
     {
         int xpos = Random.Range (0.width);
         int zpos = Random.Range (0.depth);
         for (int j = 0; j < cSize; j++) 
         {
             Vector3 blockPos = new Vector3 (xpos, height-1, zpos);
             Instantiate (cloudBlock, blockPos, Quaternion.identity);
             worldBlocks [(int)blockPos.x, (int)blockPos.y, (int)blockPos.z] = new Block (4, true);
             xpos += Random.Range (-1, 2);
             zpos += Random.Range (-1, 2);
             if (xpos < 0 || xpos >= width) xpos = width / 2;
             if (zpos < 0 || zpos >= depth) zpos = depth / 2;
         }
     }
 }

 void CreateBlock(int y, Vector3 blockPos, bool create)
 {

     if(y > 15) 
     {
         if(create)    
             Instantiate (snowBlock,blockPos, Quaternion.identity);

         worldBlocks[(int)blockPos.x,(int)blockPos.y,(int)blockPos.z] = new Block(1, create);
     } 
     else if(y > 5) 
     {
         if(create)
             Instantiate (grassBlock,blockPos, Quaternion.identity);

         worldBlocks[(int)blockPos.x,(int)blockPos.y,(int)blockPos.z] = new Block(2, create);
     } 
     else 
     {
         if(create)
             Instantiate (sandBlock,blockPos, Quaternion.identity);

         worldBlocks[(int)blockPos.x,(int)blockPos.y,(int)blockPos.z] = new Block(3, create);
     }    

 }

 void DrawBlock(Vector3 blockPos)
 {
     if (worldBlocks[(int)blockPos.x,(int)blockPos.y,(int)blockPos.z] == null) return;

     if (!worldBlocks[(int)blockPos.x,(int)blockPos.y,(int)blockPos.z].vis) 
     {

         worldBlocks[(int)blockPos.x,(int)blockPos.y,(int)blockPos.z].vis = true;
         if (worldBlocks[(int)blockPos.x,(int)blockPos.y,(int)blockPos.z].type == 1)
             Instantiate (snowBlock, blockPos, Quaternion.identity);
         
         else if (worldBlocks[(int)blockPos.x,(int)blockPos.y,(int)blockPos.z].type == 2)
             Instantiate (grassBlock, blockPos, Quaternion.identity);
         
         else if (worldBlocks [(int)blockPos.x, (int)blockPos.y, (int)blockPos.z].type == 3)
             Instantiate (sandBlock, blockPos, Quaternion.identity);
         else
             worldBlocks [(int)blockPos.x, (int)blockPos.y, (int)blockPos.z].vis = false;
     }

 }
 
     // Update is called once per frame
 void Update () 
 {
     if(Input.GetMouseButtonDown(0))
     {
         RaycastHit hit;
         Ray ray = Camera.main.ScreenPointToRay (new Vector3 (Screen.width / 2.0f, Screen.height / 2.0f, 0));
         if (Physics.Raycast (ray, out hit, 1000.0f)) 
         {
             Vector3 blockPos = hit.transform.position;

             //this is the bottom block. Don't delete it.
             if((int)blockPos.y == 0) return;

             worldBlocks [(int)blockPos.x, (int)blockPos.y, (int)blockPos.z] = null;

             Destroy (hit.transform.gameObject);

             for(int x = -1; x <= 1; x++)
                 for(int y = -1; y <= 1; y++)
                     for(int z = -1; z <= 1; z++) 
                     {
                         if(!(x == 0 && y == 0 && z == 0))
                         {    
                             Vector3 neighbour = new Vector3(blockPos.x+x, blockPos.y+y, blockPos.z+z);
                             DrawBlock(neighbour);
                         }
                     }
         }
     }

 
 }

}

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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Network Instantiate WITHOUT inspector? 0 Answers

Adding constraint component at runtime 1 Answer

Appear a text at start in the center of the screen 1 Answer

Why my editor vs code opens a few windows when i try to open a script from unity,My VS Code open a few tables when i double click a script in Unity? 0 Answers

Trying to make an object "Flee" from the player but it won't work? 3 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