public void OnSnakeCollisionEnter(Collision col, SnakeCollider snakeCol)
    {
        _rigid = snakeCol.GetComponent <Rigidbody>();
        if (!_initialParentSet)
        {
            _initialParentSet    = true;
            _originalVelcroSnake = snakeCol.transform.parent.parent;
        }
        // Objects stuck to the snake.
        foreach (var x in snakeCol.rootOfSnake.GetComponent <SnakeInventory>().inventory)
        {
            x.transform.parent = GrabHook;
        }
        _originalVelcroSnake.parent = GrabHook;

        for (int i = 0; i < _rigid.transform.parent.childCount; i++)
        {
            if (_rigid.transform.parent.GetChild(i).GetComponent <Rigidbody>() != null)
            {
                _rigid.transform.parent.GetChild(i).GetComponent <Rigidbody>().isKinematic = true;
                if (_rigid.transform.parent.GetChild(i).GetComponent <Collider>() != null)
                {
                    _rigid.transform.parent.GetChild(i).GetComponent <Collider>().enabled = false;
                }
            }
        }
        for (int i = 0; i < _rigid.transform.childCount; i++)
        {
            if (_rigid.transform.GetChild(i).GetComponent <Rigidbody>() != null)
            {
                _rigid.transform.GetChild(i).GetComponent <Rigidbody>().isKinematic = true;
                if (_rigid.transform.GetChild(i).GetComponent <Collider>() != null)
                {
                    _rigid.transform.GetChild(i).GetComponent <Collider>().enabled = false;
                }
            }
        }
        // Objects stuck to the snake.
        foreach (var x in _rigid.GetComponent <SnakeCollider>().rootOfSnake.GetComponent <SnakeInventory>().inventory)
        {
            x.rigid.isKinematic = true;
            if (x.GetComponent <Collider>() != null)
            {
                x.GetComponent <Collider>().enabled = false;
            }
        }
        _readyToReleaseSnake = true;
        _toggleCollider      = true;
    }
示例#2
0
    public void OnSnakeTriggerEnter(Collider col, SnakeCollider snakeCol)
    {
        if (col == transform.GetComponent <Collider>())
        {
            _rigid = snakeCol.GetComponent <Rigidbody>();
            if (!_initialParentSet)
            {
                _initialParentSet    = true;
                _originalVelcroSnake = snakeCol.transform.parent.parent;
                teleporter.position  = snakeCol.transform.position;
                //Debug.Log("initialParent= " + _originalVelcroSnake.name);
            }
            //Debug.Log("The rigidbody's 2nd parent= " + _rigid.transform.parent.parent.name);
            foreach (var x in snakeCol.rootOfSnake.GetComponent <SnakeInventory>().inventory)
            {
                x.transform.parent = teleporter;
            }
            _originalVelcroSnake.parent = teleporter;
            audioS.PlayOneShot(enterSound);
            //Debug.Log("The teleporter first child= " + teleporter.GetChild(0).name);
            //Debug.Log("Teleporter's number of children= " + teleporter.childCount);

            /*if (teleporter.childCount > 0)
             * {
             *  for (int i = 0; i < teleporter.childCount; i++)
             *  {
             *      Debug.Log("child name= " + teleporter.GetChild(i).name);
             *  }
             * }*/
            dustBurstHolder.SetActive(false);
            if (!snakeMoved)
            {
                snakeMoved = !snakeMoved;
                StartCoroutine(MoveSnake(timer));
            }
        }
    }