Inheritance: MonoBehaviour
    void Update()
    {
        // 2 - Проверить, начался ли спавн врагов.
        if (hasSpawn == false)
        {
            if (ScrollingScript.IsVisibleFrom(GetComponent <Renderer>(), Camera.main))  //renderer.IsVisibleFrom(Camera.main)
            {
                Spawn();
            }
        }
        else
        {
            // автоматическая стрельба
            foreach (WeaponScript weapon in weapons)
            {
                if (weapon != null && weapon.enabled && weapon.CanAttack)
                {
                    weapon.Attack(true);
                    SoundEffectsHelper.Instance.MakeEnemyShotSound();
                }
            }

            // 4 – Выход за рамки камеры? Уничтожить игровой объект.
            if (!ScrollingScript.IsVisibleFrom(GetComponent <Renderer>(), Camera.main))
            {
                Destroy(gameObject);
            }
        }
    }
Example #2
0
    /// <summary>
    /// 射击
    /// </summary>
    /// <param name="isEnemy">是否是敌人的子弹</param>
    public void Attack(bool isEnemy)
    {
        if (CanAttack)
        {
            if (isEnemy)
            {
                //SoundEffectsHelper.Instance.MakeEnemyShotSound();
            }
            else
            {
                //SoundEffectsHelper.Instance.MakePlayerShotSound();
            }

            shootCooldown = shootingRate;

            // 创建一个子弹
            var shotTransform = Instantiate(shotPrefab) as Transform;

            // 指定子弹位置
            shotTransform.position = transform.position;

            // 设置子弹归属
            missileShot shot = shotTransform.gameObject.GetComponent <missileShot>();
            shot.isClone = true;

            // 设置子弹运动方向
            ScrollingScript move = shotTransform.gameObject.GetComponent <ScrollingScript>();
            if (move != null)
            {
                // towards in 2D space is the right of the sprite
                move.direction = this.transform.right;
            }
        }
    }
 private void Start()
 {
     MainText        = FindObjectOfType <ScrollingScript>();
     spriteTransform = GetComponent <Transform>();
     //Debug.Log("New Lead");
     //StartCoroutine(StartDropCooldown());
 }
Example #4
0
 void Start()
 {
     bg_script = GameObject.Find("0 - Background").GetComponent <ScrollingScript>();
     camera    = GameObject.Find("Main Camera").GetComponent <ScrollingScript>();
     stats     = GameObject.Find("4 - PlayerStats").GetComponent <ScrollingScript>();
     other     = this.gameObject.GetComponent <ScrollingScript>();
     animator  = this.GetComponent <Animator> ();
     //bg_scroll = GameObject.Find ("0 - Background");
 }
 private void Start()
 {
     scoreScript  = FindObjectOfType <ScoreScript>();
     ThisCollider = GetComponent <Collider2D>();
     Shakey       = FindObjectOfType <ScreenShake>();
     BGTimer      = FindObjectOfType <BackgroundTimingScript>();
     MainText     = FindObjectOfType <ScrollingScript>();
     player       = FindObjectOfType <AnimatiePlayer>();
     Controls     = FindObjectOfType <TouchControls>();
 }
Example #6
0
 // Start is called before the first frame update
 void Start()
 {
     for (int i = 0; i < CoroutineStarted.Length; i++)
     {
         CoroutineStarted[i] = false;
     }
     VisBackgroundTimer = GetComponent <RectTransform>();
     MainText           = FindObjectOfType <ScrollingScript>();
     CurrentCoroutine   = Filler();
 }
    IEnumerator changeDirection(ScrollingScript script)
    {
        float timer = 0;

        while (timer < timeUntilSwitch)
        {
            timer += Time.deltaTime;
            yield return null;
        }
        script.direction = newDirection;
        script.speed = cameraSpeed;
        Destroy (this.gameObject);
    }
    /// <summary>
    /// 创建敌人
    /// </summary>
    void CreateEnemy()
    {
        var enemyTransform = Instantiate(enemyPrefab) as Transform;

        enemyTransform.position         = new Vector3(Camera.main.transform.position.x + 40, Random.Range(-4, 4), 0);
        enemyTransform.transform.parent = transform;
        ScrollingScript move = enemyTransform.gameObject.GetComponent <ScrollingScript>();

        if (move != null)
        {
            move.direction.x = -1f;
            move.speed       = new Vector2(3, 3);
        }
    }
Example #9
0
    private void sendData()
    {
        AndroidJavaClass  unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject activity    = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity");

        activity.Call("setHighScore", ScrollingScript.getHeight(), PlayerCollisionScript.getKills());
        activity.Call("setPowerups", convertPowerups());
        activity.Call("addCoins", (PlayerCollisionScript.getKills() * 10) + ScrollingScript.getHeight());

        ParseObject scoreObject = new ParseObject("Highscore");

        scoreObject["UserName"]  = name;
        scoreObject["UserScore"] = ScrollingScript.getHeight();
        scoreObject.SaveAsync();
    }
Example #10
0
    void Awake()
    {
        distance        = defaultSpeed * timeLimit;
        toWayTimeLimit  = timeLimit * 2;
        initReverseTime = Time.time + 5;
        if (Instance != null)
        {
            Debug.LogError("Multiple instances of Difficulty!");
        }


        groundScrollingScript     = GameObject.Find("Ground").GetComponent <ScrollingScript>();
        backgroundScrollingScript = GameObject.Find("ScrollingBackground").GetComponent <ScrollingScript>();
        playerControl             = GameObject.Find("RunningPlayer").GetComponent <PlayerControls>();

        Instance = this;
    }
Example #11
0
    void Awake()
    {
        distance = defaultSpeed * timeLimit;
        toWayTimeLimit = timeLimit * 2;
        initReverseTime = Time.time + 5;
        if (Instance != null)
        {
            Debug.LogError("Multiple instances of Difficulty!");
        }


        groundScrollingScript = GameObject.Find("Ground").GetComponent<ScrollingScript>();
        backgroundScrollingScript = GameObject.Find("ScrollingBackground").GetComponent<ScrollingScript>();
        playerControl = GameObject.Find("RunningPlayer").GetComponent<PlayerControls>();

        Instance = this;
    }
Example #12
0
    public Vector3 moveFollowFrame( ScrollingScript target )
    {
        float newX = target.transform.position.x;
        float newZ = target.transform.position.z;
        float newY = 0.0f;

        if( _Direction > 0 ) {
            // move up, match bottom
            newY = target.transform.position.y - ( target.sizeHeight / 2 ) - ( this.sizeHeight / 2 );
        }
        else {
            // move down, match top
            newY = target.transform.position.y + ( target.sizeHeight / 2 ) + ( this.sizeHeight / 2 );
        }

        Vector3 newPos = new Vector3( newX, newY, newZ );
        movePosition( newPos );
        Debug.Log( "moveFllow to Y:" + newY );

        return newPos;
    }
Example #13
0
  void Start() {
	instance = this;
  }
Example #14
0
    void initScrolling()
    {
        // init all frames
        foreach( ScrollingScript frame in scrollings ) {

            //frame.gameObject.SetActive( false );
            //frame._Speed = this._Speed;
            frame._Speed = _Speed;
            frame._Direction = _Direction;
            frame.SetActive( false );
        }

        _currentScrolling = 0;
        _currentFrame = getFrame( _currentScrolling );
        // todo: determine init pos;
        float initPosX = 0;
        float initPosZ = 2;
        float initPosY = 0;

        if( _Direction > 0 ) {
            // move up
            initPosY = 0;
        }
        else {
            // move down
            initPosY = _currentFrame.sizeHeight / 2 - _screenUnitHeight;
        }

        _currentFrame.movePosition( new Vector3( initPosX, initPosY, initPosZ ) );
        _disapperPosY = _currentFrame.calcDisapperPosY( _screenUnitHeight );

        ScrollingScript nextFrame = getFrame( nextScrolling() );
        nextFrame.moveFollowFrame( _currentFrame );

        // active
        _currentFrame.SetActive( true );
        nextFrame.SetActive( true );

        //Transform tScrolling = scrolling.gameObject.transform;
        //tScrolling.position = new Vector3(0,0,2);

        Debug.Log ( "Manager initScrolling" );
    }
Example #15
0
 void Awake()
 {
     var difficulty = GameplayControl.Instance;
     scroll = GetComponent<ScrollingScript>();
 }
Example #16
0
    void OnGUI()
    {
        GUIStyle textStyle = new GUIStyle("label");

        textStyle.alignment = TextAnchor.MiddleCenter;
        textStyle.fontSize  = 80;
        textStyle.fontStyle = FontStyle.Bold;
        // Make a background box

        GUIStyle buttonStyle = new GUIStyle("button");

        buttonStyle.fontSize = 50;

        GUI.Box(new Rect(10, 10, Screen.width - 20, Screen.height - 20), "");

        GUI.Label(new Rect(Screen.width / 2 - 400, 50, 800, 150), "Summary", textStyle);

        GUIStyle centeredTextStyle = new GUIStyle("label");

        centeredTextStyle.alignment = TextAnchor.MiddleCenter;
        centeredTextStyle.fontSize  = 50;
        centeredTextStyle.fontStyle = FontStyle.Bold;

        GUI.Label(new Rect(Screen.width / 2 - 400, 150, 800, 150), "Height: " + ScrollingScript.getHeight(), centeredTextStyle);
        GUI.Label(new Rect(Screen.width / 2 - 400, 250, 800, 150), "Kills: " + PlayerCollisionScript.getKills(), centeredTextStyle);


        if (!FB.IsLoggedIn)
        {
            //GUI.Label((new Rect(179 , 11, 287, 160)), "Login to Facebook");
            if (GUI.Button(new Rect(Screen.width / 2 - 300, 400, 600, 130), "Login to Facebook", buttonStyle))
            {
                //FB.Login("email,publish_actions", LoginCallback);
            }
        }

        // Make the second button.
        else if (GUI.Button(new Rect(Screen.width / 2 - 200, 400, 400, 130), "Share", buttonStyle))
        {
            if (FB.IsLoggedIn)
            {
                /*FB.Feed(
                 *      linkCaption: "I just reached " + PlayerScript.distance + "! Can you beat it?",
                 *      picture: "http://www.friendsmash.com/images/logo_large.jpg",
                 *      linkName: "Checkout my Jumpy greatness!",
                 *      link: "http://apps.facebook.com/" + FB.AppId + "/?challenge_brag=" + (FB.IsLoggedIn ? FB.UserId : "guest")
                 *      );*/
            }
        }

        // Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
        if (GUI.Button(new Rect(Screen.width / 2 - 200, 550, 400, 130), "Restart", buttonStyle))
        {
            PlayerScript.distance = 0;
            Time.timeScale        = 1;

            Application.LoadLevel(0);
        }



        if (GUI.Button(new Rect(Screen.width / 2 - 200, 700, 400, 130), "Main Menu", buttonStyle))
        {
            Application.Quit();
        }
    }
Example #17
0
    void Update()
    {
        /*
        float Move = _Speed * Time.deltaTime;
        transform.Translate(Vector3.down * Move,Space.World);
        */

        /*
        if(transform.position.y<-20)
        {
            transform.position = new Vector3(transform.position.x,
                                             20,transform.position.z);
        }
        */

        if( _currentFrame ) {

            bool bDisapper = false;
            if( _Direction > 0 ) {
                // move up
                if( _currentFrame.transform.position.y > _disapperPosY ) {
                    bDisapper = true;
                }
            }
            else {
                // move down
                if( _currentFrame.transform.position.y < _disapperPosY ) {
                    bDisapper = true;
                }
            }

            if( bDisapper ) {

                // de-active disapper frame
                _currentFrame.SetActive( false );

                // link next frame
                _currentScrolling = nextScrolling();
                _currentFrame = getFrame( _currentScrolling );
                _disapperPosY = _currentFrame.calcDisapperPosY( _screenUnitHeight );

                ScrollingScript nextFrame = getFrame( nextScrolling() );
                nextFrame.moveFollowFrame( _currentFrame );

                // active next frame
                nextFrame.SetActive( true );
            }
        }
    }
    void Awake()
    {
        createBoxScript = GetComponent<CreateBoxScript>();
        uiScript = GameObject.Find("UI").GetComponent<UIScript>();
        score = GameObject.Find("Score").GetComponent<Score>();
        scrollingScript = GameObject.Find("2 - Middleground").GetComponent<ScrollingScript>();
        adsScript = GetComponent<AdsScript>();

        road = GameObject.Find("road");
        road1 = GameObject.Find("road1");
    }
Example #19
0
    void OnGUI()
    {
        if (hide)
        {
            Color c = TopFrame.renderer.material.color;
            c.a = 0;

            TopFrame.renderer.material.color = c;
        }
        else
        {
            Color c = TopFrame.renderer.material.color;
            c.a = 0.58f;

            TopFrame.renderer.material.color = c;
            GUI.contentColor = Color.white;
            GUIStyle style = new GUIStyle();
            style.fontSize         = 75;
            style.fontStyle        = FontStyle.Bold;
            style.normal.textColor = Color.white;
            GUI.Label(new Rect(39, 20, 300, 280), "Height: " + ScrollingScript.getHeight(), style);

            GUIStyle newStyle = new GUIStyle();
            newStyle.fontSize         = 30;
            newStyle.fontStyle        = FontStyle.Bold;
            newStyle.normal.textColor = Color.white;

            // Make a background box
            //GUI.Box(new Rect(10,10,100,90), "Loader Menu");

            // Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
            if (GUI.Button(new Rect(Screen.width - 110, 10, 100, 100), texture))
            {
                if (play)
                {
                    timeScale      = Time.timeScale;
                    Time.timeScale = 0;
                    play           = false;
                    texture        = playTexture;
                }
                else
                {
                    Time.timeScale = timeScale;
                    play           = true;
                    texture        = pauseTexture;
                }
            }

            List <Powerup> powerups = player.GetComponent <PlayerScript>().getPowerups();

            if (powerups[1].getQuantity() == 0)
            {
                GUI.color = Color.grey;
            }
            else
            {
                GUI.color = Color.white;
            }

            if (!btnTexture && showGUI)
            {
                if (GUI.Button(new Rect(Screen.width / 2 - 300, Screen.height - 150, 150, 150), "Click") && powerups[1].getQuantity() > 0)
                {
                    timeLeft = 10.0f;
                    showGUI  = false;
                    player.GetComponent <PlayerScript>().Supershooter();
                    powerups[1].use();
                }
            }
            else if (showGUI)
            {
                if (GUI.Button(new Rect(Screen.width / 2 - 300, Screen.height - 150, 150, 150), btnTexture) && powerups[1].getQuantity() > 0)
                {
                    timeLeft = 10.0f;
                    showGUI  = false;
                    player.GetComponent <PlayerScript>().Supershooter();
                    GameObject  shootSound = GameObject.Find("Sounds").transform.Find("Pow1").gameObject;
                    AudioSource ac         = shootSound.GetComponent <AudioSource>();
                    ac.audio.Play();
                    powerups[1].use();
                }
            }

            if (powerups[0].getQuantity() == 0)
            {
                GUI.color = Color.grey;
            }
            else
            {
                GUI.color = Color.white;
            }

            if (!btnTexture2 && showGUI)
            {
                if (GUI.Button(new Rect(Screen.width / 2 - 150, Screen.height - 150, 150, 150), "Click") && powerups[0].getQuantity() > 0)
                {
                    timeLeft = 10.0f;
                    showGUI  = false;
                    player.GetComponent <PlayerScript>().Slowdown(0.6f);
                    powerups[0].use();
                }
            }
            else if (showGUI)
            {
                if (GUI.Button(new Rect(Screen.width / 2 - 150, Screen.height - 150, 150, 150), btnTexture2) && powerups[0].getQuantity() > 0)
                {
                    timeLeft = 10.0f;
                    showGUI  = false;
                    player.GetComponent <PlayerScript>().Slowdown(0.6f);
                    GameObject  shootSound = GameObject.Find("Sounds").transform.Find("Pow2").gameObject;
                    AudioSource ac         = shootSound.GetComponent <AudioSource>();
                    ac.audio.Play();
                    powerups[0].use();
                }
            }

            if (powerups[2].getQuantity() == 0)
            {
                GUI.color = Color.grey;
            }
            else
            {
                GUI.color = Color.white;
            }

            if (!btnTexture3 && showGUI)
            {
                if (GUI.Button(new Rect(Screen.width / 2, Screen.height - 150, 150, 150), "Click") && powerups[2].getQuantity() > 0)
                {
                    timeLeft = 30.0f;
                    showGUI  = false;
                    gameGenerator.noenemies();
                    powerups[2].use();
                }
            }
            else if (showGUI)
            {
                if (GUI.Button(new Rect(Screen.width / 2, Screen.height - 150, 150, 150), btnTexture3) && powerups[2].getQuantity() > 0)
                {
                    timeLeft = 30.0f;
                    showGUI  = false;
                    gameGenerator.noenemies();
                    GameObject  shootSound = GameObject.Find("Sounds").transform.Find("Pow3").gameObject;
                    AudioSource ac         = shootSound.GetComponent <AudioSource>();
                    ac.audio.Play();
                    powerups[2].use();
                }
            }

            if (powerups[3].getQuantity() == 0)
            {
                GUI.color = Color.grey;
            }
            else
            {
                GUI.color = Color.white;
            }

            if (!btnTexture4 && showGUI)
            {
                if (GUI.Button(new Rect(Screen.width / 2 + 150, Screen.height - 150, 150, 150), "Click") && powerups[3].getQuantity() > 0)
                {
                    timeLeft = 15.0f;
                    showGUI  = false;
                    player.GetComponent <PlayerScript>().Indestructible();
                    powerups[3].use();
                }
            }
            else if (showGUI)
            {
                if (GUI.Button(new Rect(Screen.width / 2 + 150, Screen.height - 150, 150, 150), btnTexture4) && powerups[3].getQuantity() > 0)
                {
                    timeLeft = 15.0f;
                    showGUI  = false;
                    player.GetComponent <PlayerScript>().Indestructible();
                    GameObject  shootSound = GameObject.Find("Sounds").transform.Find("Pow1").gameObject;
                    AudioSource ac         = shootSound.GetComponent <AudioSource>();
                    ac.audio.Play();
                    powerups[3].use();
                }
            }
        }
    }
Example #20
0
    void Awake()
    {
        var difficulty = GameplayControl.Instance;

        scroll = GetComponent <ScrollingScript>();
    }
Example #21
0
 // Start is called before the first frame update
 void Start()
 {
     scrollSCript = this;
 }
Example #22
0
    void Update()
    {
        if (HS.hp > MaxHP * 3 / 4)
        {
            BodySprite.sprite = BossBodies[0];
        }
        else if (HS.hp > MaxHP / 2)
        {
            BodySprite.sprite = BossBodies[1];
        }
        else if (HS.hp > MaxHP / 4)
        {
            BodySprite.sprite = BossBodies[2];
        }
        else
        {
            BodySprite.sprite = BossBodies[3];
        }
        // Проверим появился ли враг
        if (hasSpawn == false)
        {
            // Для простоты проверим только первый рендерер
            // Но мы не знаем, если это тело, и глаз или рот ...
            if (ScrollingScript.IsVisibleFrom(renderers[0], Camera.main))
            {
                Spawn();
            }
        }
        else
        {
            // AI
            //------------------------------------
            // Перемещение или атака.
            aiCooldown -= Time.deltaTime;

            if (aiCooldown <= 0f)
            {
                isAttacking    = !isAttacking;
                aiCooldown     = Random.Range(minAttackCooldown, maxAttackCooldown);
                positionTarget = Vector2.zero;

                // Настроить или сбросить анимацию атаки
                animator.SetBool("Attack", isAttacking);
            }

            // Атака
            //----------
            if (isAttacking)
            {
                // Остановить все движения
                moveScript.direction = Vector2.zero;

                foreach (WeaponScript weapon in weapons)
                {
                    if (weapon != null && weapon.enabled && weapon.CanAttack)
                    {
                        weapon.Attack(true);
                        SoundEffectsHelper.Instance.MakeEnemyShotSound();
                    }
                }
            }
            // Перемещение
            //----------
            else
            {
                // Выбрать цель?
                if (positionTarget == Vector2.zero)
                {
                    // Получить точку на экране, преобразовать ее в цель в игровом мире
                    Vector2 randomPoint = new Vector2(Random.Range(0f, 1f), Random.Range(0f, 1f));

                    positionTarget = Camera.main.ViewportToWorldPoint(randomPoint);
                }

                // У нас есть цель? Если да, найти новую
                Collider2D col = GetComponent <Collider2D>();
                if (col.OverlapPoint(positionTarget))
                {
                    // Сбросить, выбрать в следующем кадре
                    positionTarget = Vector2.zero;
                }

                // Идти к точке
                Vector3 direction = ((Vector3)positionTarget - this.transform.position);

                // Помните об использовании скрипта движения
                moveScript.direction = Vector3.Normalize(direction);
            }
        }
    }
Example #23
0
    public void spawnObjects()
    {
        float curPoint = size.y;

        if (ScrollingScript.getHeight() >= newHeight)
        {
            if (inbetween && !ScrollingScript.isTransition)
            {
                nextPlatform = null;

                while (nextPlatform == null)
                {
                    if (cur == platforms.Capacity * 2)
                    {
                        cur = 0;
                    }

                    nextPlatform = platforms[(cur + 1) / 2];
                }

                if (started)
                {
                    background.GetComponent <ScrollingScript>().Transition((GameObject)Instantiate(backgrounds[cur]), (GameObject)Instantiate(backgrounds[cur + 1]));
                    lBackground.GetComponent <ScrollingScript>().Transition((GameObject)Instantiate(leftBackgrounds[cur]), (GameObject)Instantiate(leftBackgrounds[cur + 1]));
                    rBackground.GetComponent <ScrollingScript>().Transition((GameObject)Instantiate(rightBackgrounds[cur]), (GameObject)Instantiate(rightBackgrounds[cur + 1]));

                    cur++;
                    cur++;
                }

                combine = true;

                inbetween = !inbetween;
            }
            else if (!inbetween && !ScrollingScript.isTransition)
            {
                combine   = false;
                newHeight = ScrollingScript.getHeight() + 100;

                curPlatform = nextPlatform;
                enemyProb  *= 1.3f;

                PlayerScript.speed *= 1.1f;
                if (area < 8 && increase)
                {
                    area *= 1.2f;

                    if (area > 8)
                    {
                        area    /= 1.2f;
                        increase = false;
                    }
                    lowerArea += 0.1f;
                }

                inbetween = !inbetween;

                if (!increase)
                {
                    enemyProb *= 1.3f;
                }
            }
        }

        GameObject platform = curPlatform;

        while (true)
        {
            curPoint += Random.Range(lowerArea, area) + platform.renderer.bounds.size.y;

            if (curPoint > size.y * 2)
            {
                break;
            }

            if (combine)
            {
                int n = Random.Range(0, 2);

                if (n == 0)
                {
                    platform = curPlatform;
                }
                else
                {
                    platform = nextPlatform;
                }
            }

            maxObj = (GameObject)Instantiate(platform, new Vector3(Random.Range(-size.x + platform.renderer.bounds.size.x / 2, size.x - platform.renderer.bounds.size.x / 2), curPoint), Quaternion.identity);

            if (Random.Range(0f, 1f) < enemyProb && hasEnemies)
            {
                GameObject enemy      = enemies[Random.Range(0, enemies.Count)];
                Transform  enemyChild = enemy.transform.GetChild(0);
                GameObject e          = (GameObject)Instantiate(enemy, new Vector3(maxObj.transform.position.x, maxObj.transform.position.y + enemyChild.renderer.bounds.size.y / 2, enemy.transform.position.z), Quaternion.identity);
                e.transform.parent = enemyHolder.transform;
            }
        }
    }