Inheritance: MonoBehaviour
    void OnEnable()
    {
        capCol = (CapsuleCollider2D)target;

        edgeCollider = capCol.GetComponent<EdgeCollider2D>();
        if (edgeCollider == null) {
            capCol.gameObject.AddComponent<EdgeCollider2D>();
            edgeCollider = capCol.GetComponent<EdgeCollider2D>();
        }

        edgeCollider.points = capCol.getPoints(edgeCollider.offset);
    }
Esempio n. 2
0
    IEnumerator DestroyEnemy()
    {
        CapsuleCollider2D capsule = GetComponent <CapsuleCollider2D>();

        capsule.size      = new Vector2(1f, 0.25f);
        capsule.offset    = new Vector2(0f, -0.8f);
        capsule.direction = CapsuleDirection2D.Horizontal;
        yield return(new WaitForSeconds(0.25f));

        rb.velocity = new Vector2(0, rb.velocity.y);
        yield return(new WaitForSeconds(3f));

        Destroy(gameObject);
    }
Esempio n. 3
0
 void Start()
 {
     playerRigidbody  = GetComponent <Rigidbody2D>();
     playerAnimator   = GetComponent <Animator>();
     myCapsule        = gameObject.GetComponent <CapsuleCollider2D>();
     facingRight      = true;
     game             = false;
     hasLegs          = false;
     animationTrigger = "Idle";
     bodyPart         = 0;
     key1             = false;
     displayText      = false;
     door1            = true;
 }
    // Start is called before the first frame update
    protected override void Start()
    {
        base.Start();
        rb       = GetComponent <Rigidbody2D>();
        bodyColl = GetComponent <CapsuleCollider2D>();
        headColl = GetComponent <EdgeCollider2D>();

        initInterval = interval;

        leftx  = leftpoint.position.x;
        rightx = rightpoint.position.x;
        Destroy(leftpoint.gameObject);
        Destroy(rightpoint.gameObject);
    }
Esempio n. 5
0
    public PlayerModel(double x, double y, CapsuleCollider2D cldr)//, Rigidbody2D rbody)
    {
        collider           = cldr;
        collider.direction = CapsuleDirection2D.Horizontal;

        changeState(PState.Free);

        posX = x;
        posY = y;

        angle = -PI / 2;

        moveSpd = 1.5f;
    }
Esempio n. 6
0
 // Start is called before the first frame update
 void Start()
 {
     //Get the components from the gameObject attached to
     playerRigidBody = GetComponent <Rigidbody2D>();
     playerCollider  = GetComponent <CapsuleCollider2D>();
     playerAnim      = GetComponent <Animator>();
     playerSR        = GetComponent <SpriteRenderer>();
     playerTransform = GetComponent <Transform>();
     //Immediately calculate the distance to the ground (ie bottom of player collider)
     distToGround = playerCollider.bounds.extents.y + 0.2f;
     //Initialize vectors
     horVector = new Vector2(0, 0);
     verVector = new Vector2(0, 0);
 }
Esempio n. 7
0
 void Start()
 {
     _collider   = GetComponent <CapsuleCollider2D>();
     rb          = GetComponent <Rigidbody2D>();
     animatorObj = GetComponent <Animator>();
     if (canDoubleJump)
     {
         applyRocket();
     }
     if (canDash)
     {
         applyBoots();
     }
 }
Esempio n. 8
0
    void Awake()
    {
        animMeteor   = gameObject.transform.GetComponentInChildren <Animator>();
        spriteMeteor = gameObject.transform.GetComponentInChildren <SpriteRenderer>();
        spriteMeteor.sortingLayerName = "Foreground";
        spriteMeteor.sortingOrder     = 3;
        colliderMeteor            = GetComponent <CapsuleCollider2D>();
        colliderMeteor.enabled    = !colliderMeteor.enabled;
        son.outputAudioMixerGroup = mixerGroup;
        son.clip = listSon[Random.Range(0, 3)];
        son.PlayDelayed(0.6f);

        //  FindObjectOfType<AudioManager>().Play("MeteorCrash");
    }
Esempio n. 9
0
 void OnCollisionEnter2D(Collision2D other)
 {
     if (other.gameObject.CompareTag("human"))
     {
         CapsuleCollider2D collider = this.GetComponent <CapsuleCollider2D>();
         collider.enabled = false;
     }
     else if (other.gameObject.CompareTag("ground"))
     {
         AudioSource audio = this.GetComponent <AudioSource>();
         audio.Play(0);
         this.noise_bar.AddNoise(this.sound_cost);
     }
 }
Esempio n. 10
0
 void Awake()
 {
     // Required to prevent movement while stunned
     charSpeed      = GetComponent <SimpleMovement> ();
     camera         = GameObject.Find("Main Camera").GetComponent <CameraFollow> ();
     anim           = GetComponentInChildren <Animator> ();
     rb             = GetComponent <Rigidbody2D> ();
     collider       = GetComponent <CapsuleCollider2D> ();
     healthText     = GetComponentInChildren <Text>();
     spriteRenderer = GetComponentInChildren <SpriteRenderer> ();
     isAlive        = true;
     exploded       = false;
     timer          = 0.0f;
 }
    // Start is called before the first frame update

    void Awake()
    {
        if (OnlandEvent == null)
        {
            OnlandEvent = new UnityEvent();
        }
        rig  = GetComponent <Rigidbody2D>();
        anim = GetComponent <Animator>();
        cap  = GetComponent <CapsuleCollider2D>();

        playerXY = GetComponent <Transform>();
        Debug.Log("场景已加载" + Save.flag);
        save = new Save();
    }
Esempio n. 12
0
 void Start()
 {
     playerObjectTransform = GameObject.FindWithTag("Player").transform;
     isEnemyAlive          = true;
     enemyAnimator         = GetComponent <Animator>();
     spellEffect           = GetComponentInChildren <ParticleSystem>();
     playerScript          = GameObject.Find("Player").GetComponent <PlayerMove>();
     enemyCollider         = GetComponent <CapsuleCollider2D>();
     enemyFootCollider     = GetComponent <BoxCollider2D>();
     AudioSource[] soundSources = GetComponents <AudioSource>();
     attackSound     = soundSources[2];
     deathSound      = soundSources[0];
     takeDamageSound = soundSources[1];
 }
Esempio n. 13
0
    // Start is called before the first frame update
    void Start()
    {
        //Sets reference to components within script on start function.
        rb                      = this.GetComponent <Rigidbody2D>();
        animator                = this.GetComponent <Animator>();
        jumpTimerRestart        = jumpTimer;
        capsuleCollider         = this.GetComponent <CapsuleCollider2D>();
        circleCollider          = this.GetComponent <CircleCollider2D>();
        capsuleCollider.enabled = true;
        circleCollider.enabled  = false;
        rb.sharedMaterial       = physMatPlatform;

        colliderSize = capsuleCollider.size;
    }
    // Use this for initialization
    protected override void Start()
    {
        tf         = GetComponent <Transform>();
        sprite     = GetComponent <SpriteRenderer>();
        rb         = GetComponent <Rigidbody2D>();
        hitBox     = GetComponent <CapsuleCollider2D>();
        soundMaker = GetComponent <AudioSource>();
        anim       = GetComponent <Animator>();

        if (GameManager.instance.player == null)
        {
            GameManager.instance.player = this;
        }
    }
Esempio n. 15
0
    void Awake()
    {
        rb2d           = gameObject.GetComponent <Rigidbody2D>();
        animator       = gameObject.GetComponent <Animator> ();
        spriteRenderer = gameObject.GetComponent <SpriteRenderer>();
        cc2d           = gameObject.GetComponent <CapsuleCollider2D>();

        GameObject mainCamera = GameObject.Find("Main Camera");

        if (mainCamera)
        {
            cameraController = mainCamera.GetComponent <CameraController>();
        }
    }
Esempio n. 16
0
    protected virtual void Start()
    {
        transform.GetChild(1).GetComponent <TriggerScript>().On_T_Enter  += ViewTriggered;
        transform.GetChild(2).GetComponent <ColliderScript>().On_C_Enter += HeadTriggered;
        headTransform = transform.GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0);

        rb   = GetComponent <Rigidbody2D>();
        col  = GetComponent <CapsuleCollider2D>();
        anim = transform.GetChild(0).GetComponent <Animator>();
        aSrc = GetComponent <AudioSource>();

        x_center = transform.position.x + offset;
        StartCoroutine(MoveAround());
    }
Esempio n. 17
0
    private void Start()
    {
        #region Refs.
        pc      = FindObjectOfType <CharacterMovement>().gameObject;
        tilemap = FindObjectOfType <Tilemap>().gameObject;
        range   = GetComponent <CapsuleCollider2D>();

        var m = FindObjectsOfType <Tilemap>();
        foreach (Tilemap t in m)
        {
            maps.Add(t.gameObject);
        }
        #endregion
    }
Esempio n. 18
0
    private SpriteRenderer sr;       // 圖片渲染
    #endregion

    #region 事件
    // 初始事件:遊戲開始執行一次
    private void Start()
    {
        maxHp = hp;

        //print("哈囉,沃德~");
        // GetComponent<T>() 泛型方法<T>
        ani  = GetComponent <Animator>();
        cc2d = GetComponent <CapsuleCollider2D>();
        r2d  = GetComponent <Rigidbody2D>();
        aud  = GetComponent <AudioSource>();
        sr   = GetComponent <SpriteRenderer>();

        cam = GameObject.Find("Main Camera").transform;
    }
Esempio n. 19
0
 void Start()
 {
     // healthBar = gameObject.AddComponent<HealthBar>();
     healthBar = GameObject.Find("Health Bar").GetComponent <HealthBar>();
     healthBar.SetMaxHealth(100);
     //healthBar.SetHealth(30);
     rigidbody            = GetComponent <Rigidbody2D>();
     animatorComponent    = GetComponent <Animator>();
     spriteComponent      = GetComponent <SpriteRenderer>();
     bodyCollider         = GetComponent <CapsuleCollider2D>();
     previousGravityScale = rigidbody.gravityScale;
     //HealthText.text = health.ToString();
     playerFeet = GetComponent <BoxCollider2D>();
 }
        void Awake()
        {
            rigid         = GetComponent <Rigidbody2D>();
            animator      = GetComponent <Animator>();
            vision_target = GetComponent <VisionTarget>();
            collide       = GetComponentInChildren <Collider2D>();
            capsule_coll  = GetComponentInChildren <CapsuleCollider2D>();
            start_scale   = transform.localScale;

            contact_filter              = new ContactFilter2D();
            contact_filter.layerMask    = ground_mask;
            contact_filter.useLayerMask = true;
            contact_filter.useTriggers  = false;
        }
Esempio n. 21
0
        float enterClimbingState; // Timer to control climbing animation

        void Start()
        {
            myRigidbody         = GetComponent <Rigidbody2D>();
            myAnimator          = GetComponent <Animator>();
            myFeetCollider      = GetComponent <BoxCollider2D>();
            gravityScaleAtStart = myRigidbody.gravityScale;

            if (gameObject.tag == "Player")
            {
                bodyCollider = GetComponent <CapsuleCollider2D>();
                defaultBodyColliderOffset = bodyCollider.offset;
                defaultBodyColliderSize   = bodyCollider.size;
            }
        }
Esempio n. 22
0
    // 起始事件: 開始時執行一次
    private void Start()
    {
        maxHp = hp;

        // 取得攝影機物件
        cam = GameObject.Find("Main Camera").transform;
        // 取得元件, GetComponent<T>() 泛型
        ani  = GetComponent <Animator>();
        cc2d = GetComponent <CapsuleCollider2D>();
        r2d  = GetComponent <Rigidbody2D>();
        sr   = GetComponent <SpriteRenderer>();

        audioSource = GetComponent <AudioSource>();
    }
Esempio n. 23
0
    //For RayCasting

/*	private bool spoted;
 *      Vector3 initialPosition;
 *      [Tooltip("float value. This value represnts the position where the bullet will be created when the enemy shoots")]
 *      public float visionRadius;
 *      private GameObject player;
 */
    // Use this for initialization
    void Start()
    {
        rb          = GetComponent <Rigidbody2D> ();
        sr          = GetComponent <SpriteRenderer> ();
        enemy       = GetComponent <EnemyHealth> ();
        player      = GameObject.FindGameObjectWithTag("Player");
        cap2D       = GetComponent <CapsuleCollider2D> ();
        speedPatrol = 2f;
        //	maxDelay = 4f;
        minDelay = 2f;
        canTurn  = true;
        SetStartDirection();
//		player = GameObject.FindGameObjectWithTag("Player");
    }
 void Awake()
 {
     Assert.IsNotNull(groundDetector);
     Assert.IsNotNull(climbUpperDetector);
     Assert.IsNotNull(climbLowerDetector);
     rb = GetComponent <Rigidbody2D>();
     Assert.IsNotNull(rb);
     physicsCollider = GetComponent <CapsuleCollider2D>();
     Assert.IsNotNull(physicsCollider);
     facingController = GetComponentInChildren <MirrorToInput>();
     Assert.IsNotNull(facingController);
     mover = GetComponentInParent <CharacterMover>();
     Assert.IsNotNull(mover);
 }
        void Awake()
        {
            characterRb     = GetComponent <Rigidbody2D>();
            capsuleCollider = GetComponent <CapsuleCollider2D>();

            currentPosition  = characterRb.position;
            previousPosition = characterRb.position;

            m_ContactFilter.layerMask    = groundedLayerMask;
            m_ContactFilter.useLayerMask = true;
            m_ContactFilter.useTriggers  = false;

            Physics2D.queriesStartInColliders = false;
        }
Esempio n. 26
0
        void Awake()
        {
            m_Rigidbody2D = GetComponent <Rigidbody2D>();
            m_Capsule     = GetComponent <CapsuleCollider2D>();

            m_CurrentPosition  = m_Rigidbody2D.position;
            m_PreviousPosition = m_Rigidbody2D.position;

            m_ContactFilter.layerMask    = groundedLayerMask;
            m_ContactFilter.useLayerMask = true;
            m_ContactFilter.useTriggers  = false;

            Physics2D.queriesStartInColliders = false;
        }
Esempio n. 27
0
 // Use this for initialization
 private void Awake()
 {
     // 이 객체의 정보들을 담는다.
     ThisAudio     = GetComponent <AudioSource>();
     ThisBody      = GetComponent <Rigidbody2D>();
     ThisTransform = GetComponent <Transform>();
     ThisCollider  = GetComponent <CapsuleCollider2D>();
     bulletBody    = bullet.GetComponent <Rigidbody2D>();
     playerShield.SetActive(false);
     bullet.gameObject.SetActive(false);
     FlipDirection();
     Health      = UIM.playerMaxHP;
     ShieldLimit = UIM.shieldLimit;
 }
Esempio n. 28
0
    protected void Awake()
    {
        col           = GetComponent <CapsuleCollider2D>();
        animator      = GetComponent <Animator>();
        ennemySpawner = FindObjectOfType <EnnemySpawner>(); //Send to the ennemy spawn that he has been destroyed

        hullPoints   = MaxHullPoints;
        shieldPoints = MaxShieldPoints;
        platePoints  = MaxPlatePoints;

        isMoving = true;
        squad    = GetComponentInParent <EnnemySquad>();
        agent    = GetComponent <NavMeshAgent>();
    }
        protected static void AddCapsuleOffset(CapsuleCollider2D collider, ref Vector2 StartPosition, ref Vector2 EndPosition, Vector2 scale, bool useLossyScale)
        {
            if (useLossyScale)
            {
                scale *= collider.offset;
            }
            else
            {
                scale = collider.offset;
            }

            StartPosition += scale;
            EndPosition   += scale;
        }
Esempio n. 30
0
    public static bool Verifique(Collider2D collision)
    {
        CapsuleCollider2D cc2d = null;

        try { cc2d = (CapsuleCollider2D)collision; }
        catch { }

        if (cc2d != null)
        {
            return(true);
        }

        return(false);
    }
Esempio n. 31
0
    // Use this for initialization
    void Start()
    {
        grappleJoint         = GetComponent <DistanceJoint2D>();
        grappleJoint.enabled = false;
        player             = GetComponent <Player>();
        playerFeetCollider = GetComponent <CircleCollider2D>();
        playerBodyCollider = GetComponent <CapsuleCollider2D>();


        ropeRenderer         = GetComponent <LineRenderer>();
        ropeRenderer.enabled = false;

        playerRigidBody = player.GetComponent <Rigidbody2D>();
    }