
1・・・オスひよこ
上のオス専用の柵の中にドラッグしましょう。
下のメス専用の柵の中に入れてしまったり10秒間放置すると怒られてゲームオーバーです。
2・・・メスひよこ
下のメス専用の柵の中にドラッグしましょう。
上のオス専用の柵の中に入れてしまったり10秒間放置すると怒られてゲームオーバーです。
時間制限などはありません。
時間経過で出てくるひよこがどんどん増えるので、どれだけ多く仕訳けれるか挑戦してみてください。
ひよこをドラッグ&ドロップできるようにする
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjectController : MonoBehaviour
{
// 追加
private Vector3 screenPoint;
private Vector3 offset;
private Vector2 prevPosition;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnMouseDown()
{
this.screenPoint = Camera.main.WorldToScreenPoint(transform.position);
this.offset = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
GetComponent<BoxCollider2D>().enabled = false;
}
void OnMouseDrag()
{
Vector3 currentScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
Vector3 currentPosition = Camera.main.ScreenToWorldPoint(currentScreenPoint) + this.offset;
transform.position = currentPosition;
}
void OnMouseUp()
{
GetComponent<BoxCollider2D>().enabled = true;
}
}
}
時間経過でひよこが出てくる量を変える
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour
{
GameObject sw;
float delta;
float gamedelta;
public GameObject pg;
public GameObject pg1;
public GameObject pg2;
public GameObject pg3;
public GameObject pg4;
public GameObject pg5;
void Start()
{
sw = GameObject.Find("Switch");
}
void Update()
{
gamedelta += Time.deltaTime;
if (gamedelta >= 20)
{
pg1.SetActive(true);
}
if (gamedelta >= 40)
{
pg.SetActive(false);
pg2.SetActive(true);
}
if (gamedelta >= 60)
{
pg1.SetActive(false);
pg3.SetActive(true);
}
if (gamedelta >= 80)
{
pg2.SetActive(false);
pg4.SetActive(true);
}
if (gamedelta >= 100)
{
pg3.SetActive(false);
pg5.SetActive(true);
}
if (sw.GetComponent<MissSwitch>().Switch == true)
{
delta += Time.deltaTime;
pg.SetActive(false);
pg1.SetActive(false);
pg2.SetActive(false);
pg3.SetActive(false);
pg4.SetActive(false);
pg5.SetActive(false);
}
if (delta >= 2.5f)
{
SceneManager.LoadScene("Result");
}
}
}
}
ひよこの動きの処理
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MaleMove : MonoBehaviour
{
float x;
float y;
public float YSwitch = 0;
public float XSwitch = 0;
public bool MissSwitch;
bool deltaSwitch = true;
GameObject gd;
GameObject sw;
float delta = 0;
float span = 7;
float end = 10;
Animator animator;
void Start()
{
animator = GetComponent<Animator>();
gd = GameObject.Find("GameDirector");
sw = GameObject.Find("Switch");
}
void Update()
{
transform.Translate(x, y, 0);
if (deltaSwitch == true)
{
delta += Time.deltaTime;
}
if (delta >= span)
{
animator.SetTrigger("MaleChangeTrigger");
}
if (delta >= end)
{
animator.SetTrigger("MaleAngryTrigger");
sw.GetComponent<MissSwitch>().Switch = true;
}
x = 0.015f;
y = 0.015f;
if (YSwitch == 1)
{
y *= -1;
}
if (YSwitch == 2)
{
y *= -1;
YSwitch = 0;
}
if (XSwitch == 1)
{
x *= -1;
}
if (XSwitch == 2)
{
x *= -1;
XSwitch = 0;
}
if (sw.GetComponent<MissSwitch>().Switch == true)
{
x = 0;
y = 0;
Destroy(GetComponent<ObjectController>());
deltaSwitch = false;
GetComponent<AudioSource>().Stop();
}
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Side")
{
XSwitch += 1;
}
if (other.gameObject.tag == "Wide")
{
YSwitch += 1;
}
if (other.gameObject.tag == "Male")
{
gd.GetComponent<GameDirector>().AddPoint();
transform.position = new Vector3(0, 2.55f, 0);
Destroy(GetComponent<ObjectController>());
animator.SetTrigger("MaleNomalTrigger");
delta = 0;
deltaSwitch = false;
GetComponent<AudioSource>().Stop();
}
if (other.gameObject.tag == "Female")
{
gd.GetComponent<GameDirector>().AddPoint();
transform.position = new Vector3(0, -3.3f, 0);
Destroy(GetComponent<ObjectController>());
sw.GetComponent<MissSwitch>().Switch = true;
animator.SetTrigger("MaleAngryTrigger");
}
}
}