// public playerMove instance; // Start is called before the first frame update void Start() { player_Together = playerTogether.GetComponent <playerMove>(); join_Together = playerTogether.GetComponent <playerJoin>(); //전체모임이 선택되었을때, 플레이어를 예쁘게 모이게 해주는아이 // playerMove player_1 = GameObject.Find("Player_1").GetComponent<playerMove>(); // player_1 = GameObeject.Find("Player_1") }
// Update is called once per frame void Update() { topPoint = GameObject.FindGameObjectWithTag("topPoint"); leftPoint = GameObject.FindGameObjectWithTag("leftPoint"); rightPoint = GameObject.FindGameObjectWithTag("rightPoint"); if (Active) { if (Position == topPoint || Position == leftPoint || Position == rightPoint) { topPoint.transform.DetachChildren(); leftPoint.transform.DetachChildren(); rightPoint.transform.DetachChildren(); } //마우스로 이동할 위치 받기 if (Input.GetMouseButtonDown(0)) { Vector2 wp = Camera.main.ScreenToWorldPoint(Input.mousePosition); // Ray2D ray = new Ray2D(wp, Vector2.zero); // RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction); // if (hit.collider != null) //체크용 { // Debug.Log(wp); // wp랑 hit.point 랑 똑같네 뭘까. } finalPos = wp; //vector3로 변환 curPos = transform.position; dir = finalPos - curPos; //방향 길이 dir.Normalize(); canMove = true; //true일때 변경불가 false면 캐릭터변경가능. } if (canMove) { step = Time.deltaTime * moveSpeed; curPos = transform.position; endPos = finalPos - curPos; // 도착위치 = 최종도착- 현재 if (endPos.magnitude <= step) { animator.SetFloat("Magnitude", dir.magnitude); canMove = false; //true일때 변경불가 false면 캐릭터변경가능. } else { transform.position = curPos + (dir * step); } animator.SetFloat("Horizontal", dir.x); animator.SetFloat("Vertical", dir.y); animator.SetFloat("Magnitude", dir.magnitude); } // Move(finalPos); // 에러있음. 추후 함수화 //false가 자주 잘 안먹는다. 어떡하지? } if (join) { playerJoin player_Together = GameObject.Find("Player_Together").GetComponent <playerJoin>(); if (Position == topPoint) // Point위치 정의. top or left or right { Point = topPoint.transform.position; } else if (Position == leftPoint) // Point위치 정의. top or left or right { Point = leftPoint.transform.position; } else if (Position == rightPoint) // Point위치 정의. top or left or right { Point = rightPoint.transform.position; } // Debug.Log("MoveForJoin " + Point); dir = Point - curPos; dir.Normalize(); step = Time.deltaTime * moveSpeed; curPos = transform.position; endPos = Point - curPos; // 도착위치 = 최종도착- 현재 if (endPos.magnitude >= step) { // Debug.Log("MoveForJoinDO " + Point); transform.position = curPos + (dir * step); } else { animator.SetFloat("Magnitude", dir.magnitude); //Debug.Log("도착해쪙"); join = false; player_Together.Active = false; //차일드화 if (Position == topPoint) // Point위치 정의. top or left or right { transform.SetParent(topPoint.transform); // Debug.Log("엄마"); } else if (Position == leftPoint) // Point위치 정의. top or left or right { transform.SetParent(leftPoint.transform); } else if (Position == rightPoint) // Point위치 정의. top or left or right { transform.SetParent(rightPoint.transform); } } } }