Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
สคริปต์ติดบัค ช่วยทีครับ
#1
ตามหัวข้อเลยนะครับ อันนี้ตัวสคริปต์ครับ

เป็นสคริปต์ไว้ดำน้ำครับ
Quote:var waterLevel : float;
var myParticles : ParticleSystem;
private var isUnderwater : boolean;
private var normalColor : Color;
private var underwaterColor : Color;
private var chMotor : CharacterMotor;


private var canSwim : boolean = false;
private var underGround : boolean = false;
var groundLevel : float;

function Start ()
{
normalColor = new Color (0.5f, 0.5f, 0.5f, 0.5f);
underwaterColor = new Color (0.22f, 0.65f, 0.77f, 0.5f);
chMotor = GetComponent(CharacterMotor);
myParticles.Stop(); // อันนี้เอฟเฟ็คตอนอยู่ใต้น้ำเฉยๆ
}

function Update ()
{
if ((transform.position.y < waterLevel) != isUnderwater)
{
isUnderwater = transform.position.y < waterLevel;
if (isUnderwater) SetUnderwater ();
if (!isUnderwater) SetNormal (); // ประมาณว่า ถ้าอยู่ต่ำกว่าระดับน้ำให้นับเป็นใต้น้ำ ครับ ถ้าอยู่ใต้น้ำก็ว่ายน้ำได้ประมาณเนี้ย
}


if(transform.position.y < groundLevel)
{
canSwim = true;
underGround = true;
}

else
{
underGround = false;
}

if(isUnderwater && canSwim == true && underGround == false && Input.GetKey(KeyCode.E)) // อันนี้ประมาณว่ากด e แล้วใช้ constance force
{
constantForce.relativeForce = Vector3(0,-200, 0);
}
else
{
constantForce.relativeForce = Vector3(0, 0, 0);
}

if(isUnderwater && canSwim == true && Input.GetKey(KeyCode.Q)) // เหมือนๆกับกด q แต่อันนี้ดำลงอันนั้นว่ายขึ้น
{
constantForce.relativeForce = Vector3(0, 200, 0);
}
}

function SetNormal ()
{
RenderSettings.fogColor = normalColor;
RenderSettings.fogDensity = 0.002f;
chMotor.movement.gravity = 20;
chMotor.movement.maxFallSpeed = 20;
chMotor.movement.maxForwardSpeed = 6;
chMotor.movement.maxSidewaysSpeed = 6;
myParticles.Stop();
canSwim = false;
}
// อันนั้คือ set normal ครับ ประมาณว่าอยู่บนบกแหละ
function SetUnderwater ()
{
RenderSettings.fogColor = underwaterColor;
RenderSettings.fogDensity = 0.3f;
chMotor.movement.gravity = 2;
chMotor.movement.maxFallSpeed = 5;
chMotor.movement.maxForwardSpeed = 4;
chMotor.movement.maxSidewaysSpeed = 4;
myParticles.Play();
}
// อันนี้คืออยู่ใต้น้ำ

แต่มันติดปัญหาที่ พอขึ้นบกแล้วมันไม่ยอมเปลี่ยนไปใช้ set normal แพนด้าจ๊าก

รบกวนด้วยนะครับ
Y me gusta muchoY me gusta muchoY me gusta muchoY me gusta muchoY me gusta muchoY me gusta mucho
Reply
#2
;3

งงอ่ะ มันคืออาราย แมวร้อง

ผมยังไม่เห็น groundLevel เลยครับ ว่ามีค่าเท่าไหร่ เห็นแต่ประกาศตัวแปรเฉยๆ

waterLevel ด้วยครับ หรือมันดึงค่ามาจากไหนยังไงครับ แมวร้อง
May the flames guide your way. Every ending will make you stronger.

Reply
#3
(04-07-2014, 10:42 AM)dreamknight Wrote: ;3

งงอ่ะ มันคืออาราย แมวร้อง

ผมยังไม่เห็น groundLevel เลยครับ ว่ามีค่าเท่าไหร่ เห็นแต่ประกาศตัวแปรเฉยๆ

waterLevel ด้วยครับ หรือมันดึงค่ามาจากไหนยังไงครับ แมวร้อง

ผมทำไว้เอาไว้ปรับใน unity เลยอ่ะครับ เพราะว่าเผ่ืิอความสูงน้ำเล่นๆปรับน้ำเล่นๆ
water level ก็คือ position y ของน้ำ
ground เป็น y ของพื้นครับ
Y me gusta muchoY me gusta muchoY me gusta muchoY me gusta muchoY me gusta muchoY me gusta mucho
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)