示例#1
0
    void OnSmartTriggerStay2D(SmartContactPoint smartContactPoint)
    {
        //NOTE: dot product will be 1 if collision in perpendicular and opposite facing direction and 0 if horizontal and < 0 if perpendicular but in the same direction as facing direction
        float      dot        = Vector3.Dot(transform.up, smartContactPoint.normal);
        GameObject playerCtrl = smartContactPoint.otherCollider.gameObject;
        bool       isPlayer   = playerCtrl.tag == "Player";

        //Debug.Log("dot: " + dot);
        //Debug.DrawRay(smartContactPoint.point, smartContactPoint.normal, Color.white, 3f);
        if (isPlayer)
        {
            // if dot > 0, the collision is with top side
            if (dot > SmartRectCollider2D.k_OneSideSlopeNormThreshold)
            {
                // Kill the enemy, add player impulse
                smartContactPoint.otherCollider.RigidBody2D.velocity = new Vector2(smartContactPoint.otherCollider.RigidBody2D.velocity.x, 0f);
                smartContactPoint.otherCollider.RigidBody2D.AddForce(5f * smartContactPoint.otherCollider.RigidBody2D.transform.up, ForceMode2D.Impulse);
                PlatformCharacterController platformCtrl = playerCtrl.GetComponent <PlatformCharacterController>();
                if (platformCtrl)
                {
                    platformCtrl.PlatformCharacterPhysics.Velocity = 2 * platformCtrl.JumpingSpeed * smartContactPoint.otherCollider.RigidBody2D.transform.up;
                }
                Kill();
            }
            else
            {
                playerCtrl.SendMessage("Kill", SendMessageOptions.DontRequireReceiver);
            }
        }
    }
示例#2
0
    /*
    void GameUpdate()
    {
        //check death
        if (heroInstance.transform.position.y < deathLimit)
        {
            //SceneManager.LoadScene("Main");
            //SetupGameoverState();
        }
    }
    */
    /*
    void PauseUpdate()
    {
        bool anykey = false;
#if UNITY_STANDALONE || UNITY_WEBPLAYER || UNITY_EDITOR
        anykey = Input.anyKeyDown;
#elif UNITY_IOS || UNITY_ANDROID
        if (Input.touchCount > 0){
            Touch myTouch = Input.touches[0];
            if (myTouch.phase == TouchPhase.Began)
                anykey = true;
        }
#endif
        if (anykey)
        {
            //spawn hero
            //SetCharacterVisible(true);
            InstantiateHero();
            gameOverText.gameObject.SetActive(false);
            InGameUI.SetActive(true);
            PauseOverlaySetActive(false);
            currentUpdate = GameUpdate;
            Time.timeScale = gameSpeed;
            score.Reset();

            bgm.PlayAudio(gameMusic);
        }
    }
    */
    /*
    void SetupGameoverState()
    {
        currentUpdate = PauseUpdate;
        Time.timeScale = 0;

        gameOverText.gameObject.SetActive(true);
        Text restartText = gameOverText.transform.Find("TapToRestart").gameObject.GetComponent<Text>();
        Text scoreValText = gameOverText.transform.Find("GOScoreVal").gameObject.GetComponent<Text>();
        Text hiScoreValText = gameOverText.transform.Find("GOHiScoreVal").gameObject.GetComponent<Text>();
        if (firstRun)
        {
            firstRun = false;
            gameOverText.text = "Go!";
            restartText.text = "Tap to start";
        }
        else
        {
            gameOverText.text = "Game Over";
            restartText.text = "Tap to restart";
        }
        scoreValText.text = score.GetScore().ToString();
        hiScoreValText.text = score.GetHiScore().ToString();

        InGameUI.SetActive(false);
        //SetCharacterVisible(false); 
        RemoveHero(); //destroy hero instance if created

        bgm.PlayAudio(menuMusic);
    }
    */
    /*
    private void SetCharacterVisible(bool visible)
    {
        if (visible)
        {
            heroInstance.transform.localScale = initialCharScale;
        }
        else
        {
            heroInstance.transform.localScale = Vector3.zero;
        }
    }
    */
    private void InstantiateHero()
    {
        Assert.IsNotNull(heroPrefab, "Character GameObject not set!");

        Transform hp = transform.Find("HeroSpawn");
        heroInstance = Instantiate<GameObject>(heroPrefab, hp.position, hp.rotation);
        initialCharScale = heroInstance.transform.localScale;

        //set score adding callback
        PlatformCharacterController pcc = heroInstance.GetComponent<PlatformCharacterController>();
        pcc.addScore = score.AddScore;
        pcc.ResetSpeed();
    }
示例#3
0
 private void ToggleAutoWalk(bool state)
 {
     autoWalk = state;
     for (int c = 0; c < characters.Length; c++)
     {
         WanderingAICharacterController comp = characters[c].GetComponent(typeof(WanderingAICharacterController)) as WanderingAICharacterController;
         comp.enabled = state;
         PlatformCharacterController comp2 = characters[c].GetComponent(typeof(PlatformCharacterController)) as PlatformCharacterController;
         comp2.enabled = !state;
     }
     if (state == false)
     {
         ToggleAutoSwitch(false);
     }
 }
示例#4
0
    void OnSmartCollisionStay2D(SmartCollision2D collision)
    {
        //NOTE: dot product will be 1 if collision in perpendicular and opposite facing direction and 0 if horizontal and < 0 if perpendicular but in the same direction as facing direction
        float dot = Vector3.Dot(transform.up, -collision.relativeVelocity);

        if (dot > 0)
        {
            m_fixedUpdatesToRemoveActivator = 4;
            m_rigidBody    = collision.rigidbody;
            m_rigidBody2D  = collision.rigidbody2D;
            m_platformCtrl = collision.gameObject.GetComponent <PlatformCharacterController>();
            if (!m_isActivated)
            {
                m_isActivated = true;
                Open.SetActive(!m_isActivated);
                Close.SetActive(m_isActivated);
                m_activationTime = ActivationTime;
                m_activator      = collision.gameObject;
                m_activatorPos   = new Vector2(0f, float.MaxValue);
            }
        }
    }
示例#5
0
 void Awake()
 {
     platformer = GetComponent<PlatformCharacterController>();
 }
	// Use this for initialization
	void Start () {
        player = GetComponent<PlatformCharacterController>();
	}
示例#7
0
 void Awake()
 {
     platformer = GetComponent <PlatformCharacterController>();
 }