Harigami
ログイン
anonymous タイトルなし
No License C#
コピー
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
	class BulletType
	{
		public enum Types
		{
			Small,
			TwoWay,
			Length
		}

		public GameObject Prefab;
		public Vector2 minOffset;
		public Vector2 maxOffset;

		public BulletType(GameObject prefab, float minOffsetX, float maxOffsetX, float minOffsetY, float maxOffsetY)
		{
			this.Prefab = prefab;
			this.minOffset = new Vector2(minOffsetX, minOffsetY);
			this.maxOffset = new Vector2(maxOffsetX, maxOffsetY);
		}
	}
	BulletType[] BulletTypes;
	BulletType CurrentBulletType;

	void Start()
	{
		InitBulletTypes();
		CurrentBulletType = BulletTypes[(int)BulletType.Types.Small];
	}

	void InitBulletTypes()
	{
		BulletTypes = new BulletType[(int)BulletType.Types.Length];
		BulletTypes[(int)BulletType.Types.Small] = new BulletType((GameObject)Resources.Load("Prefabs/Player_Bullet_Small"), 0.5f, 0.6f, -0.15f, 0.15f);
		BulletTypes[(int)BulletType.Types.TwoWay] = new BulletType((GameObject)Resources.Load("Prefabs/Player_Bullet_2way"), 0.5f, 0.6f, -0.15f, 0.15f);
	}

	void Fire1_Push()
	{
		ShootBullet(CurrentBulletType);
	}

	void ShootBullet( BulletType bullet ){
		Vector3 position = transform.position;
		position += transform.up * Random.Range(bullet.minOffset.y, bullet.maxOffset.y);
		position += transform.right * Random.Range(bullet.minOffset.x, bullet.maxOffset.x);
		Instantiate(bullet.Prefab, transform.position, transform.rotation);
	}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
	class BulletType
	{
		public enum Types
		{
			Small,
			TwoWay,
			Length
		}

		public GameObject Prefab;
		public Vector2 minOffset;
		public Vector2 maxOffset;

		public BulletType(GameObject prefab, float minOffsetX, float maxOffsetX, float minOffsetY, float maxOffsetY)
		{
			this.Prefab = prefab;
			this.minOffset = new Vector2(minOffsetX, minOffsetY);
			this.maxOffset = new Vector2(maxOffsetX, maxOffsetY);
		}
	}
	BulletType[] BulletTypes;
	BulletType CurrentBulletType;

	void Start()
	{
		InitBulletTypes();
		CurrentBulletType = BulletTypes[(int)BulletType.Types.Small];
	}

	void InitBulletTypes()
	{
		BulletTypes = new BulletType[(int)BulletType.Types.Length];
		BulletTypes[(int)BulletType.Types.Small] = new BulletType((GameObject)Resources.Load("Prefabs/Player_Bullet_Small"), 0.5f, 0.6f, -0.15f, 0.15f);
		BulletTypes[(int)BulletType.Types.TwoWay] = new BulletType((GameObject)Resources.Load("Prefabs/Player_Bullet_2way"), 0.5f, 0.6f, -0.15f, 0.15f);
	}

	void Fire1_Push()
	{
		ShootBullet(CurrentBulletType);
	}

	void ShootBullet( BulletType bullet ){
		Vector3 position = transform.position;
		position += transform.up * Random.Range(bullet.minOffset.y, bullet.maxOffset.y);
		position += transform.right * Random.Range(bullet.minOffset.x, bullet.maxOffset.x);
		Instantiate(bullet.Prefab, transform.position, transform.rotation);
	}
}
現在、コメントはありません。
最初のコメンターになりませんか?