收藏
回答

这组代码,我在自己手机上能够直接跑的通的,可是上传到开发者工具上就跑不通了?求大神帮忙看一眼

void Start()

{

duck = transform.GetChild(0);

}

void Update()

{

Vector3 dir = Vector3.forward;

dir.z = -Input.acceleration.x* speed;

//rotatePos.text = Input.acceleration.ToString();//测试手机重力感应值

//transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(dir),

0.05f);//重力控制挡板角度

duck.localPosition -= new Vector3(transform.rotation.z*0.8f, 0, 0);//鸭子随挡板的转

动而滑动

}

}

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

/// <summary>

///

/// </summary>

public class DestroyObject : MonoBehaviour

{

public void OnTriggerEnter2D(Collider2D collision)

{

if((collision.tag == "Border"|| collision.tag == "Duck" )&&gameObject.tag!="Pipe")

{

Destroy(gameObject);

}

if(gameObject.tag == "Pipe"&& collision.tag == "Border")

{

Destroy(gameObject);

}

}

}using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;

/// <summary>

///

/// </summary>

public class DuckController : MonoBehaviour

{

private int speed = 100;

public Transform[] baffle;//挡板数组

private Transform currentBaffle;//当前挡板

public int grade = 0;

public Text gradeText;

private float gradeTime = 0f;//得分计时

private float starTime = 0f;

private bool isStar = false;//判断是否为星星 Buff

private float mushRoomTime = 0f;

private bool isMushroom = false;

public bool isGoldPipe = false;

private float goldTime = 0f;

private float paperTime = 0f;//定身符计时

private bool isPaper = false;

public Transform canvas;

private Transform overPanel;

private AudioSource duckAudio;

public AudioClip[] audioClips;//各种音效

void Start()

{

currentBaffle = transform.parent;

overPanel = canvas.GetComponent<UIContronller>().overPanel;

duckAudio = transform.GetComponent<AudioSource>();

}

// Update is called once per frame

void Update()

{

Move();//控制鸭子和挡板的运动UpdateGrade();//更新分数

BuffTime();//Buff 时间计算

}

private void Move()

{

Vector3 dir = Vector3.forward;

dir.z = -Input.acceleration.x * speed;

//dir.z = -Input.GetAxis("Horizontal") * 10;//按键测试

currentBaffle.rotation = Quaternion.Lerp(currentBaffle.rotation,

Quaternion.Euler(dir), 0.05f);//重力控制挡板角度

if (!isPaper)

{

transform.localPosition -= new Vector3(currentBaffle.rotation.z * 0.4f, 0, 0);//

鸭子随挡板的转动而滑动

}

}

private void UpdateGrade()

{

gradeTime += Time.deltaTime;

if (gradeTime > 1)

{

grade += 1;

gradeTime = 0f;

gradeText.text = "分数:" + grade;

}

}

private void BuffTime()

{

if (isMushroom)

{

mushRoomTime += Time.deltaTime;

}

if (mushRoomTime > 10)

{

mushRoomTime = 0f;

isMushroom = false;

baffle[0].gameObject.SetActive(true);//恢复为正常挡板

transform.SetParent(baffle[0]);currentBaffle.gameObject.SetActive(false);

currentBaffle = baffle[0];//更新当前挡板

回答关注问题邀请回答
收藏

1 个回答

  • Demons
    Demons
    2023-07-21

    报什么错

    2023-07-21
    有用
    回复
登录 后发表内容