プレーヤーを右方向に移動させる
強制横スクロール
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float gameSpeed = 1.0f;//ゲームのスピード
public float timeElapsed;
public float timeOut;
AudioSource audioSource;
public AudioClip ShotSE;
KabuGenerate kabuGenerate;
private void Start()
{
audioSource = GetComponent<AudioSource>();
kabuGenerate = FindObjectOfType<KabuGenerate>();
}
void Update()
{
if (gameSpeed == 0)
{
//右向きに等速で進む
this.transform.position += new Vector3(gameSpeed * Time.deltaTime, 0, 0);
}
else
{
//右向きに等速で進む
this.transform.position += new Vector3(gameSpeed * Time.deltaTime, 0, 0);
timeElapsed += Time.deltaTime;
if (timeElapsed >= timeOut)
{
timeElapsed = 0.0f;
//Debug.Log("");
gameSpeed += 0.2f;
kabuGenerate.timeleft -= 0.5f;//株の間隔を狭める
audioSource.PlayOneShot(ShotSE);
}
}
}
}