- Home /
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
**/
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)
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.
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);
Your answer
Follow this Question
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