i have 23 public vector3’s
public Vector3 vertice0 = new Vector3(-1,1,1);
public Vector3 vertice1 = new Vector3(1,1,1);
public Vector3 vertice2 = new Vector3(-1,-1,1);
public Vector3 vertice3 = new Vector3(1,-1,1);
//back face
public Vector3 vertice4 = new Vector3(1,1,-1);
public Vector3 vertice5 = new Vector3(-1,1,-1);
public Vector3 vertice6 = new Vector3(1,-1,-1);
public Vector3 vertice7 = new Vector3(-1,-1,-1);
//left face
public Vector3 vertice8 = new Vector3(-1,1,-1);
public Vector3 vertice9 = new Vector3(-1,1,1);
public Vector3 vertice10 = new Vector3(-1,-1,-1);
public Vector3 vertice11 = new Vector3(-1,-1,1);
//right face
public Vector3 vertice12 = new Vector3(1,1,1);
public Vector3 vertice13 = new Vector3(1,1,-1);
public Vector3 vertice14 = new Vector3(1,-1,1);
public Vector3 vertice15 = new Vector3(1,-1,-1);
//top face
public Vector3 vertice16 = new Vector3(-1,1,-1);
public Vector3 vertice17 = new Vector3(1,1,-1);
public Vector3 vertice18 = new Vector3(-1,1,1);
public Vector3 vertice19 = new Vector3(1,1,1);
//bottom face
public Vector3 vertice20 = new Vector3(-1,-1,1);
public Vector3 vertice21 = new Vector3(1,-1,1);
public Vector3 vertice22 = new Vector3(-1,-1,-1);
public Vector3 vertice23 = new Vector3(1,-1,-1);
i tried turning it into a separate class but my array that utilizes the vertice0, vertice1 etc… could not acquire the vector3’s. i than tried {get ; set;} on the tail end but i received an error of unexpected symbol";" for the first three public variables. so now I’m thinking that since i want to access these variables in multiple scripts that i should place them in a separate resource file. my goal is i have a gameFuntionality script which loads my UI which are gameobjects in the game to display the menus and buttons etc… one of those buttons im trying to connect to my meshbuilder script so when it clicks it spawns the cube.
atm i don’t have the game objects i just have two buttons. one of those buttons was to test my lvling up
the other is to spawn the cube. as you can see i have no pointers or loading of meshbuilder .cs thats becuase no mater which way i did it making a game prefab with my script and instantiating it or trying to do a call meshbuilder cubeBuild = new meshbuilder; cubeBuild.CubeMe(); or doing a resource load for the file in awake still resulted in null results some most of the time i would get “null exception reference” . nothing occurred when i clicked the button. this is the main reference ive been going back to though when i use it i dont get any errors in vim but in unity i get the null reference exception to line 69 of gameFunctionality.cs i have tried another method of removing monobehavior but than the whole script breaks.
meshbuilder.cs
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(MeshRenderer))]
[RequireComponent(typeof(MeshFilter))]
public class meshbuilder : MonoBehaviour
{
//GameObject Cube = new GameObject();
//public Material Red = Resources.Load("Red",typeof(Material)) as Material;
//front face
public Vector3 vertice0 = new Vector3(-1,1,1); //Left Top Front vertice 0 lft 0
public Vector3 vertice1 = new Vector3(1,1,1); //right top front vertice 1 rtf 1
public Vector3 vertice2 = new Vector3(-1,-1,1); //left bottom front vertice 2 lbmf 2
public Vector3 vertice3 = new Vector3(1,-1,1); //right bottom front vertice 3 rbmf 3
//back face
public Vector3 vertice4 = new Vector3(1,1,-1); //right top back vertice 4 rtb 4
public Vector3 vertice5 = new Vector3(-1,1,-1); //left top back vertice 5 ltb 5
public Vector3 vertice6 = new Vector3(1,-1,-1); //right bottom back vertice 6 rbmb 6
public Vector3 vertice7 = new Vector3(-1,-1,-1); //left bottom back vertice 7 lbmb 7
//left face
public Vector3 vertice8 = new Vector3(-1,1,-1);//left top back vertice 8 ltb 5
public Vector3 vertice9 = new Vector3(-1,1,1);//left top front vertice 9 lft 0
public Vector3 vertice10 = new Vector3(-1,-1,-1);//left bottom back vertice 10 lbmb7
public Vector3 vertice11 = new Vector3(-1,-1,1);//left bottom front vertice 11 lbmf
//right face
public Vector3 vertice12 = new Vector3(1,1,1);//right top front vertice 12 rtf
public Vector3 vertice13 = new Vector3(1,1,-1);//right top back vertice 13 rtb
public Vector3 vertice14 = new Vector3(1,-1,1);//right bottom front vertice 14 rbmf
public Vector3 vertice15 = new Vector3(1,-1,-1);//right bottom back vertice 15 rbmb
//top face
public Vector3 vertice16 = new Vector3(-1,1,-1);//left top back vertice 16 ltb
public Vector3 vertice17 = new Vector3(1,1,-1);//right top back vertice 17 rtb
public Vector3 vertice18 = new Vector3(-1,1,1);//left top front vertice 18 lft
public Vector3 vertice19 = new Vector3(1,1,1);//right top front vertice 19 rtf
//bottom face
public Vector3 vertice20 = new Vector3(-1,-1,1);//left bottom front vertice 20 lbmf
public Vector3 vertice21 = new Vector3(1,-1,1);//right bottom front vertice 21 rbmf
public Vector3 vertice22 = new Vector3(-1,-1,-1);//left bottom back vertice 22 lbmb
public Vector3 vertice23 = new Vector3(1,-1,-1);//right bottom back vertice 23 rbmb
// mesh building properties
public void CubeMe()
{
MeshFilter Filtration = GetComponent<MeshFilter>();
Mesh CubeMorph = Filtration.mesh;
GetComponent<MeshRenderer>().material = Resources.Load("Red",typeof(Material)) as Material;
//VerticesArray
Vector3[] VertArray = new Vector3[]
{
//Front Face
vertice0,//0
vertice1,//1
vertice2,//2
vertice3,//3
//back face
vertice4,//4
vertice5,//5
vertice6,//6
vertice7,//7
//left face
vertice8,//8
vertice9,//9
vertice10,//10
vertice11,//11
//right face
vertice12,//12
vertice13,//13
vertice14,//14
vertice15,//15
//top face
vertice16,//16
vertice17,//17
vertice18,//18
vertice19,//19
//bottom face
vertice20,//20
vertice21,//21
vertice22,//22
vertice23//23
};
//triangles array clockwise points equals visablity
int[] triArray = new int[]
{
//front face
0,2,3,
3,1,0,
//back face
4,6,7,
7,5,4,
//left face
8,10,11,
11,9,8,
//right face
12,14,15,
15,13,12,
//top face
16,18,19,
19,17,16 ,
//bottom face
20,22,23,
23,21,20
};
//uvs
Vector2[] uvs = new Vector2[]
{
//front face
new Vector2(0,1),
new Vector2(0,0),
new Vector2(1,1),
new Vector2(1,0),
//back face
new Vector2(0,1),
new Vector2(0,0),
new Vector2(1,1),
new Vector2(1,0),
//left face
new Vector2(0,1),
new Vector2(0,0),
new Vector2(1,1),
new Vector2(1,0),
//right face
new Vector2(0,1),
new Vector2(0,0),
new Vector2(1,1),
new Vector2(1,0),
//top face
new Vector2(0,1),
new Vector2(0,0),
new Vector2(1,1),
new Vector2(1,0),
//bottom face
new Vector2(0,1),
new Vector2(0,0),
new Vector2(1,1),
new Vector2(1,0)
};
CubeMorph.Clear();
CubeMorph.vertices = VertArray;
CubeMorph.triangles = triArray;
CubeMorph.uv = uvs;
CubeMorph.Optimize();
CubeMorph.RecalculateNormals();
}
void awake ()
{
CubeMe ();
}
void start()
{
awake ();
}
// Update is called once per frame
void Update ()
{
start ();
}
gameFunctionality.cs
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Runtime;
using System;
using UnityEngine.UI;
using UnityEngine.EventSystems;
[RequireComponent()]
public class gameFunctionality : MonoBehaviour
{
public float Xp = 0f; // experience points used in lvl up, enemy and player scripts, items
public float XpToNxtLvl = 0f; // player and item equation to determin amount of points required for lvling up
public float Health = 100f; // a stat for the player
public float StatPoints = 0f; // number of points to allocate into stats for items and player
public float Level = 1f; // current lvl of item or character
public Texture2D button; // texture of a button
//onclick event for button
public void OnMouseDown()
{
Xp += 1000000000;
print("+10Xp");
}
//onclickRelease event for button
public void OnMouseUp()
{
XpGain ();
if(Xp >= XpToNxtLvl)
{
print("Level Up!");
}
}
//function to acquire meshbuilder script
void build ()
{
}
// not sure if this is needed but possible use in future probaly could just combine it with nxtLvl function
void XpGain()
{
if( Xp >= XpToNxtLvl)
{
NextLvl();
}
}
//acquiring xp
void XpToLvl()
{
XpToNxtLvl = ((1+Mathf.Pow(Mathf.Sqrt(5f),Level)) - (1f-(Mathf.Pow(Mathf.Sqrt(5f),Level)))) /(Mathf.Pow(2,Level)*Mathf.Sqrt(5f));
}
// LevelUP!
void NextLvl()
{
Xp -= Xp;
Health += 50;
StatPoints += 10;
Level += 1;
}
// Button and other user interface things
void OnGUI()
{
if(GUI.Button(new Rect(0,0,100,20),"Cube Me!"))
{
CubeMe ();
}
if (GUI.Button (new Rect (10, 70, 100, 20), "Click"))
{
OnMouseDown ();
OnMouseUp ();
}
}
//intializes before start
public void awake()
{
}
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
XpToLvl();
}
}