我需要在游戏中添加触控,我不知道该怎么做。 在我的游戏时间尺度非常重要 我阅读了很多教程,但这不起作用。 我认为左半屏和半屏右边的东西 地图是道路,但我认为这并不重要。 请帮帮我。
这就是无限跑者的游戏。 我的脚本编写很少。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerBehaviour : MonoBehaviour {
public float death =0f;
public float timee;
public float points = 0f;
public float distance = 0f;
void Start ()
{
timee = Time.timeScale;
}
void Update ()
{
if (Input.GetKey(KeyCode.A) && transform.position.x <12.5f && transform.position.x >-2.5f)
{
GameObject.Find("player").transform.position -= new Vector3((Time.deltaTime * 3.5f )* timee ,0, 0);
}
if (Input.GetKey(KeyCode.D) && transform.position.x < 2.5f && transform.position.x > -12.5f)
{
GameObject.Find("player").transform.position += new Vector3((Time.deltaTime * 3.5f) * timee , 0, 0);
}
distance = distance + 15 * Time.deltaTime;
}
public float score;
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag == "siema")
{
if (score < 33)
{
score++;
Time.timeScale = 1f+ score * 0.03f;
timee = 1f - (0.04f * score);
if (timee < 0.5f && score <= 33)
{
timee = 0.5f;
}
if (score > 29)
{
timee = 0.4f;
}
}
}
if (col.gameObject.tag == "base")
{
points = points + score * score;
score = 0f;
}
if (score == 0)
{
Texture texture = Resources.Load<Texture> ("0");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
Time.timeScale = 1f;
timee = 1f;
}
if (score == 1) {
Texture texture = Resources.Load<Texture> ("1");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 2) {
Texture texture = Resources.Load<Texture> ("2");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 3) {
Texture texture = Resources.Load<Texture> ("3");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 4) {
Texture texture = Resources.Load<Texture> ("4");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 5) {
Texture texture = Resources.Load<Texture> ("5");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 6) {
Texture texture = Resources.Load<Texture> ("6");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 7) {
Texture texture = Resources.Load<Texture> ("7");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 8) {
Texture texture = Resources.Load<Texture> ("8");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 9) {
Texture texture = Resources.Load<Texture> ("9");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 10) {
Texture texture = Resources.Load<Texture> ("10");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 11) {
Texture texture = Resources.Load<Texture> ("11");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 12) {
Texture texture = Resources.Load<Texture> ("12");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 13) {
Texture texture = Resources.Load<Texture> ("13");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 14) {
Texture texture = Resources.Load<Texture> ("14");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 15) {
Texture texture = Resources.Load<Texture> ("15");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 16) {
Texture texture = Resources.Load<Texture> ("16");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 17) {
Texture texture = Resources.Load<Texture> ("17");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 18) {
Texture texture = Resources.Load<Texture> ("18");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 19) {
Texture texture = Resources.Load<Texture> ("19");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 20) {
Texture texture = Resources.Load<Texture> ("20");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 21) {
Texture texture = Resources.Load<Texture> ("21");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 22) {
Texture texture = Resources.Load<Texture> ("22");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 23) {
Texture texture = Resources.Load<Texture> ("23");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 24) {
Texture texture = Resources.Load<Texture> ("24");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 25) {
Texture texture = Resources.Load<Texture> ("25");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 26) {
Texture texture = Resources.Load<Texture> ("26");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 27) {
Texture texture = Resources.Load<Texture> ("27");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 28) {
Texture texture = Resources.Load<Texture> ("28");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 29) {
Texture texture = Resources.Load<Texture> ("29");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 30) {
Texture texture = Resources.Load<Texture> ("30");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 31) {
Texture texture = Resources.Load<Texture> ("31");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 32) {
Texture texture = Resources.Load<Texture> ("32");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (score == 33) {
Texture texture = Resources.Load<Texture> ("33");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
}
if (col.gameObject.tag == "siema")
{
Destroy (col.gameObject);
}
if (col.gameObject.tag == "blocade")
{
if (score > 0)
{
score = 0;
Texture texture = Resources.Load<Texture> ("0");
GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
Time.timeScale = 1f;
timee = 1f;
Destroy (col.gameObject);
}
death++;
Destroy (col.gameObject);
if (death == 2)
{
Time.timeScale = 0.0001f;
}
}
}
}
答案 0 :(得分:0)
如果你的意思是类似操纵杆,你可以从Unity标准资产添加它 - CrossPlatformInput - 预制 - 移动单杆控制