커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
충돌처리를 하여도 되지가 않습니다...ㅠㅠ
undefined주차
북마크
이*목
댓글
5
추천
0
조회수
14
조회수
14
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.


수업시간에 배운것을 응용하여 사용해보았는데 충돌처리를 하더라도 충돌이 발생하지않습니다.. ㅠㅠ



스파르타 즉문즉답 스파르타 즉문즉답




작성한 코드 및 에러 메세지


1번사진의 코드

using System.Collections;

using System.Collections.Generic;

using Unity.VisualScripting;

using UnityEngine;

using static UnityEngine.EventSystems.EventTrigger;


public class building : MonoBehaviour

{

  public float dead = 0.0f;

  public float health = 5.0f;

  Rigidbody2D rigid;


  private void Awake()

  {

    rigid = GetComponent<Rigidbody2D>(); 

    //중력 지맘대로 바꾸는 코드rigid.gravityScale = Random.Range(1, 5);

  }

  void Start()

  {

    float x = Random.Range(-3f, 3f);

    float y = Random.Range(100f, 100f);

    transform.position = new Vector3(x, y, 0);


    float size = Random.Range(0.5f, 1.5f);

    transform.localScale = new Vector3(size, size, 0);

  }


  // Update is called once per frame

  void FixedUpdate()

  { 

  }


  void OnTriggerEnter2D(Collider2D coll)

  {

    if (!coll.CompareTag("Weapon"))

      return;


    health -= coll.GetComponent<Weapon>().damage;

    Debug.Log("맞음");

       

      if (health > 0)

      {

        health -= 1.0f;

      }

      else

      {

        Dead();

      }

  }


  void Dead()

  {

    gameObject.SetActive(false);

    Debug.Log("삭제");

  }

}




취소
 공유
취소
댓글 0
댓글 알림
나의얼굴