玩家坚持重新激活 - 不改变产生的位置

时间:2016-08-21 17:36:15

标签: c# unity3d scripting

我正在编写一个控制2D游戏中太空船进入和退出的脚本。 我遇到的问题是当退出船时,玩家重新启动,你重新获得控制权,但它不会将玩家移动到我已经附着在船上的空游戏对象,初学者试图移动玩家到船的位置,没有破坏玩家。在进入船只之前,玩家只是在其最后一个已知位置产生,我似乎被迫进入该位置,我可以尝试移动,但它就像我固定在那个位置。

    using UnityEngine;
using System.Collections;

public class SpaceShipActivator : MonoBehaviour
{
    //Takeoff
    public bool inRange;
    public SpaceShipAtmosphereController SpaceShipAtmosphereController;
    public PlayerController playerControl;
    public GameObject Player;
    public bool onBoard;
    //End Takeoff

    //Landing
    public Transform Spawn;
    public Transform landingGear2;
    public Transform landingGear;
    public LayerMask whatIsGround;
    float groundRadius = 0.2f;
    bool getIn;
    bool landingGearStable;
    bool landingGearStable2;
    bool shipStable;
    //EndLanding

    Animator anim;


    void Start()
    {
        anim = GetComponent<Animator>();
        inRange = false;
        SpaceShipAtmosphereController.enabled = false; 

    }


    void Update()
    {

        AnimationUpdate();

        //Launch
        if (inRange && Input.GetButtonDown("Interact") && !onBoard)
        {
            LaunchShip();
        }
        //End launch

        CheckLandingGear();

        //Land
        if(onBoard && Input.GetButtonDown("Roll"))
        {
            LandShip();
        }
        //End Land

    }

    //*********************************Functions**************************************

    void LaunchShip()
    {
        anim.SetBool("Get In", true);
        this.gameObject.tag = "Player";
        SpaceShipAtmosphereController.enabled = true;
        Player.tag = "InactivePlayer";
        playerControl.enabled = false;
        Player.SetActive(false);
        onBoard = true;
    }

    void LandShip()
    {
        anim.SetBool("Get Out", true);
        this.gameObject.tag = "InactivePlayer";
        Player.tag = "Player";
        playerControl.enabled = true;
        SpaceShipAtmosphereController.enabled = false;
        onBoard = false;
        Player.SetActive(true);
        Player.transform.position = Spawn.transform.position;
    }

    void CheckLandingGear()
    {
        //landingGear
        landingGearStable = Physics2D.OverlapCircle(landingGear.position, groundRadius, whatIsGround);
        landingGearStable2 = Physics2D.OverlapCircle(landingGear2.position, groundRadius, whatIsGround);

        if (landingGearStable && landingGearStable2)
        {
            shipStable = true;
        }
        //End landingGear
    }

    void AnimationUpdate()
    {
        anim.SetBool("Get In", false);
        anim.SetBool("Get Out", false);
    }

    //For launching ship
    //IF player: inRange enter/exit boolean control.
    void OnTriggerEnter2D(Collider2D other)
    {

        if (other.CompareTag("Player"))
        {
            //Debug.Log("houi p;gberf");
            inRange = true;
        }
    }

    void OnTriggerExit2D(Collider2D other)
    {
        if (other.CompareTag("Player"))
        {
            inRange = false;
        }
    }
    //End IF player: inRange enter/exit boolean control.


}

在旁注中,在同一个剧本中,我包括landingGear,它被设置为两个空的游戏对象,它们基本上共享Y并在X上间隔开,以检查宇宙飞船是否不仅接地而且等级为大多数情况下,所以动画看起来并不傻并检查玩家是否可以退出。我知道这不是问题所在,但是对它的任何意见都会表示赞赏,但请不要感到有义务。

感谢您的帮助

0 个答案:

没有答案