الان انتهيت من عمل اللعبة مع وجود بعض الملاحظات ولكن بشكل عام ارى انها مقبوله................
اهم مافي الموضوع هو الكود تحريك اللذي يعرضة السبرايت ويجعله يتحرك وهو اهم عنصر بالموضوع اتمنى ان يستخدم مستقبلا في عمل الالعاب 2D وسوفه اضعه لمن يرغب في استخدامه واي سؤال انا حاضر.............
اولا كود تحريك السبرايت
المصـــــــــــدر::: من النت بشكل غير مكتمل وتم التعديل عليه لساعات طويله
كود:
var uvAnimationTileX = 4;
var uvAnimationTileY = 0;
var framesPerSecond = 10.0;
function Update () {
if(Input.GetKey("down") || Input.GetKey("s")) {
// Calculate index
var index : int = Time.time * framesPerSecond;
// repeat when exhausting all frames
index = index % (uvAnimationTileX * uvAnimationTileY);
// Size of every tile
var size = Vector2 (-1.0 / uvAnimationTileX, -0.26 );
// split into horizontal and vertical index
var uIndex = index % uvAnimationTileX;
var vIndex = index / uvAnimationTileX;
// build offset
// v coordinate is the bottom of the image in opengl so we need to invert.
var offset = Vector2 (uIndex * size.x, 0);
renderer.material.SetTextureOffset ("_MainTex", offset);
renderer.material.SetTextureScale ("_MainTex", size);
}
if(Input.GetKey("up") || Input.GetKey("w")) {
// Calculate index
var index1 : int = Time.time * framesPerSecond;
// repeat when exhausting all frames
index1 = index1 % (uvAnimationTileX * uvAnimationTileY);
var size1 = Vector2 (-1.0 / uvAnimationTileX, -0.26 );
// split into horizontal and vertical index
var uIndex1 = index1 % uvAnimationTileX;
var vIndex1 = index1 / uvAnimationTileX;
// build offset
// v coordinate is the bottom of the image in opengl so we need to invert.
var offset1 = Vector2 (uIndex1 * size1.x, 0.25);
renderer.material.SetTextureOffset ("_MainTex", offset1);
renderer.material.SetTextureScale ("_MainTex", size1);
}
if(Input.GetKey("right") || Input.GetKey("a")) {
// Calculate index
var index2 : int = Time.time * framesPerSecond;
// repeat when exhausting all frames
index2 = index2 % (uvAnimationTileX * uvAnimationTileY);
var size2 = Vector2 (-1.0 / uvAnimationTileX, -0.26 );
// split into horizontal and vertical index
var uIndex2 = index2 % uvAnimationTileX;
var vIndex2 = index2 / uvAnimationTileX;
// build offset
// v coordinate is the bottom of the image in opengl so we need to invert.
var offset2 = Vector2 (uIndex2 * size2.x, 0.5);
renderer.material.SetTextureOffset ("_MainTex", offset2);
renderer.material.SetTextureScale ("_MainTex", size2);
}
if(Input.GetKey("left") || Input.GetKey("d")) {
// Calculate index
var index3 : int = Time.time * framesPerSecond;
// repeat when exhausting all frames
index3 = index3 % (uvAnimationTileX * uvAnimationTileY);
var size3 = Vector2 (-1.0 / uvAnimationTileX, -0.26 );
// split into horizontal and vertical index
var uIndex3 = index3 % uvAnimationTileX;
var vIndex3 = index3 / uvAnimationTileX;
// build offset
// v coordinate is the bottom of the image in opengl so we need to invert.
var offset3 = Vector2 (uIndex3 * size3.x, 0.75);
renderer.material.SetTextureOffset ("_MainTex", offset3);
renderer.material.SetTextureScale ("_MainTex", size3);
}
}
الحقيقه لا يوجد كود بالنت ولا بالمنتديات يتكلم عن تحريك السبرايت بهذي الطريقه حسب بحثي بالنت..........
كذلك اود القول اني لا اعلم ان كان بالامكان كتابة نفس الكود بطريقه اقل وبشكل مختصر...........
واخيرااااااااااااااااااااااا
رابط تحميل التجربه 2D IN 3D واتمنى ان تحوز على اعجابكم ولكم مطلق الحريه باستخدام اكواد المعروضه بالموضوع
شباب ابي اسمع ارائكم باللعبة وبهذي التجربه وتقبلووو تحياتي