Unityにて、ボタンを押してる間キャラの画像を切り替える
というものを作りたいんですがうまくいきません
コードはこのように書いてありました。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class player : MonoBehaviour {
[SerializeField]
float speed;
//移動ベクトル
public GameObject hensin;
Vector3 velocity;
// Use this for initialization
IEnumerator Start()
{
while (true)
{
if (Input.GetKey(KeyCode.SpaceArrow))
{
Instantiate(hensin, transform.position, transfrom.rotation);
}
}
}
// Update is called once per frame
void Update() {
Run();
}
//ベクトル向き初期化
void Run()
{
velocity = Vector3.zero;
//キー入力によりベクトルを加算
//左右移動
if(Input.GetKey(KeyCode.RightArrow))
{
velocity.x += -speed;
}
if(Input.GetKey(KeyCode.LeftArrow))
{
velocity.x += speed;
}
if(Input.GetKey(KeyCode.UpArrow))
{
velocity.y += -speed;
}
if(Input.GetKey(KeyCode.DownArrow))
{
velocity.y += speed;
}
transform.position -= velocity;
}
}
参考にしているソースです
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
// 移動スピード
public float speed = 5;
// PlayerBulletプレハブ public GameObject bullet; // Startメソッドをコルーチンとして呼び出す IEnumerator Start () { while (true) { // 弾をプレイヤーと同じ位置/角度で作成 Instantiate (bullet, transform.position, transform.rotation); // 0.05秒待つ yield return new WaitForSeconds (0.05f); } }
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/05/01 08:58
2017/05/01 14:19
2017/05/02 00:26 編集
2017/05/02 00:33
2017/05/02 01:38
2017/05/02 01:58
2017/05/05 10:23
2017/05/08 01:04 編集