using UnityEngine;
using System.Collections;
public class SimpleShip : MonoBehaviour
{
public float speed; // 物件移動速度;
public int speed2; //發射物件數度;
public Rigidbody Projectile;
// Update is called once per frame
void Update ()
{
float abtToMove = Input.GetAxis ("Horizontal") * speed * Time.deltaTime; //輸入方向鍵及a,d 鍵 就水平移動
transform.Translate (Vector3.right * abtToMove); // 物件移動
if (transform.position.x >= 205.0f) // 假設物件移到調鍵x軸
transform.position = new Vector3 (-205.0f, transform.position.y, transform.position.y); // 物件 就重-x軸出現
else if (transform.position.x <= -205.0f) // 假設物件移到調鍵x軸
transform.position = new Vector3 (205.0f, transform.position.y, transform.position.y); // 物件 就重x軸出現
// 發射物件
if (Input.GetKeyDown ("space")) {
Rigidbody clone;
clone = (Rigidbody)Instantiate (Projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection(Vector3.up * speed2);
}
}
}
留言列表