Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 kastorsak · Jan 02, 2020 at 12:42 PM · errorlistvector2

I need help on adding vector2 to a lest and the exstecting it Look in the wright and read fucshins,how do i put a vector 2 in a list and exstrat for if statmes

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class depth_gen : MonoBehaviour
 {
     public GameObject dirt;
     public GameObject IronOre;
     public GameObject Stone;
     public Transform Player;
     private int RanInt;
     private float X = 0f;
     private float Y = 0f;
     private float Z = 0f;
     private int Stage = 0;
     private int RanOre = 0;
     private float id = 0f;
     private int LoaddedCount = 0;
     private Vector3 SpanPos;
     private Vector2 BlockInfo;
     private float Level;
     private List<Vector4> Blocks = new List<Vector4>();
     
     // Start is called before the first frame update
     private float yfinder = 0f;
     void Start()
     {
         
         X = this.transform.position.x;
         Y = this.transform.position.y;
         Stage = 1;
     }
 
     // Update is called once per frame
     void Update()
     {  
         if ((Player.position.x - X) < 10 && (Player.position.x - X) > -10) {// && (Player.position.y - Y) < 6 && (Player.position.y - Y) > -6
             if (Stage >= 1 && Stage <= 5) {//this is dirt
                 Y = Y - 0.48f;
                 SpanPos.Set(X,Y,Z);
                 Instantiate(dirt, SpanPos, this.transform.rotation);
                 Stage = Stage + 1;
                 id = 1f;
                 Read();
             }
             if (Stage >= 6 && Stage <= 100) {
                 RanOre = Random.Range(1,231);
                 if (RanOre <= 3) {//this is iron
                     Y = Y - 0.48f;
                     SpanPos.Set(X,Y,Z);
                     Instantiate(IronOre, SpanPos, this.transform.rotation);
                     Stage = Stage + 1;
                     id = 3f;
                     Read();
                 } else {//this is stone
                     Y = Y - 0.48f;
                     SpanPos.Set(X,Y,Z);
                     Instantiate(Stone, SpanPos, this.transform.rotation);
                     Stage = Stage + 1;
                     id = 2f;
                     Read();
                 }
 
             }
         }
         if ((Player.position.x - this.transform.position.x) > 10 || (Player.position.x - this.transform.position.x) < -10) {// && (Player.position.y - this.transform.position.y) > 6 || (Player.position.y - this.transform.position.y) < -6
             //off
             LoaddedCount = LoaddedCount + 1;
         }
         if ((Player.position.x - this.transform.position.x) < 10 && (Player.position.x - this.transform.position.x) > -10) {// && (Player.position.y - this.transform.position.y) < 6 && (Player.position.y - this.transform.position.y) > -6
             //on
             LoaddedCount = LoaddedCount + 1;
         }
         if (LoaddedCount >= 3) {
             LoaddedCount = 0;
             yfinder = transform.position.y;
             Wright();
         }
     }
     void Read() {
         Level = Y / 0.48f;
         yfinder = 0.48f;
         BlockInfo = new Vector2(Y,id);
         Blocks.Add(new BlockInfo);
     }
     void Wright() {
         foreach(Vector2 blockInfo in Blocks) {
             if (blockInfo.Y == yfinder) {
                 if (blockInfo.id == 3) {//this is iron
                     SpanPos.Set(X,yfinder,Z);
                     Instantiate(IronOre, SpanPos, this.transform.rotation);
                     yfinder = yfinder - 0.48f;
                 }
             }
         }
 
     }
 }
 /**
 Id List
 Id | Block
 1:Dirt // Grass is not 1 becuse it will not be stored
 2:Stone
 3:Iron
 **/
 
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 kastorsak · Dec 30, 2019 at 07:28 PM 0
Share

look in read and wright funshins

avatar image kastorsak · Dec 30, 2019 at 07:29 PM 0
Share

i mean list

avatar image kastorsak · Dec 30, 2019 at 07:30 PM 0
Share

this is the proble: The type or namespace name 'BlockInfo' could not be found (are you missing a using directive or an assembly reference?) [Assembly-CSharp]csharp(CS0246)

avatar image PrimeSoul · Jan 02, 2020 at 04:07 PM 0
Share

This code does not have proper syntax, you are tackling a problem that is out of your level. I suggest starting with the basics of C# and program$$anonymous$$g principles. Especially how to use Types and Lists.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by PrimeSoul · Jan 02, 2020 at 03:51 PM

Your Blocks list is a Vector4 and your blockinfo is a Vector2, You can't do that.

Change:

 private List<Vector4> Blocks = new List<Vector4>();

To:

 private List<Vector2> Blocks = new List<Vector2>();

Also, You need to refer to the x and y values of the vector2.

Change:

 if (blockInfo.Y == yfinder) {
                  if (blockInfo.id == 3) {//this is iron
                      SpanPos.Set(X,yfinder,Z);
                      Instantiate(IronOre, SpanPos, this.transform.rotation);
                      yfinder = yfinder - 0.48f;
                  }
              }

To:

 if (blockInfo.x == yfinder) {
                  if (blockInfo.y == 3) {//this is iron
                      SpanPos.Set(X,yfinder,Z);
                      Instantiate(IronOre, SpanPos, this.transform.rotation);
                      yfinder = yfinder - 0.48f;
                  }
              }

Also, You do not need a "new Blockinfo" since you have just assigned it. Change:

 Blocks.Add(new BlockInfo);

To:

   Blocks.Add(BlockInfo);
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

154 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 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 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 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 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 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 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 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

A node in a childnode? 1 Answer

The generic list blues (Argument out of range error) 1 Answer

How to make an IList of a certain type? 2 Answers

Cannot implicitly convert type string to list - Why is this? 1 Answer

Im getting this error CS0246 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