1 분 소요

함수 : function

  • 어떤 기능을 하는것들의 집합체
    1. Int
    2. Float
    3. String
    4. Bool
    5. Void : 뭔가를 리턴하지 않음. 그냥 기능만 넣어두는 함수 공백함수
  • 변수는 소문자 , 함수는 대문자
  • Void Move() {} : 함수 선언
  • 변수는 스택처럼 쌓였다가 마지막 중괄호에서 선입 후출로 빠져나감

지역변수 / 전역 변수

  • () : 조건 // 매개변수가 ()안에 들어감
  • {} : 내용
  • [] : 배열

  • 함수의 이름은 똑같으면 안됨
  • 단, 매개변수를 다르게 하면 상관없음.
  • 컴퍼넌트(유니티에서 만든 스크립트)도 다 스크립트다
  • [Serialise] : 유니티에서는 사용 X, 스크립트간에는 이동 가능

  • 변수 2종류
    1. Basic – int, float, string, bool
    2. 각종 Component:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Player : MonoBehaviour
{
    int qwe;
    int a;
    float b;
    string c;
    bool d;
 
    public float _movespeed;
    // Start is called before the first frame update
    void Start()
    {
        
    }
 
    // Update is called once per frame
    void Update()
    {
        Move();
        a = Plus();
        c = Daehwa() + Plus();
        if (Input.GetKeyDown(KeyCode.Return))
        {
            a = Plus();
        }
    }
 
    void Move()
    {
        if (Input.GetKey(KeyCode.UpArrow))
        {
            this.gameObject.transform.Translate(0, 0, _moveSpeed * Time.deltaTime);          // 1초에 5만큼 움직인다 
        }
 
        if (Input.GetKey(KeyCode.DownArrow))
        {
            this.gameObject.transform.Translate(0, 0, _moveSpeed * Time.deltaTime);
        }
 
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            this.gameObject.transform.Translate(-_moveSpeed * Time.deltaTime, 0, 0);
        }
 
        if (Input.GetKey(KeyCode.RightArrow))
        {
            this.gameObject.transform.Translate(_moveSpeed * Time.deltaTime, 0, 0);
        }
 
    }
 
    int Plus(int q, int w)
    {
        
        return q + w;       //return은 아래 중괄호까지 안가고 돌아가버림
    }
 
    string Daehwa()
    {
        string nickname = "김밥";
        string conver = "안녕하세요";
        return nickname + conver;
    }
}     
public class Player : MonoBehaviour
 
{
    Public Player2 _player2;   //Player2라는 스크립트를 만들고, 유니티에서 player2가 담긴 오브젝트를 넣으면 player에서 접근가능
    public int _moveSpeed;
    BoxCollider _box;           //무명의 박스 만듦
 
    void Start()
 
    {
        _box = this.gameObject.GetComponent<BoxCollider>();                  //이 스크립트가 들어가있는 = this
        //이 무명의박스는 뭐냐면, 이 스크립트가 들어있는 게임오브젝트의 boxcoliider라는 컴퍼넌트를 가져와서 넣은 박스임
        _box.isTrigger = true;
        //isTrigger를 체크함(체크하는게 true임, 체크해제는 false)
    }
}

댓글남기기