Hello all,
i am back again with a small and quick issue.
i am creating a game,where i need to convert my material(instance) type into material type.
any thing can be very much helpful for me.
Thanks in advance!
Niki.j
Hello all,
i am back again with a small and quick issue.
i am creating a game,where i need to convert my material(instance) type into material type.
any thing can be very much helpful for me.
Thanks in advance!
Niki.j
Hello All,
i have done with it by changing the color of material rather then the material itself,
but now when i run my game it works, but it works with some random behavior.some times it changes the colors of materials for all the required objects,but sometimes it will not
any help will be very much appreciated.
private var square : GameObject[ ];
var prefab : GameObject;
var blue_Tex : GUITexture;
var cyan_Tex : GUITexture;
var magenta_Tex : GUITexture;
var red_Tex : GUITexture;
var green_Tex : GUITexture;
var yellow_Tex : GUITexture;
var turns : GUIText;
private var prev_Mat : Material;
private var curr_Mat : Material;
private var swap_Mat : Material;
var mat : Material[ ];
var pos : Vector3[ ];
private var mouse_Pos : Vector2;
private var rand : int;
private var count : int = 0;
private var color : int[,];
private var sw : float;
private var sh : float;
var text_Font : GUIStyle;
private var top : boolean;
private var bottom : boolean;
private var left : boolean;
private var right : boolean;
private var reached : boolean[ ];
private var right_stop : boolean = false;
private var bottom_stop : boolean= false;
private var top_Stop : boolean = true;
private var left_Stop : boolean = true;
private var x : int;
function Start ()
{
square = new GameObject[196];
pos = new Vector3[196];
pos[0] = prefab.transform.position;
color = new int[14,14];
reached = new boolean[196];
for(var i : int = 0; i < 14; i++)
{
for(var j : int = 0; j < 14; j++)
{
rand = Random.Range(0,6);
pos[14i+j].x = pos[0].x + prefab.transform.localScale.x * j * 10;
pos[14i+j].y = pos[0].y - prefab.transform.localScale.y * i * 10 ;
pos[14i+j].z = pos[0].z;
square[14i+j] = Instantiate(prefab,pos[14i+j],Quaternion.Euler(new Vector3(270,0,0))) as GameObject;
square[14i+j].renderer.material = mat[rand];
color[i,j] = rand;
square[14i+j].name = “Square[”+ (14i+j) +“]”;
}
}
sw = Screen.width;
sh = Screen.height;
prev_Mat = mat[0];
curr_Mat = mat[0];
}
//check the color choosed by player and call function to process the color
function Update ()
{
turns.text = “Turn : " +count + " / 25”;
if(count < 25)
{
if(blue_Tex.HitTest(Input.mousePosition) Input.GetMouseButtonDown(0))
{
count++;
square[0].renderer.material = mat[0];
swap_Mat = curr_Mat;
curr_Mat = mat[0];
process_Color(0,0);
}
else if(red_Tex.HitTest(Input.mousePosition) Input.GetMouseButtonDown(0))
{
count++;
square[0].renderer.material = mat[1];
swap_Mat = curr_Mat;
curr_Mat = mat[1];
process_Color(1,0);
}
else if(magenta_Tex.HitTest(Input.mousePosition) Input.GetMouseButtonDown(0))
{
count++;
square[0].renderer.material = mat[2];
swap_Mat = curr_Mat;
curr_Mat = mat[2];
process_Color(2,0);
}
else if(yellow_Tex.HitTest(Input.mousePosition) Input.GetMouseButtonDown(0))
{
count++;
square[0].renderer.material = mat[3];
swap_Mat = curr_Mat;
curr_Mat = mat[3];
process_Color(3,0);
}
else if(green_Tex.HitTest(Input.mousePosition) Input.GetMouseButtonDown(0))
{
count++;
square[0].renderer.material = mat[4];
swap_Mat = curr_Mat;
curr_Mat = mat[4];
process_Color(4,0);
}
else if(cyan_Tex.HitTest(Input.mousePosition) Input.GetMouseButtonDown(0))
{
count++;
square[0].renderer.material = mat[5];
swap_Mat = curr_Mat;
curr_Mat = mat[5];
process_Color(5,0);
}
}
else
Time.timeScale = 0;
}
function FixedUpdate()
{
Debug.Log(“”);
}
//creates new game button and loosing text after completing 25 turns
function OnGUI()
{
if(GUI.Button(Rect(20,10,80,30),“New Game”))
{
Application.LoadLevel(Application.loadedLevel);
}
if(count >= 25)
{
GUI.Label(Rect(sw/3,sh/2.5,sw/1.5,sh/2),“You Lose”,text_Font);
}
}
//process color and apply the same on next object
function process_Color(c : int, obj : int)
{
prev_Mat = swap_Mat;
x = obj;
try{
if(square[x-14].renderer.material.color == curr_Mat.color || square[x-14].renderer.material.color == prev_Mat.color)
{
square[×].renderer.material = curr_Mat;
//Debug.Log("1st try block → square[×] = " + x);
process_Color(c,x-14);
}
}catch (e){}
try{
if(square[x-1].renderer.material.color == curr_Mat.color || square[x-1].renderer.material.color == prev_Mat.color)
{
square[×].renderer.material = curr_Mat;
//Debug.Log("2nd try block → square[×] = " + x);
process_Color(c,x-1);
}
}catch (e){}
try{
if(square[x+1].renderer.material.color == curr_Mat.color || square[x+1].renderer.material.color == prev_Mat.color)
{
square[×].renderer.material = curr_Mat;
//Debug.Log("3rd try block → square[×] = " + x);
process_Color(c,x+1);
}
}catch (e){}
try{
if(square[x+14].renderer.material.color == curr_Mat.color || square[x+14].renderer.material.color == prev_Mat.color)
{
square[×].renderer.material = curr_Mat;
//Debug.Log("4th try block → square[×] = " + x);
process_Color(c,x+14);
}
}catch (e){}
}
========================================================================
Thanks in Advance!
Niki.j
1193547–47173–$ColorManager.js (4.58 KB)