Unity/Project : Unity 2D 1945

Unity 2D 1945 21.04.06

HappyFrog 2021. 4. 7. 09:34
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CatController : MonoBehaviour
{
    public float speed;

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {


        if (Input.GetKey(KeyCode.LeftArrow))
        {
            
            this.transform.Translate(-speed, 0, 0);
        }

        if (Input.GetKey(KeyCode.RightArrow))
        {
            this.transform.Translate(speed, 0, 0);
        }

        if (Input.GetKey(KeyCode.UpArrow))
        {
            this.transform.Translate(0, speed, 0);
        }
        if (Input.GetKey(KeyCode.DownArrow))
        {
            this.transform.Translate(0, -speed, 0);
        }


    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WaterController : MonoBehaviour
{
    GameObject player;
    public float dropspeed;
    GameObject paw;
    // Start is called before the first frame update
    void Start()
    {
        this.player = GameObject.Find("cat1");
    }

    // Update is called once per frame
    void Update()
    {
        this.paw = GameObject.Find("CatPaw");

        this.transform.Translate(0, -dropspeed, 0);

        Vector2 pos1 = this.transform.position;
        Vector2 pos2 = this.player.transform.position;
        Vector2 dir = pos1 - pos2;
        float d = dir.magnitude;
        float r1 = 0.1f;
        float r2 = 0.6f;

        Vector3 pos3 = this.paw.transform.position;
        Vector3 pos4 = this.transform.position;
        Vector3 dir2 = pos4 - pos3;

        float d2 = dir.magnitude;
        float r3 = 0.25f;
        float r4 = 0.1f;

        if (d < r1 + r2)
        {
            GameObject director = GameObject.Find("GameDirector");
            director.GetComponent<GameDirector>().DecreaseHp();

            Destroy(this.gameObject);
        }

        if (d2 < r3 + r4)
        {
            Destroy(this.gameObject);
            Destroy(this.paw);
        }


        if(this.transform.position.y < -4)
        {
            Destroy(this.gameObject);
        }
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WaterGenerator : MonoBehaviour
{
    public GameObject waterPrefab;
    public float span;
    float delta;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        this.delta += Time.deltaTime;
        if (this.delta > this.span)
        {
            this.delta = 0;
            GameObject go = Instantiate(waterPrefab) as GameObject;
            float px = Random.Range(-1.6f, 3.5f);
            go.transform.position = new Vector3(px, 5, 0);
        }
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class GameDirector : MonoBehaviour
{
    GameObject hpGauge;

    // Start is called before the first frame update
    void Start()
    {
        this.hpGauge = GameObject.Find("hpGauge");
    }

    public void DecreaseHp()
    {
        this.hpGauge.GetComponent<Image>().fillAmount -= 0.2f;
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PawController : MonoBehaviour
{
    GameObject water;
    public float speed;
    // Start is called before the first frame update
    void Start()
    {
        water = GameObject.Find("waterPrefab");
    }

    // Update is called once per frame
    void Update()
    {/*
        this.transform.Translate(0, speed, 0);

        Vector3 pos1 = this.transform.position;
        Vector3 pos2 = water.transform.position;
        Vector3 dir = pos2 - pos1;

        float d = dir.magnitude;
        float r1 = 0.25f;
        float r2 = 0.1f;

        if(d < r1 + r2)
        {
            Destroy(water);
            Destroy(this);
        }*/

        if(this.transform.position.y > 5)
        {
            Destroy(this);
        }


    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PawGenerator : MonoBehaviour
{
    GameObject player;
    // Start is called before the first frame update
    void Start()
    {
        this.player = GameObject.Find("cat1");
    }

    // Update is called once per frame
    void Update()
    {
        /*this.delta += Time.deltaTime;*/

        Vector3 playerPos = this.player.transform.position;
        this.transform.position = new Vector3(playerPos.x, playerPos.y, this.transform.position.z);
    }
}

============================================================================

04.07. 추가/수정안

ㄴ물방울이랑 발바닥이 만나면 둘 다 사라짐

ㄴ세로에서 가로모드로 바꿈

ㄴ물방울 나오는 범위 수정

ㄴ캣푸드 프리팹 완성시키고 적용은 아직 안함

ㄴ캣푸드 먹으면 20%씩 체력이 차며 30초마다 맵 왼쪽 절반에서 무작위 위치에 나타남

ㄴx축 모션 만드는중

ㄴ점수 텍스트UI추가

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CatFoodGenerator : MonoBehaviour
{
    public GameObject catFoodPrefab;
    float delta;
    public float spawn;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        this.delta += Time.deltaTime;
        if (this.delta >= 30f)
        {
            this.delta = 0;
            GameObject go = Instantiate(catFoodPrefab) as GameObject;
            int x = Random.Range(-9, 1);
            go.transform.position = new Vector3(x, 5, 0);
            
        }
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CatFoodController : MonoBehaviour
{
    public float dropSpeed;
    GameObject player;
    // Start is called before the first frame update
    void Start()
    {
        this.player = GameObject.Find("cat1");
    }

    // Update is called once per frame
    void Update()
    {
        Vector3 pos1 = this.player.transform.position;
        Vector3 pos2 = this.gameObject.transform.position;
        Vector3 dir = pos2 - pos1;

        float d = dir.magnitude;
        float r1 = 0.15f;
        float r2 = 0.6f;

        if(d < r1 + r2)
        {
            GameObject gd = GameObject.Find("GameDirector");
            gd.GetComponent<GameDirector>().IncreaseHp();
            Destroy(gameObject);
        }

        this.gameObject.transform.Translate(0, -dropSpeed, 0);               
    }

   
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PawController : MonoBehaviour
{ 
    public float speed = 0.03f;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        this.gameObject.transform.Translate(0, speed, 0);
                
        if(this.transform.position.y > 4.9f)
        {
            Destroy(gameObject);
        }

    }

    public void OnTriggerEnter2D(Collider2D collision)
    {       
        Destroy(gameObject);                        
    }


}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WaterController : MonoBehaviour
{
    WaterGenerator wg;
    GameObject player;
    public float dropspeed;
    float hp =1;
    

    
    // Start is called before the first frame update
    void Start()
    {
        this.player = GameObject.Find("cat1");
       
    }

    // Update is called once per frame
    void Update()
    {       
        this.transform.Translate(0, -dropspeed, 0);

        Vector2 pos1 = this.transform.position;
        Vector2 pos2 = this.player.transform.position;
        Vector2 dir = pos1 - pos2;
        float d = dir.magnitude;
        float r1 = 0.1f;
        float r2 = 0.6f;

        if (d < r1 + r2)
        {                        
            GameObject director = GameObject.Find("GameDirector");
            director.GetComponent<GameDirector>().DecreaseHp();

            Destroy(gameObject);
        }

        if (this.transform.position.y < -4)
        {
            Destroy(gameObject);
        }
    }

    public void OnTriggerEnter2D(Collider2D collision)
    {
        
        this.hp -= 0.5f;

        if(this.hp <= 0)
        {           
            Destroy(gameObject);            
        }
        
    }
}

 

추가 예정 사항

ㄴx축 공격모션

ㄴ물방울 일정이상 생성시 강력한 물방울 생성

ㄴx축에서 랜덤한 시간에 웨이브 발생

ㄴ폭탄(궁극기)추가

ㄴ캐릭터가 풀 위쪽으로 못나가게 정의

ㄴ버튼구현(x축, y축 모드 바꾸기/이동/폭탄사용/지난 시간)

 

 

댓글수0