Google Cardboard Magnet Refresh在Unity中不起作用

时间:2014-12-02 02:25:15

标签: unity3d unityscript

我的谷歌纸板磁铁需要帮助。我创造了一个球类游戏,我想要它,这样当你拉动磁铁时,球就会跳起来。第一轮,我的磁铁工作正常,但是当我重新启动水平时(通过跌落),磁铁不再工作了。我使用了一个名为MagnetSensor.cs(https://github.com/theqwertman/UnityCardboardTrigger/blob/develop/MagnetSensor.cs)的脚本。这是我的控球脚本。如果可以,请帮助我。在团结论坛中粘贴代码时,也尝试帮助我格式化代码;我不知道该怎么做。这就是我的代码混乱的原因:

var rotationSpeed = 100;
var jumpHeight = 8;

var Hit01 : AudioClip;
var Hit02 : AudioClip;
var Hit03 : AudioClip;
var distToGround : float;

function Start () { distToGround = collider.bounds.extents.y; }

function Update () {
    var rotation : float = rotationSpeed;
    rotation = Time.deltaTime;
    rigidbody.AddRelativeTorque (Vector3.back rotation);
    MagnetSensor.OnMagnetPull += JumpOnMagnet;
}

function IsGrounded () : boolean {
    return Physics.Raycast(transform.position, -Vector3.up, distToGround + 0.1);
}

function JumpOnMagnet () { rigidbody.velocity.y = jumpHeight; }

function OnCollisionEnter () {
    var theHit = Random.Range(0, 3);
    if (theHit == 0) { audio.clip = Hit01; }
    else if (theHit == 1) { audio.clip = Hit02; }
    else { audio.clip = Hit03; }
    audio.pitch = Random.Range (0.9,1.1);
    audio.Play();
}

0 个答案:

没有答案