Inheritance: MonoBehaviour
示例#1
0
	// Use this for initialization
	void Start () {
		//Enemy killed counter initialisation
		text = GetComponentInChildren<Text>();
		text.text = ("Enemies killed : " + enemiesKilled);
		GameObject player = GameObject.FindGameObjectWithTag("Player");
		health = player.GetComponent<HealthScript>();
		playerHealth = health.health;
		totalHealth = playerHealth;
		weapon = player.GetComponent<WeaponController>();
		skill = player.GetComponent<SkillController>();

		GameObject skills = GameObject.Find("Skills");
		//skills.gameObject.
		GameObject bullet = GameObject.Find("Bullet");
		bulletCooldownBar = bullet.GetComponentInChildren<RectTransform>();
		bulletCooldownBar = bulletCooldownBar.FindChild("Cooldown") as RectTransform;
		GameObject secondary = GameObject.Find("Secondary");
		secondaryCooldownBar = secondary.GetComponentInChildren<RectTransform>();
		secondaryCooldownBar = secondaryCooldownBar.FindChild("Cooldown") as RectTransform;
		GameObject dodge = GameObject.Find("Dodge");
		dodgeCooldownBar = dodge.GetComponentInChildren<RectTransform>();
		dodgeCooldownBar = dodgeCooldownBar.Find("Cooldown") as RectTransform;

		Image healthBarImage = GetComponentInChildren<Image>();
		healthBar = healthBarImage.gameObject.GetComponent<RectTransform>();
	}
示例#2
0
 // Use this for initialization
 void Start()
 {
     movement = this.gameObject.transform.position;
     health = this.GetComponent<HealthScript>();
     weapons = GetComponentsInChildren<WeaponScript>();
     health.hp = 1000;
 }
示例#3
0
    void Start()
    {
        player = (GameObject) GameObject.FindWithTag ("Player");
        playerHealth = (HealthScript) player.GetComponent(typeof(HealthScript));
        router = (GameObject) GameObject.FindWithTag("Router");
        variableScript = (VariableScript) router.GetComponent( typeof(VariableScript) );

        tgtm = (ThinkGearTestManager) router.GetComponent( typeof(ThinkGearTestManager) );
    }
示例#4
0
 void Awake()
 {
     coins = 0;
     bullets = 0;
     shield = 0;
     healthScript = GetComponent<HealthScript>();
     health = Settings.health;
     shieldSlider.value = shield;
 }
 // Use this for initialization
 void Start () {
     _axeRes = Resources.Load("Battle_axe") as GameObject;
     Debug.Log(_axeRes);
     _mover = GetComponent<MoveScript>();
     _anim = GetComponent<Animator>();
     _health = GetComponent<HealthScript>();
     _anim.SetFloat("SpeedX", 0);
     _anim.SetFloat("SpeedY", -1);
 }
示例#6
0
    void Awake()
    {
        // Retrieve the weapon only once
        weapons = GetComponentsInChildren<WeaponScript>();

        // Retrieve scripts to disable when not spawn
        moveScript = GetComponent<MoveScript>();
        healthScript = GetComponent<HealthScript>();
        animator = GetComponent<Animator>();
    }
示例#7
0
    void Awake()
    {
        // Vi hämtar en referens till Healtht-scriptet som också ligger på det här objektet (titta på Player i scenen)
        controller = GetComponent<HealthScript>();

        lifeCounter = new Rect(
                               -50, 								// Placering på skärmen, i sidled
                               Screen.height - 60, 				// Här använder vi helt enkelt hela skärmhöjden minus texthöjden, eftersom olika skärmar är olika stora
                               100, 							// Rektangelns bredd
                               20		 						// Rektangelns höjd
                               );
    }
 // Use this for initialization
 void Start()
 {
     ThePlayer = this.gameObject;
     rb2D = this.GetComponent<Rigidbody2D>();
     HealthController = this.GetComponent<HealthScript>();
     MoveController = this.GetComponent<ActorMoveScript>();
     JumpController = this.GetComponent<ActorJumpScript>();
     AttackController = this.GetComponent<ActorAttackScript>();
     GroundCheck = GameObject.Find(this.name + "/GroundCheck").transform;
     WallCheck = GameObject.Find(this.name + "/WallCheck").transform;
     Anim = GetComponent<Animator>();
 }
示例#9
0
    // Update is called once per frame
    void Update()
    {
        if(gameTimer!=null){
            smokeTimer = (int)gameTimer.GetComponent<GameTimer>().secStackValue;
            if(colliderHeight.y>=0.54f){
                StartCoroutine("fillingRoom");
            }//end of if
        }//if not null timer

        if(HPBar!=null){
            hp = HPBar.GetComponent<HealthScript>();
        }//get hp
    }
示例#10
0
    // Use this for initialization
    void Start()
    {

        player1 = GameObject.FindGameObjectWithTag("Player");
        player2 = GameObject.FindGameObjectWithTag("Player2");
        Wall1 = GameObject.FindGameObjectWithTag("Wall1");
        Wall2 = GameObject.FindGameObjectWithTag("Wall2");
        playerScript = gameObject.GetComponent<HealthScript>();
        enemyScript = gameObject.GetComponent<EnemyHealth>();
        armorScript = gameObject.GetComponent<WallHealth>();
        anim = GetComponent<Animator>();

    }
	// Only will call Attach when this method is called
	public void ArmHitt(Collision2D coll){

		if (coll.gameObject.CompareTag("Core") && coll.collider.gameObject.CompareTag("Circle") || 
			coll.collider.gameObject.CompareTag("Core")){

			transform.parent = coll.collider.gameObject.transform;

			GetComponent<Rigidbody2D>().isKinematic = true;

			coll.collider.gameObject.GetComponent<HealthScript>().OnDeath += SetKinematicFalse;

			hScript = coll.collider.gameObject.GetComponent<HealthScript>();
		}
	}
示例#12
0
    private HealthScript targetHealthScript; // The target's health script

    #endregion Fields

    #region Methods

    protected override void ApplyEffect()
    {
        // Apply damage to the target (will happen once per tick)

        if(target) {
            // Check if target is still alive
            targetHealthScript = target.GetComponent<HealthScript>();	// Damage() is part of HealthScript

            targetHealthScript.Damage(amount);	// Apply damage to the target (mitigation is handled by HealthScript)
        }
        else {
            // Target is dead, get rid of the DoT
            base.EndEffect();
        }
    }
示例#13
0
    // Use this for initialization
    void Start()
    {
        // Find character by searching parent's character script
        character = transform.parent.GetComponent<CharacterScript>();
        if(character) {
            // Assuming character exists)
            health = character.GetComponent<HealthScript>();

            maxHp = health.hp;	// HP when mob spawns is assumed to be the total hp it can have
        }

        // Find current HP bar
        currentHPBar = transform.GetComponentInChildren<GUITexture>();
        currentHPBar.transform.localScale = Vector3.zero;	// Zero-out the scale vector to allow us to manipulate it later
    }
示例#14
0
    void DealDamage(HealthScript health)
    {
        if (health != null && health.isEnemy != isEnemy && !damaged.Contains(health)) {
            // Can only damage each healthScript once (per damage/attack)
            damaged.Add(health);

            // Deal the damage
            health.ModifyHealth(-damage);

            // Send messages
            /*
            health.SendMessage("TookDamage", this, SendMessageOptions.DontRequireReceiver);
            SendMessage("DealtDamage", this, SendMessageOptions.DontRequireReceiver);
            */
        }
    }
示例#15
0
 void Awake()
 {
     hpScript = GetComponent<HealthScript> ();
     sprite = GetComponent<SpriteRenderer> ();
     player = GameObject.FindGameObjectWithTag ("Player");
     WorldGen = GameObject.Find ("WorldGenerator").GetComponent<WorldGenerator>();
     float size = Random.Range (minSize, maxSize);
     float torque = Random.Range (minTorque, maxTorque);
     float force = Random.Range (minForce, maxForce);
     transform.Rotate(0.0f, 0.0f, Random.Range(0.0f, 360.0f));
     transform.localScale = new Vector3 (size, size, size);
     rb = GetComponent<Rigidbody2D> ();
     rb.mass = size * 2000;
     rb.AddTorque (torque, ForceMode2D.Impulse);
     rb.AddForce (transform.up * force, ForceMode2D.Impulse);
     hpScript.maxHp = Mathf.RoundToInt(30 * size);
     hpScript.hp = Mathf.RoundToInt(hpScript.maxHp - Random.Range (0, hpScript.maxHp));
 }
示例#16
0
    private void Awake()
    {
        healthScript = GetComponent<HealthScript>();
        animator = GetComponent<Animator>();
        pHP = GetComponent<PlayerHealth> ();

        GameObject gameDirectorObject = GameObject.FindWithTag ("GameController");

        if (gameDirectorObject != null)
        {
            gameDirector = gameDirectorObject.GetComponent<GameDirector>();
        }
        else
        {
            Debug.Log("Cannot find 'Game Director Script' ");
        }

        gameDirector = GetComponent<GameDirector> ();

        circuleCollider = gameObject.collider2D as CircleCollider2D;
    }
示例#17
0
    public static DamageScript SpawnDamage(Vector3 position, float radius, int damage, HealthScript source)
    {
        // Create the object
        var damageObject = new GameObject("Damage");
        damageObject.transform.position = position;

        // Add components
        var circleCollider = damageObject.AddComponent<CircleCollider2D>();
        var damageScript = damageObject.AddComponent<DamageScript>();
        var body = damageObject.AddComponent<Rigidbody2D>();

        // Init components
        circleCollider.radius = radius;
        circleCollider.isTrigger = true;
        damageScript.source = source;
        damageScript.damage = damage;
        body.gravityScale = 0;

        // Return referance
        return damageScript;
    }
示例#18
0
    // Use this for initialization
    void Start()
    {
        Player = (GameObject) GameObject.FindWithTag ("Player");
        //playerScript = (PlayerScript) Player.gameObject.GetComponent(typeof(PlayerScript));
        playerHealth = (HealthScript) Player.gameObject.GetComponent(typeof(HealthScript));
        gameTime = 0;

        //if (WithPortal)
        //	portalScript = (PortalScript) Portal.GetComponent(typeof(PortalScript));

        //tgtm = (ThinkGearTestManager) this.GetComponent(typeof(ThinkGearTestManager));

        PlayerFireSFX = (GameObject) GameObject.Find("PlayerFireSFX");

        GameObject EnemyNormalDestroySFX = (GameObject) GameObject.Find("EnemyNormalDestroySFX");
        GameObject EnemyShooterDestroySFX = (GameObject) GameObject.Find("EnemyShooterDestroySFX");
        GameObject EnemyShooterFireSFX = (GameObject) GameObject.Find("EnemyShooterFireSFX");
        //EnemyNormalDestroySFX = (GameObject)Instantiate(EnemyNormalDestroySFXScript );

        TextReader tr = new StreamReader("D:/Computer Science/Thesis/TestThings.txt");
        tgtm.setFileName(tr.ReadLine() + LevelNumber);
        tgtm.setFilePath(tr.ReadLine());
    }
    void Update()
    {
        if (Input.GetButtonDown("Cancel"))
        {
            #if UNITY_EDITOR
            UnityEditor.EditorApplication.isPlaying = false;
            #elif UNITY_WEBPLAYER
            Application.OpenURL(webplayerQuitURL);
            #else
            Application.Quit();
            #endif
        }


        playerController PC = gameObject.GetComponent <playerController>();

        if (Input.GetButtonDown("Interact") && !PC.isMoving)
        {
            GameObject doorOpen = InRangeOfInteract("Door");
            GameObject Stairs   = InRangeOfInteract("Stairs");
            GameObject Ladder   = InRangeOfInteract("Ladder");
            GameObject Sign     = InRangeOfInteract("Sign");

            if (Ladder != null)
            {
                GameObject[] enemyCount = GameObject.FindGameObjectsWithTag("Enemies"); //Checks if all enemies are killed before going to next level.
                if (enemyCount.Length == 0)
                {
                    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
                }
                else
                {
                    Debug.Log("Need this many enemies to kill: " + enemyCount.Length);
                }
            }

            else if (Stairs != null)
            {
                ChangeLevel  levelChange = Stairs.GetComponent <ChangeLevel>();
                HealthScript HS          = gameObject.GetComponent <HealthScript>();
                Transform    newArea     = levelChange.areaLocation.GetChild("Location").transform;
                gameObject.transform.position = new Vector3(newArea.position.x + 1, newArea.position.y + 0.1f, newArea.position.z);
                HS.respawnPoint = gameObject.transform.position;
                Stairs          = null;
            }


            else if (doorOpen != null)
            {
                if (doorOpen.GetChild("Door Closed").activeSelf)       //ef hurðin er lokuð
                {
                    doorOpen.GetChild("Door Closed").SetActive(false); // setur lokuðu hurðina sem ekki active
                    doorOpen.GetChild("Door Open").SetActive(true);    // setur opnuðu hurðina sem active
                }
                else if (!doorOpen.GetChild("Door Closed").activeSelf) // ef hurðin er opin
                {
                    doorOpen.GetChild("Door Open").SetActive(false);   // setur opnuðu hurðina sem ekki active
                    doorOpen.GetChild("Door Closed").SetActive(true);  // setur lokuðu hurðina sem active
                }
            }

            else if (Sign != null)
            {
                if (!Sign.GetChild("SignCanvas").activeInHierarchy)
                {
                    Sign.GetChild("SignCanvas").SetActive(true);
                }
                else
                {
                    Sign.GetChild("SignCanvas").SetActive(false);
                }
            }
        }
    }
示例#20
0
 // Use this for initialization
 void Start()
 {
     m_instance = this;
     HealthBar  = GameObject.Find("HealthBar").GetComponent <Image> ();
     SetHealth(maxHealth);
 }
示例#21
0
    // Update is called once per frame
    void Update()
    {
        // TODO: 尝试每5帧计算一次,提高效率

        /*
         * if (!isPending && !isEnemyTurn && Input.GetMouseButtonDown (0)) {
         *      mouse_clicked = true;
         * } else if (mouse_clicked && Input.GetMouseButtonUp (0)) {
         *      mouse_clicked = false;
         * }
         * if (frameCounter < 4) {
         *      frameCounter += 1;
         *      return;
         * }
         * frameCounter = 0;
         */

        // 等待对手消息中 ...
        if (!isOperating)
        {
            return;
        }

        arrowEnd = Input.mousePosition;
        Vector2 dir = arrowStart - arrowEnd;
        float   len = Vector2.Distance(arrowStart, arrowEnd);

        if (len > arrowMaxLen)
        {
            dir.x    = dir.x * arrowMaxLen / len;
            dir.y    = dir.y * arrowMaxLen / len;
            arrowEnd = arrowStart + dir;
        }
        arrowEnd = arrowStart + dir;

        //if (!isPending && Input.GetMouseButtonDown (0)) {
        if (Input.GetMouseButtonDown(0))
        {
            hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
            if (hit)
            {
                //ts_mouse_start = System.DateTime.Now;
                ball = GameObject.Find(hit.transform.name);
                HealthScript hs = ball.GetComponent <HealthScript> ();
                if (hs.isEnemy != isEnemyTurn)
                {
                    return;
                }

                mouse_clicked = true;
                // 只在当前小球靠近屏幕边缘的时候调整camera
                savedPos = Camera.main.transform.position;
                Vector2 ballPos = ball.transform.position;
                //float newX, newY;
                if (ballPos.x < bgWidth * (-0.6f) / 200.0f || ballPos.x > bgWidth * 0.6f / 200.0f ||
                    ballPos.y < bgHeight * (-0.6f) / 200.0f || ballPos.y > bgWidth * 0.6f / 200.0f)
                {
                    //Camera.main.orthographicSize = cameraSize / 1.5f;
                    Camera.main.transform.position = new Vector3(ball.transform.position.x, ball.transform.position.y, -10);
                }

                arrowStart  = Camera.main.WorldToScreenPoint(ball.transform.position);
                startVertex = new Vector3(arrowStart.x / Screen.width, arrowStart.y / Screen.height, 0);
                arrowEnd    = arrowStart;
            }
        }

        if (mouse_clicked && Input.GetMouseButtonUp(0))
        {
            mouse_clicked = false;

            Camera.main.transform.position = savedPos;
            //Camera.main.orthographicSize = cameraSize;

            // 将用户操作发送到
            int actor  = int.Parse(ball.transform.name.ToCharArray()[4].ToString());
            int forceX = (int)(dir.x * forceFactor);
            int forceY = (int)(dir.y * forceFactor);
            //sendMove(actor, forceX, forceY);
            ball.GetComponent <HealthScript> ().Attack(new Vector2(forceX, forceY));
            isPending = true;                   // 等待actor运动结束

            // 发送操作给slave
            client.sendMove(actor, forceX, forceY);
            isWaiting   = true;
            isOperating = false;
        }
    }
示例#22
0
 // Use this for initialization
 void Start()
 {
     //reference
     health = FindObjectOfType <HealthScript>();
     score  = FindObjectOfType <ScoreScript>();
 }
示例#23
0
 private void  attack(HeroScript cible)
 {
     health = cible.GetComponent <HealthScript>();
     health.Damage(arme.degat);
 }
示例#24
0
    void ShowGUI(int windowID)
    {
        bool         damagePlayer = false;
        HealthScript playerHealth = this.GetComponent <HealthScript> ();

        switch (i)
        {
        case 0:
            GUI.Label(new Rect(30, 40, 250, 500), "¿A que se debe la forma peculiar de un ferrofluido?\n [A] Las lineas del campo magnetico\n [B] Gravedad\n [C] Temperatura\n");
            if (GUI.Button(new Rect(70, 175, 40, 30), "A"))
            {
                correct_answer = 1;
                i++;
            }
            else
            if (GUI.Button(new Rect(120, 175, 40, 30), "B"))
            {
                correct_answer = 0;
                clicks++;
                if (playerHealth != null)
                {
                    playerHealth.Damage(4, respawnPosX, respawnPosY, false);
                }
                if (clicks == 3)
                {
                    showPopUp    = false;
                    maxSpeed     = 30;
                    anim.enabled = true;
                    clicks       = 0;
                }
            }
            else
            if (GUI.Button(new Rect(170, 175, 40, 30), "C"))
            {
                correct_answer = 0;
                clicks++;
                if (playerHealth != null)
                {
                    playerHealth.Damage(4, respawnPosX, respawnPosY, false);
                }
                if (clicks == 3)
                {
                    showPopUp    = false;
                    maxSpeed     = 30;
                    anim.enabled = true;
                    clicks       = 0;
                }
            }
            break;

        case 1:
            GUI.Label(new Rect(30, 40, 250, 500), "¿Que es un ferrofluido?\n [A] Un liquido que no se polariza en un campo magnetico\n [B] Un liquido que repele el agua\n [C] Un liquido que se polariza en un campo magnetico\n");
            if (GUI.Button(new Rect(70, 175, 40, 30), "A"))
            {
                correct_answer = 0;
                clicks++;
                if (playerHealth != null)
                {
                    playerHealth.Damage(4, respawnPosX, respawnPosY, false);
                }
                if (clicks == 3)
                {
                    showPopUp    = false;
                    maxSpeed     = 30;
                    anim.enabled = true;
                    clicks       = 0;
                }
            }
            else
            if (GUI.Button(new Rect(120, 175, 40, 30), "B"))
            {
                correct_answer = 0;
                clicks++;
                if (playerHealth != null)
                {
                    playerHealth.Damage(4, respawnPosX, respawnPosY, false);
                }
                if (clicks == 3)
                {
                    showPopUp    = false;
                    maxSpeed     = 30;
                    anim.enabled = true;
                    clicks       = 0;
                }
            }
            else
            if (GUI.Button(new Rect(170, 175, 40, 30), "C"))
            {
                correct_answer = 1;
                i++;
            }
            break;

        case 2:
            GUI.Label(new Rect(30, 40, 250, 500), "¿Como los ferrofluidos ayudan a combatir el cancer?\n [A] Los ferrofluidos no son capaces de combatir el cancer\n [B] Quimeoterapia usando ferrofluidos\n [C] Utilizando una tecnica llamada cocinar el tumor\n");
            if (GUI.Button(new Rect(70, 175, 40, 30), "A"))
            {
                correct_answer = 0;
                clicks++;
                if (playerHealth != null)
                {
                    playerHealth.Damage(4, respawnPosX, respawnPosY, false);
                }
                if (clicks == 3)
                {
                    showPopUp    = false;
                    maxSpeed     = 30;
                    anim.enabled = true;
                    clicks       = 0;
                }
            }
            else
            if (GUI.Button(new Rect(120, 175, 40, 30), "B"))
            {
                correct_answer = 0;
                clicks++;
                if (playerHealth != null)
                {
                    playerHealth.Damage(4, respawnPosX, respawnPosY, false);
                }
                if (clicks == 3)
                {
                    showPopUp    = false;
                    maxSpeed     = 30;
                    anim.enabled = true;
                    clicks       = 0;
                }
            }
            else
            if (GUI.Button(new Rect(170, 175, 40, 30), "C"))
            {
                correct_answer = 1;
                i++;
            }
            break;

        case 3:
            GUI.Label(new Rect(30, 40, 250, 500), "¿Que le pasa a un iman y un metal si se le aplica ferrofluido?\n [A] Aumenta la friccion\n [B] Disminuye la friccion\n [C] Se queda igual\n");
            if (GUI.Button(new Rect(70, 175, 40, 30), "A"))
            {
                correct_answer = 0;
                clicks++;
                if (playerHealth != null)
                {
                    playerHealth.Damage(4, respawnPosX, respawnPosY, false);
                }
                if (clicks == 3)
                {
                    showPopUp    = false;
                    maxSpeed     = 30;
                    anim.enabled = true;
                    clicks       = 0;
                }
            }
            else
            if (GUI.Button(new Rect(120, 175, 40, 30), "B"))
            {
                correct_answer = 1;
                i++;
            }
            else
            if (GUI.Button(new Rect(170, 175, 40, 30), "C"))
            {
                correct_answer = 0;
                clicks++;
                if (playerHealth != null)
                {
                    playerHealth.Damage(4, respawnPosX, respawnPosY, false);
                }
                if (clicks == 3)
                {
                    showPopUp    = false;
                    maxSpeed     = 30;
                    anim.enabled = true;
                    clicks       = 0;
                }
            }
            break;

        case 4:
            GUI.Label(new Rect(30, 40, 250, 500), "¿En que parte de los robots se utiliza ferrofluidos?\n [A] La cabeza\n [B] Las coyunturas\n [C] El cuello\n");
            if (GUI.Button(new Rect(70, 175, 40, 30), "A"))
            {
                correct_answer = 0;
                clicks++;
                if (playerHealth != null)
                {
                    playerHealth.Damage(4, respawnPosX, respawnPosY, false);
                }
                if (clicks == 3)
                {
                    showPopUp    = false;
                    maxSpeed     = 30;
                    anim.enabled = true;
                    clicks       = 0;
                }
            }
            else
            if (GUI.Button(new Rect(120, 175, 40, 30), "B"))
            {
                correct_answer = 1;
                i++;
            }
            else
            if (GUI.Button(new Rect(170, 175, 40, 30), "C"))
            {
                correct_answer = 0;
                clicks++;
                if (playerHealth != null)
                {
                    playerHealth.Damage(4, respawnPosX, respawnPosY, false);
                }
                if (clicks == 3)
                {
                    showPopUp    = false;
                    maxSpeed     = 30;
                    anim.enabled = true;
                    clicks       = 0;
                }
            }
            break;

        case 5:
            showPopUp = false;
            break;
        }
    }
示例#25
0
 void Update()
 {
     script = NPC.GetComponentInChildren <HealthScript>() as HealthScript;
     text   = "HP: " + script.currentHealth;
 }
示例#26
0
    // Update is called once per frame
    void Update()
    {
        // TODO: 尝试每5帧计算一次,提高效率

        /*
         *      if (!isPending && !isEnemyTurn && Input.GetMouseButtonDown (0)) {
         *              mouse_clicked = true;
         *      } else if (mouse_clicked && Input.GetMouseButtonUp (0)) {
         *              mouse_clicked = false;
         *      }
         *      if (frameCounter < 4) {
         *              frameCounter += 1;
         *              return;
         *      }
         *      frameCounter = 0;
         */
        arrowEnd = Input.mousePosition;
        Vector2 dir = arrowStart - arrowEnd;
        //float angle = Vector2.Angle(dir, new Vector2(1, 0));
        float len = Vector2.Distance(arrowStart, arrowEnd);

        if (len > arrowMaxLen)
        {
            dir.x    = dir.x * arrowMaxLen / len;
            dir.y    = dir.y * arrowMaxLen / len;
            arrowEnd = arrowStart + dir;
        }
        arrowEnd = arrowStart + dir;

        //if (!isPending && !isEnemyTurn && Input.GetMouseButtonDown (0)) {
        if (!isPending && Input.GetMouseButtonDown(0))
        {
            hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
            if (hit)
            {
                //ts_mouse_start = System.DateTime.Now;
                ball = GameObject.Find(hit.transform.name);
                HealthScript hs = ball.GetComponent <HealthScript>();
                if (!hs || hs.isEnemy != isEnemyTurn)
                {
                    return;
                }

                hs.mouseAudio.PlayOneShot(hs.mouseSelect, 1f);
                mouse_clicked = true;
                // 只在当前小球靠近屏幕边缘的时候调整camera
                savedPos = Camera.main.transform.position;
                Vector2 ballPos = ball.transform.position;
                //float newX, newY;
                if (ballPos.x < bgWidth * (-0.6f) / 200.0f || ballPos.x > bgWidth * 0.6f / 200.0f ||
                    ballPos.y < bgHeight * (-0.6f) / 200.0f || ballPos.y > bgWidth * 0.6f / 200.0f)
                {
                    //Camera.main.orthographicSize = cameraSize / 1.5f;
                    Camera.main.transform.position = new Vector3(ball.transform.position.x, ball.transform.position.y, -10);
                }

                arrowStart  = Camera.main.WorldToScreenPoint(ball.transform.position);
                startVertex = new Vector3(arrowStart.x / Screen.width, arrowStart.y / Screen.height, 0);
                arrowEnd    = arrowStart;
            }
        }

        // 暂时并未使用

        /*
         *      if (mouse_clicked && !playerReady) {
         *              //Vector2 p = Input.mousePosition;
         *              Vector2 p = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         *              ball.transform.position = new Vector3(p.x, p.y, -5);
         *      }
         */

        if (mouse_clicked && Input.GetMouseButtonUp(0))
        {
            mouse_clicked = false;
            //if (playerReady && enemyReady) { // if battle started

            dir.x = dir.x * forceFactor;
            dir.y = dir.y * forceFactor;

            Camera.main.transform.position = savedPos;
            //Camera.main.orthographicSize = cameraSize;
            //itemGenerator.clearPosition(ball.transform.position);
            ball.GetComponent <HealthScript>().Attack(dir);
            isPending = true;
            //}
        }
    }
示例#27
0
    void newRound(bool withStatic)
    {
        // 检查道具效果是否到期,如果到期则取消
        GameObject[] playerActors = GameObject.FindGameObjectsWithTag("player");
        foreach (GameObject a in playerActors)
        {
            HealthScript hs = a.GetComponent <HealthScript>();
            if (hs.attackEnhanceTurnLeft > 0)
            {
                hs.attackEnhanceTurnLeft -= 1;
                if (hs.attackEnhanceTurnLeft == 0)
                {
                    hs.attack = 0;
                    hs.animator.SetBool("isFire", false);
                }
            }
        }

        GameObject[] enemyActors = GameObject.FindGameObjectsWithTag("enemy");
        foreach (GameObject a in enemyActors)
        {
            HealthScript hs = a.GetComponent <HealthScript>();
            if (hs.attackEnhanceTurnLeft > 0)
            {
                hs.attackEnhanceTurnLeft -= 1;
                if (hs.attackEnhanceTurnLeft == 0)
                {
                    hs.attack = 0;
                    hs.animator.SetBool("isFire", false);
                }
            }
        }

        // 检查道具是否过期
        GameObject[] itemObjects = GameObject.FindGameObjectsWithTag("items");
        foreach (GameObject a in itemObjects)
        {
            ItemScript iScript = a.GetComponent <ItemScript> ();
            if (iScript == null)
            {
                Debug.Log("not an item: " + a);
                continue;
            }
            if (iScript.isStatic)
            {
                continue;
            }
            iScript.availableTurnsLeft -= 1;
            if (iScript.availableTurnsLeft == 0)
            {
                Destroy(a);
            }
        }

        // 随机生成新的道具
        int i = withStatic ? 0 : nStaticItems;

        for (; i < itemProb.Length; i++)
        {
            int p = Random.Range(0, 100);
            if (p >= itemProb[i])
            {
                continue;
            }

            itemObjects = GameObject.FindGameObjectsWithTag("items");

            int outX, outY;
            while (!randomPos(1.2f, playerActors, enemyActors, itemObjects, out outX, out outY))
            {
                ;
            }
            Vector2   pos        = new Vector2(outX / 10.0f, outY / 10.0f);
            Transform iTransform = Instantiate(itemPrefabs[i]);
            iTransform.position = pos;
        }
    }
    void Start()
    {
        TimeStartSpawn = Time.realtimeSinceStartup;
        if (XkGameCtrl.PlayerActiveNum > 0)
        {
            GetAimPlayerMoveScript();
        }

        foreach (var item in SpawnAmmoPoint)
        {
            item.gameObject.SetActive(true);
        }

        if (AudioCannonFire != null)
        {
            AudioCannonFire.Stop();
        }

        if (SpawnAmmoPoint.Length <= 0)
        {
            //Debug.LogWarning("Unity:"+"XKCannonCtrl -> SpawnAmmoPoint was wrong!");
        }
        else
        {
            for (int i = 0; i < SpawnAmmoPoint.Length; i++)
            {
                if (SpawnAmmoPoint[i] == null)
                {
                    Debug.LogWarning("Unity:" + "XKCannonCtrl -> SpawnAmmoPoint was wrong! index = " + i);
                    IsOutputError = true;
                    break;
                }
            }
        }
        CosAngleUp   = Mathf.Cos((UpPaoGuanJDVal / 180f) * Mathf.PI);
        CosAngleDown = Mathf.Cos((DownPaoGuanJDVal / 180f) * Mathf.PI);

        CannonTran = transform;
        if (HealthScript == null)
        {
            HealthScript = GetComponent <XKNpcHealthCtrl>();
        }

        if (HealthScript != null)
        {
            HealthScript.SetCannonScript(this, false);
            IsYouTongNpc = HealthScript.IsYouTongNpc;
        }

        if (SpawnAmmoPoint.Length > 1)
        {
            IsDouGuanDaPao = true;
        }
        InitNpcAmmoList();

        NpcMoveScript = GetComponentInParent <XKNpcMoveCtrl>();
        if (IsOutputError)
        {
            GameObject obj = null;
            obj.name = "null";
        }
    }
示例#29
0
 public override void OnStateEnter(Transform player, GameObject self)
 {
     curHealthScript = self.GetComponent <BaseEnemy>().healthScript;
     rotSpeed        = self.GetComponent <BaseEnemy>().rotationSpeed;
     self.GetComponent <BaseEnemy>().spawnerScript.shoot = true;
 }
示例#30
0
 // Use this for initialization
 void Start()
 {
     health = GetComponent <HealthScript> ();
     health.initialize(maxHealth, startHealth);
 }
示例#31
0
    public override void OnTriggerEnter2D(Collider2D other)
    {
        MovementScript movScr = other.GetComponent <MovementScript> ();

        if (movScr != null)
        {
            if (movScr.player_num == id)
            {
                return;
            }
        }

        if (other.tag == "Wall")
        {
            Instantiate(explosionPrefab, transform.position, Quaternion.identity);
            Destroy(gameObject);
        }


        if (!alreadyStunned)
        {
            HealthScript healthScr = other.GetComponent <HealthScript> ();

            if (healthScr != null)
            {
                if (healthScr.stunStack >= 3)
                {
                    return;
                }
                alreadyStunned = true;
                healthScr.stunStack++;
                //Debug.Log ("stun+++: " + healthScr.stunStack);
                healthScr.stunText.gameObject.SetActive(true);
                healthScr.stunText.text += "* ";
                if (healthScr.stunStack > 2)
                {
                    //Debug.Log ("STUN!");
                    healthScr.stunText.text = "STUN!";
                    healthScr.StartCoroutine(healthScr.StunSelf());
                }
                //Destroy (gameObject);
            }
        }

        /*
         * EnemyScript enemy = other.GetComponent<EnemyScript> ();
         * if (enemy == null)
         *      return;
         * if (enemy.id == id)
         *      return;
         * if (team != 0 && team == enemy.team)
         *      return;
         *
         * Instantiate (explosionPrefab, transform.position, Quaternion.identity);
         * //float r = Random.Range (0f,1f);
         * //float crit = (r < crit_chance) ? 1f+crit_damage : 1f;
         * enemy.hp -= damage;// * crit;
         * enemy.CreateNumber(enemy.transform.position, damage.ToString(),new Color(1f,.9f,.9f),.1f,120f,2f);
         * enemy.particleSystems[1].Play();
         * enemy.audioManager.Play (0);
         * enemy.StartCoroutine (enemy.FlashRoutine ());
         *
         */
    }
    // Use this for initialization
    void Start()
    {
        if (DeathExplodePoint == null)
        {
            DeathExplodePoint = transform;
        }

        if (AudioCannonFire != null)
        {
            AudioCannonFire.Stop();
        }

        if (SpawnAmmoPoint.Length <= 0)
        {
            //Debug.LogWarning("XKCannonCtrl -> SpawnAmmoPoint was wrong!");
            //IsOutputError = true;
        }
        else
        {
            for (int i = 0; i < SpawnAmmoPoint.Length; i++)
            {
                if (SpawnAmmoPoint[i] == null)
                {
                    Debug.LogWarning("XKCannonCtrl -> SpawnAmmoPoint was wrong! index = " + i);
                    IsOutputError = true;
                    break;
                }
            }
        }

        if (DaPaoHiddenArray.Length > 0)
        {
            int max = DaPaoHiddenArray.Length;
            for (int i = 0; i < max; i++)
            {
                if (DaPaoHiddenArray[i] == null)
                {
                    Debug.LogWarning("DaPaoHiddenArray was wrong! index is " + i);
                    IsOutputError = true;
                    break;
                }

                XKDaPaoCtrl daPaoScript = DaPaoHiddenArray[i].GetComponent <XKDaPaoCtrl>();
                if (daPaoScript != null)
                {
                    Debug.LogWarning("DaPaoHiddenArray was wrong! name is " + daPaoScript.gameObject.name);
                }
            }
        }

        CosAngleUp   = Mathf.Cos((UpPaoGuanJDVal / 180f) * Mathf.PI);
        CosAngleDown = Mathf.Cos((DownPaoGuanJDVal / 180f) * Mathf.PI);

        CannonTran = transform;
        if (HealthScript == null)
        {
            HealthScript = GetComponent <XKNpcHealthCtrl>();
        }
        if (HealthScript != null)
        {
            HealthScript.SetCannonScript(this);
            IsYouTongNpc = HealthScript.IsYouTongNpc;
        }

        if (SpawnAmmoPoint.Length > 1)
        {
            IsDouGuanDaPao = true;
        }
        DaPaoAmmoLiZiObj = new GameObject[SpawnAmmoPoint.Length];
        InitNpcAmmoList();

        NpcMoveScript = GetComponentInParent <XKNpcMoveCtrl>();
        if (NpcMoveScript != null && IsHiddenAmmoSpawnPoint)
        {
            NpcMoveScript.SetIsRemoveNpcObj();
        }

        if (IsOutputError)
        {
            GameObject obj = null;
            obj.name = "null";
        }
    }
示例#33
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        bool hell = false;

        //collision with ff
        FerrofluidScript goo          = collision.gameObject.GetComponent <FerrofluidScript> ();
        HealthScript     playerHealth = GetComponent <HealthScript> ();
        FloorScript      floor        = collision.gameObject.GetComponent <FloorScript> ();
        PopUpScript      popUp        = collision.gameObject.GetComponent <PopUpScript> ();
        BossFight        boss         = collision.gameObject.GetComponent <BossFight> ();
        ShieldScript     shield       = collision.gameObject.GetComponent <ShieldScript> ();
        ShieldNumber     shieldnumber = collision.gameObject.GetComponent <ShieldNumber> ();
        FfScript         ffBottle     = collision.gameObject.GetComponent <FfScript> ();
        WingsCounter     wings        = collision.gameObject.GetComponent <WingsCounter> ();
        RobotArm         robot        = GetComponent <RobotArm> ();
        OrangeCell       orangeCell   = collision.gameObject.GetComponent <OrangeCell>();
        RedCell          redCell      = collision.gameObject.GetComponent <RedCell>();
        BlueCell         blueCell     = collision.gameObject.GetComponent <BlueCell>();
        MetalCell        metalCell    = collision.gameObject.GetComponent <MetalCell>();
        MazePlatform     maze         = collision.gameObject.GetComponent <MazePlatform>();


        //BridgePlatformScript bridge = GetComponent<BridgePlatformScript> ();

        if (collision.gameObject.tag == "orange")
        {
//			damagePlayer = true;
//			Debug.Log("shield not hit");
//			if(playerHealth != null)
//				playerHealth.Damage(orangeCell.damage,respawnPosX,respawnPosY,false);

            if (shieldGO.activeSelf == true)
            {
                damagePlayer = false;
                shieldHits--;
                metalCell.hitByShield = true;
                Debug.Log("shield hit");
                //orangeCell = null;
                if (playerHealth != null)
                {
                    playerHealth.Damage(orangeCell.damage, respawnPosX, respawnPosY, true);
                }
            }
            else
            {
                damagePlayer = true;
                Debug.Log("shield not hit");
                if (playerHealth != null)
                {
                    playerHealth.Damage(orangeCell.damage, respawnPosX, respawnPosY, false);
                }
            }
        }

        if (collision.gameObject.tag == "red")
        {
            damagePlayer = true;
            Debug.Log("shield not hit");
            if (playerHealth != null)
            {
                playerHealth.Damage(redCell.damage, respawnPosX, respawnPosY, false);
            }
        }

        if (collision.gameObject.tag == "blue")
        {
            damagePlayer = true;
            Debug.Log("shield not hit");
            if (playerHealth != null)
            {
                playerHealth.Damage(blueCell.damage, respawnPosX, respawnPosY, false);
            }
        }

        if (collision.gameObject.tag == "metal")
        {
            //			damagePlayer = true;
            //			Debug.Log("shield not hit");
            //			if(playerHealth != null)
            //				playerHealth.Damage(orangeCell.damage,respawnPosX,respawnPosY,false);

            if (shieldGO.activeSelf == true)
            {
                damagePlayer = false;
                shieldHits--;
                metalCell.hitByShield = true;
                Debug.Log("shield hit");
            }
            else
            {
                damagePlayer = true;
                Debug.Log("shield not hit");
                if (playerHealth != null)
                {
                    playerHealth.Damage(orangeCell.damage, respawnPosX, respawnPosY, false);
                }
            }
        }


        if (floor != null)
        {
            damagePlayer = true;
            hell         = true;
        }


        if (hell)
        {
            if (playerHealth != null)
            {
                playerHealth.Damage(floor.damage, respawnPosX, respawnPosY, false);
            }
        }
        if (collision.gameObject.name == "Checkpoint1")
        {
            CheckpointScript checkpoint = collision.gameObject.GetComponent <CheckpointScript>();
            respawnPosX = checkpoint.posX;
            respawnPosY = checkpoint.posY;
            Destroy(collision.gameObject.GetComponent <Collider2D>());
        }
        if (collision.gameObject.name == "Checkpoint2")
        {
            CheckpointScript checkpoint = collision.gameObject.GetComponent <CheckpointScript>();
            respawnPosX = checkpoint.posX;
            respawnPosY = checkpoint.posY;
            Destroy(collision.gameObject.GetComponent <Collider2D>());
        }
        if (collision.gameObject.name == "Checkpoint3")
        {
            CheckpointScript checkpoint = collision.gameObject.GetComponent <CheckpointScript>();
            respawnPosX = checkpoint.posX;
            respawnPosY = checkpoint.posY;
            Destroy(collision.gameObject.GetComponent <Collider2D>());
        }
        if (collision.gameObject.name == "Checkpoint4")
        {
            CheckpointScript checkpoint = collision.gameObject.GetComponent <CheckpointScript>();
            respawnPosX = checkpoint.posX;
            respawnPosY = checkpoint.posY;
            Destroy(collision.gameObject.GetComponent <Collider2D>());
        }

//		if (collision.gameObject.name == "atomo") {
//			popUp.showPopUp = true;
//			popUp.gameObject.GetComponent<Renderer>().enabled = false;
//			Destroy(popUp.gameObject.GetComponent<Collider2D>());
//		}

        if (collision.gameObject.tag == "MovingPlatform")
        {
            this.transform.parent = collision.transform;
        }

//		if (collision.gameObject.tag == "lever"){
//			RobotArm.move = true;
//		}
//
//		if (collision.gameObject.tag == "lever1") {
//			RobotArm.move1 = true;
//		}

        if (collision.gameObject.tag == "Boss")
        {
            boss.gameObject.GetComponent <Renderer>().enabled = true;

            showPopUp = true;
            maxSpeed  = 0;

            if (i == 5)
            {
                maxSpeed = 25;
                Destroy(boss.gameObject);
                boss.gameObject.GetComponent <Renderer>().enabled = false;
            }
        }

        if (collision.gameObject.tag == "Door")
        {
            Application.LoadLevel("Hidrofobia");
        }

        if (wings != null)
        {
            wings.GetComponent <Renderer>().enabled          = false;
            wings.GetComponent <PolygonCollider2D>().enabled = false;
            wingsCounter = 7;
        }

        if (collision.gameObject.tag == "shield")
        {
            ShieldCounterManager.AddShield(shieldnumber.shieldNumber);
            Destroy(shieldnumber.gameObject);
            shieldFlag = true;
            Debug.Log("Shield available");
        }


        if (collision.gameObject.tag == "ffbottle")
        {
            FfCounterManager.AddFF(ffBottle.ffNumber);
            gunFlag = true;
            Destroy(ffBottle.gameObject);
        }

        //platform activator
        if (collision.gameObject.tag == "ActivatePlatform")
        {
            collision.gameObject.GetComponent <Animator>().enabled = true;
        }

        if (collision.gameObject.tag == "Boots")
        {
            collision.gameObject.GetComponent <Renderer>().enabled          = false;
            collision.gameObject.GetComponent <PolygonCollider2D>().enabled = false;
            time = 5;
        }

        if (collision.gameObject.tag == "box")
        {
            bool          founded = false;
            BoxController box     = collision.gameObject.GetComponent <BoxController>();
            box.Founded(true);
            Destroy(collision.gameObject);
        }

        if (collision.gameObject.tag == "Bridge1")
        {
            BridgePlatformScript.bridge1 = true;
        }
        if (collision.gameObject.tag == "Bridge2")
        {
            BridgePlatformScript.bridge2 = true;
        }
        if (collision.gameObject.tag == "Bridge3")
        {
            BridgePlatformScript.bridge3 = true;
        }
        if (collision.gameObject.tag == "Bridge4")
        {
            BridgePlatformScript.bridge4 = true;
        }
        if (collision.gameObject.tag == "Bridge5")
        {
            BridgePlatformScript.bridge5 = true;
        }
        if (collision.gameObject.tag == "Bridge6")
        {
            BridgePlatformScript.bridge6 = true;
        }
        if (collision.gameObject.tag == "Bridge7")
        {
            BridgePlatformScript.bridge7 = true;
        }
        if (collision.gameObject.name == "MetallicFloorFerroFluidMAP 159")
        {
            MazePlatform.ground = true;
            transform.parent    = collision.transform;
        }
    }
示例#34
0
 void Start()
 {
     spriteRenderer = gameObject.GetComponent<SpriteRenderer> ();
     screen = new Vector3 (Screen.width, Screen.height);
     screen = Camera.main.ScreenToWorldPoint (screen);
     hbScript = healthBar.GetComponent<HealthScript>();
 }
示例#35
0
    void OnTriggerStay2D(Collider2D other)
    {
        if (other.tag == "Enemy")
        {
            HealthScript enemyHealthManager = other.GetComponent <HealthScript>();
            if (enemyHealthManager.IsVulnerable())
            {
                if (isCharging && skillsTimer > chargeDelay + 0.02f && !collidedBodies.Contains(other))
                {
                    collidedBodies.Add(other);
                    attackScript.lastHitTime = Time.time;
                    comboScript.UpdateCC(enemyHealthManager.ScoreValue);

                    enemyHealthManager.TakeDamage(ChargeSkillDamage, new Vector2(targetVelocity.x * 4, 0), true, healthScript, chargeWeight, other);
                    sfx.PlayPunch2();
                    if (controllerScript.facingRight == true)
                    {
                        camShake.ShakeRight(0.3f, 0.2f);
                    }
                    else if (controllerScript.facingRight == false)
                    {
                        camShake.ShakeLeft(0.3f, 0.2f);
                    }
                }

                if (isSpinning && tornadoHitBox.IsTouching(other))
                {
                    if (!collidedBodies.Contains(other))
                    {
                        collidedBodies.Add(other);
                    }
                    float unit_xDistance = (transform.position.x - other.transform.position.x) / tornadoHitBox.bounds.extents.x;
                    float unit_yDistance = (transform.position.y - other.transform.position.y) / tornadoHitBox.bounds.extents.y;
                    // Sucks the enemies staying inside tornadohitbox to the player's position.
                    enemyHealthManager.TakeDamage(0, new Vector2(unit_xDistance, 0), false); // Damage is dealt inside useTornado() function.
                }
            }
        }
        else if (other.tag == "Boss")
        {
            BossHealth bossHealth = other.GetComponentInParent <BossHealth>();
            if (isCharging && skillsTimer > chargeDelay)
            {
                if (bossChargeHittable == true)
                {
                    attackScript.lastHitTime = Time.time;
                    comboScript.UpdateCC(bossHealth.ScoreValue);
                    bossHealth.TakeDamage(bossChargeDamage, Vector2.zero, true, healthScript, chargeWeight, other);
                    sfx.PlayPunch2();
                    camShake.ShakeRight(0.3f, 0.2f);
                    bossChargeHittable = false;
                    StartCoroutine(BossChargeReset());
                }
            }

            if (isSpinning && !collidedBodies.Contains(other))
            {
                if (tornadoHitBox.IsTouching(other))
                {
                    collidedBodies.Add(other);
                }
            }
        }
    }
示例#36
0
 // Start is called before the first frame update
 void Awake()
 {
     HS = GameObject.Find("Diamonds/Hitpoints").GetComponent <HealthScript>();
 }
示例#37
0
 public void setHS(HealthScript h)
 {
     hs = h;
 }
示例#38
0
 public void SetHealth(float amt)
 {
     health = amt;
     HealthScript.UpdateHealth(health);
 }
示例#39
0
    // 产生一个新的回合
    void newRound(bool withStatic)
    {
        // 检查道具效果是否到期,如果到期则取消
        //GameObject[] playerActors = GameObject.FindGameObjectsWithTag("player");
        foreach (GameObject a in playerActors)
        {
            // 跳过inactive(已经死掉)的对象
            if (a.activeInHierarchy == false)
            {
                continue;
            }
            HealthScript hs = a.GetComponent <HealthScript>();
            if (hs.attackEnhanceTurnLeft > 0)
            {
                hs.attackEnhanceTurnLeft -= 1;
                if (hs.attackEnhanceTurnLeft == 0)
                {
                    hs.attack = 0;
                    hs.animator.SetBool("isFire", false);
                }
            }
        }

        //GameObject[] enemyActors = GameObject.FindGameObjectsWithTag("enemy");
        foreach (GameObject a in enemyActors)
        {
            // 跳过inactive(已经死掉)的对象
            if (a.activeInHierarchy == false)
            {
                continue;
            }
            HealthScript hs = a.GetComponent <HealthScript>();
            if (hs.attackEnhanceTurnLeft > 0)
            {
                hs.attackEnhanceTurnLeft -= 1;
                if (hs.attackEnhanceTurnLeft == 0)
                {
                    hs.attack = 0;
                    hs.animator.SetBool("isFire", false);
                }
            }
        }

        GameObject[] itemObjects = GameObject.FindGameObjectsWithTag("items");
        foreach (GameObject a in itemObjects)
        {
            ItemScript iScript = a.GetComponent <ItemScript> ();
            if (iScript == null)
            {
                Debug.Log("not an item: " + a);
                continue;
            }
            if (iScript.isStatic)
            {
                continue;
            }
            iScript.availableTurnsLeft -= 1;
            if (iScript.availableTurnsLeft == 0)
            {
                Destroy(a);
            }
        }

        // master负责生成道具,slave跳过次步骤
        if (client.isMaster())
        {
            // 重新获取一次items
            itemObjects = GameObject.FindGameObjectsWithTag("items");

            // 随机生成新的道具
            int[]  outX, outY;
            bool[] outFlags;
            int    nItems = 0;
            outFlags = new bool[itemProbs.Length];
            outX     = new int[itemProbs.Length];
            outY     = new int[itemProbs.Length];

            // 道具0和1是静态道具,动态道具从2开始
            int i = withStatic ? 0 : nStaticItems;
            for (; i < itemProbs.Length; i++)
            {
                outFlags [i] = false;
                int p = Random.Range(0, 100);
                if (p >= itemProbs [i])
                {
                    continue;
                }

                outFlags [i] = true;
                while (!randomPos(1.2f, playerActors, enemyActors, itemObjects, out outX[i], out outY[i]))
                {
                    ;
                }
                Vector2   pos        = new Vector2(outX [i] / 10.0f, outY [i] / 10.0f);
                Transform iTransform = Instantiate(itemPrefabs [i]);
                iTransform.position = pos;
                nItems += 1;
            }
            // 发送道具类型和位置给slave
            client.sendNew(nItems, outFlags, outX, outY);
        }
    }
示例#40
0
    public override void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Wall")
        {
            Instantiate(explosionPrefab, transform.position, Quaternion.identity);
            Destroy(gameObject);
        }
        EnemyScript enemy = other.GetComponent <EnemyScript> ();

        if (enemy != null)
        {
            if (enemy.id == id)
            {
                return;
            }
            if (team != 0 && team == enemy.team)
            {
                return;
            }
        }

        MovementScript movement = other.GetComponent <MovementScript> ();

        if (movement != null)
        {
            if (movement.player_num == id)
            {
                return;
            }
            if (team != 0 && team == movement.team)
            {
                return;
            }
        }

        if (movement == null && enemy == null)
        {
            return;
        }
        Instantiate(explosionPrefab, transform.position, Quaternion.identity);
        if (myPlayer != null)
        {
            HealthScript hs = myPlayer.GetComponent <HealthScript> ();

            float healthPercent = hs.health / hs.health_max;
            float healing;
            if (healthPercent > .50f)
            {
                healing = 1f;
            }
            else
            {
                healing  = damage;
                healing += Mathf.Round((1f - (hs.health / (hs.health_max / 2))) * 20f);
            }

            NumberSpawner.Instance.CreateNumber(myPlayer.transform.position, healing.ToString(), new Color(0f, 1f, 0f), .1f, 120f, 2f);
            hs.health += healing;
            if (hs.health > hs.health_max)
            {
                hs.health = hs.health_max;
            }
        }
        Destroy(gameObject);
    }
示例#41
0
    void Attack()   //attack
    {
        switch ((int)monsterType)
        {
        case 0:     //dog
            //randomize
            attackCooldown = Random.Range(-cooldownVariation + initialAttackCooldown, cooldownVariation + initialAttackCooldown);
            //
            // RaycastHit hit;



            Vector3 forward = transform.TransformDirection(Vector3.forward) * 10;

            // float temp_centreX = GetComponent<Renderer>().bounds.center.x; //get the centre of the renderer

            // float temp_y = transform.position.y; // get y of the parent position
            // float temp_x = transform.position.x - 0.3f; //get x of parent position
            // float temp_z = transform.position.z; // get z of parent position

            Vector3 firstRayPosition  = new Vector3(transform.position.x + dogAttackRaySpread, transform.position.y + 1f, transform.position.z);  // create a start ray position dependent on the temp variables
            Vector3 secondRayPosition = new Vector3(transform.position.x - dogAttackRaySpread, transform.position.y + 1f, transform.position.z);


            Debug.DrawRay(firstRayPosition, forward); Debug.DrawRay(secondRayPosition, forward);

            //bool forwardRay = Physics.Raycast(transform.position,forward,out hit, attackRadius);
            bool ray1 = Physics.Raycast(firstRayPosition, forward, out hit, attackRadius);
            bool ray2 = Physics.Raycast(secondRayPosition, forward, out hit, attackRadius);

            if (/* forwardRay ||*/ ray1 || ray2)
            {
                if (hit.transform == null)
                {
                    return;
                }
                if (hit.transform.gameObject.tag == "Player")
                {
                    healthScript = hit.transform.gameObject.GetComponent <HealthScript>();

                    healthScript.health -= damage;

                    //make sound
                    FindObjectOfType <audioManager>().Play("dogBiteSound");

                    //Debug.Log(healthScript.health);
                }
            }
            Debug.DrawRay(transform.position, transform.forward, Color.red);

            break;

        case 1:     //Zombie
            break;

        case 2:                                                                                    //trap
            bool upRay = Physics.Raycast(transform.position, transform.up, out hit, attackRadius); //raycast that points up
            if (upRay)
            {
                if (hit.transform != null)                        //if the ray hit something
                {
                    if (hit.transform.gameObject.tag == "Player") //if the ray hit the player
                    {
                        HealthScript healthScript = hit.transform.gameObject.GetComponent <HealthScript>();

                        healthScript.health -= damage;

                        //make sound
                        FindObjectOfType <audioManager>().Play("dogBiteSound");
                    }
                }
            }
            Debug.DrawRay(transform.position, transform.up);

            break;

        case 3:

            break;

        case 4:    //spider
            //randomize
            attackCooldown = Random.Range(-cooldownVariation + initialAttackCooldown, cooldownVariation + initialAttackCooldown);
            //

            Vector3 forwardSpider = transform.TransformDirection(Vector3.forward) * 10;

            Vector3 firstRayPositionSpider  = new Vector3(transform.position.x + dogAttackRaySpread, transform.position.y + 1f, transform.position.z);  // create a start ray position dependent on the temp variables
            Vector3 secondRayPositionSpider = new Vector3(transform.position.x - dogAttackRaySpread, transform.position.y + 1f, transform.position.z);


            // Debug.DrawRay(firstRayPositionSpider, forwardSpider); Debug.DrawRay(secondRayPositionSpider, forwardSpider);

            bool ray1Spider = Physics.Raycast(firstRayPositionSpider, forwardSpider, out hit, attackRadius);
            bool ray2Spider = Physics.Raycast(secondRayPositionSpider, forwardSpider, out hit, attackRadius);

            if (/* forwardRay ||*/ ray1Spider || ray2Spider)
            {
                if (hit.transform == null)
                {
                    return;
                }
                if (hit.transform.gameObject.tag == "Player")
                {
                    healthScript = hit.transform.gameObject.GetComponent <HealthScript>();

                    healthScript.health -= damage;

                    //make sound
                    FindObjectOfType <audioManager>().Play("dogBiteSound");
                }
            }
            // Debug.DrawRay(transform.position, transform.forward, Color.red);
            break;

        case 5:
            playerGO         = FindClosestPlayer();
            player_transform = playerGO.transform;

            if (distance != Vector3.Distance(transform.position, player_transform.localPosition))
            {
                distance = Vector3.Distance(transform.position, player_transform.localPosition);
            }


            break;
        }
    }
示例#42
0
    /*====================FORMAT IN PROGRESS====================*/
    public override void TakeDamage(float amount, Vector2 knockBackForce, bool flinch, HealthScript attacker = null, float freezeDelay = 0.0f, Collider2D gotHitCollider = null)
    {
        currentHealth -= amount;
        enemyAI.AddForce(knockBackForce.x, knockBackForce.y);

        if (flinch)
        {
            enemyAI.ChangeState(AIStates.FLINCHED);
        }

        if (gotHitCollider)
        {                                                                                                                                                         // Pass attacker (their health scripts) and 'this object's collider that was hit' as argument for hiteffect instantiation.
            Vector3    hitPos         = gotHitCollider.bounds.ClosestPoint(new Vector3(attacker.transform.position.x, attacker.transform.position.y + 0.86f, 0)); // 0.86f is the shoulder height of yasushi.
            GameObject hitEffectInst  = Instantiate(hitEffect, hitPos, attacker.transform.rotation);
            Vector3    hitEffectScale = hitEffectInst.transform.localScale;
            hitEffectScale.x *= Mathf.Sign(attacker.transform.position.x - gotHitCollider.transform.position.x);
            hitEffectInst.transform.localScale = hitEffectScale;
        }

        if (attacker != null && freezeDelay > 0)
        {
            attacker.FreezeFrames(freezeDelay);
            FreezeFrames(freezeDelay);
        }

        if (currentHealth <= 0 && canDie)
        {
            vulnerable = false;
            canConsume = false;
            consumeIndicator.gameObject.SetActive(false); // Turn off the consumeIndicator why dying anim is playing so that it won't confuse the player.
            enemyAI.ChangeState(AIStates.DEAD);           // Dead state plays death animation and call DestroyEnemy() at the end of its anim.
        }
        else if (currentHealth <= (MaxHealth * 0.2))      // When health fell under 20%, enemies became consumable.
        {
            enemyAI.ChangeState(AIStates.CONSUMABLE);
            canConsume = true;
            consumeIndicator.gameObject.SetActive(true);
            if (this.name == "Tempura1" || this.name == "MakiRoll1" || this.name == "Chuka1")
            {
                vulnerable  = false;
                this.canDie = false;
            }
        }
    }
示例#43
0
    // Use this for initialization
    void Start()
    {
        player = (GameObject) GameObject.FindGameObjectWithTag("Player");
        playerHealth = (HealthScript) player.GetComponent(typeof(HealthScript));
        router = (GameObject) GameObject.FindWithTag("Router");
        variableScript = (VariableScript) router.GetComponent( typeof(VariableScript) );
        healthScript = (HealthScript) GetComponent(typeof(HealthScript));
        switch(type){
            case "follower":
                    //health = DifficultyScaler.followerHealth;
                    //healthScript.maxHealth = 70;
                    onDestroySFX = (GameObject)Instantiate(variableScript.EnemyNormalDestroySFX );
                break;
            case "shooter":
                    //health = DifficultyScaler.shooterHealth;
                    //healthScript.maxHealth = 40;
                    fireSFX	 = (GameObject)Instantiate(variableScript.EnemyShooterFireSFX );
                    onDestroySFX = (GameObject)Instantiate(variableScript.EnemyShooterDestroySFX );
                break;

        }
        variableScript.Enemies.Add(gameObject);

        tgtm = (ThinkGearTestManager) router.GetComponent(typeof(ThinkGearTestManager));
    }
 void Start()
 {
     animator = GetComponent <Animator>();
     weapon   = GetComponent <WeaponScript>();
     health   = GetComponent <HealthScript>();
 }
示例#45
0
 public override void OnStateEnter(Transform player, GameObject self)
 {
     selfHealthScript = self.GetComponent <BaseEnemy>().healthScript;
     rotationSpeed    = self.GetComponent <BaseEnemy>().rotationSpeed;
 }
    // Here we have four cases:
    // 1) both creatures do not have plates/spines attached
    // 2) the creature that collided had at least one spine attached and the one that took the collision had no plates
    // 3) the creature that collided had no spines attached and the one that took the collision had at least one plate
    // 4) both creatures have at least one plate/spine attached

    // for case 1), if the creature that collided first is a carnivore then the other one if it is a herbivore, it immediately dies
    // for case 2), the result is instant death for the creature that took the collision
    // for case 3), the result is -25 hp to the creature that collided first
    // for case 4), both creatures take some damage, -25 hp for the creature that collided first and the same for the creature that took the collision.

    // if hp of creature reaches 0, the creature is dead.


    private void OnTriggerEnter(Collider other)
    {
        // save the tags of the creatures in two strings for easier comparison
        // save the creature's attachments that did the collision first in an array
        // use similar method to the first one to identify the joints of the creature that collided
        // get the healthscript of the creature that collided first so that we can increase/decrease/zero the health according to each case

        string collideOne = other.tag;
        string collideTwo = creatureRigidbody.tag;

        FixedJoint[] colliderFixedJoints;
        colliderFixedJoints = other.GetComponentsInChildren <FixedJoint>();
        HealthScript otherHealthScript = other.gameObject.GetComponent <HealthScript>();
        int          otherSpineNum     = 0;
        int          otherPlateNum     = 0;

        for (int i = 0; i < colliderFixedJoints.Length; i++)
        {
            if (colliderFixedJoints[i].connectedBody.tag == "Spine")
            {
                otherSpineNum = otherSpineNum + 1;
            }
            if (colliderFixedJoints[i].connectedBody.tag == "Plate")
            {
                otherPlateNum = otherPlateNum + 1;
            }
        }
        // first case: a herbivore gets attacked by a carnivore (this means that the script is attached on a herbivore gameobject)
        if (collideOne == "Carnivore")
        {
            if (collideTwo == "Herbivore")
            {
                if (otherSpineNum == 0 && plateNum == 0)
                {
                    Debug.Log("Carnivore with no spines attacked and killed herbivore with no plates");
                    // kill the herbivore
                    healthScript.setHP(0);
                    // increase carnivore's life by 10
                    otherHealthScript.IncreaseHP(10);
                }
                else if (otherSpineNum != 0 && plateNum == 0)
                {
                    Debug.Log("Carnivore with at least one spine attacked and killed herbivore with no plates");
                    // kill the herbivore
                    healthScript.setHP(0);
                    // increase carnivore's life by 10
                    otherHealthScript.IncreaseHP(10);
                }
                else if (otherSpineNum == 0 && plateNum != 0)
                {
                    Debug.Log("Carnivore with no spines attacked a herbivore with at least one plate");
                    // carnivore's hp reduced by 25
                    otherHealthScript.DecreaseHP(25);
                }
                else if (otherSpineNum != 0 && plateNum != 0)
                {
                    Debug.Log("Carnivore with at least one spine attacked a herbivore with at least one plate");
                    // herbivore's hp reduced by 25
                    healthScript.DecreaseHP(25);
                    // carnivore's hp reduced by 25
                    otherHealthScript.DecreaseHP(25);
                }
            }
        }
        // second case: a carnivore collides with a herbivore (this means that the script is attached on a carnivore gameobject)
        else if (collideOne == "Herbivore")
        {
            if (collideTwo == "Carnivore")
            {
                if (spineNum == 0 && otherPlateNum == 0)
                {
                    Debug.Log("Carnivore with no spines collided and killed herbivore with no plates");
                    // kill the herbivore
                    otherHealthScript.setHP(0);
                    // increase carnivore's life by 10
                    healthScript.IncreaseHP(10);
                }
                else if (spineNum != 0 && otherPlateNum == 0)
                {
                    Debug.Log("Carnivore with at least one spine collided and killed herbivore with no plates");
                    // kill the herbivore
                    otherHealthScript.setHP(0);
                    // increase carnivore's life by 10
                    healthScript.IncreaseHP(10);
                }
                else if (spineNum == 0 && otherPlateNum != 0)
                {
                    Debug.Log("Carnivore with no spines collided a herbivore with at least one plate");
                    // carnivore's hp reduced by 25
                    healthScript.DecreaseHP(25);
                }
                else if (spineNum != 0 && otherPlateNum != 0)
                {
                    Debug.Log("Carnivore with at least one spine collided a herbivore with at least one plate");
                    // herbivore's hp reduced by 25
                    otherHealthScript.DecreaseHP(25);
                    // carnivore's hp reduced by 25
                    healthScript.DecreaseHP(25);
                }
            }
        }
    }
示例#47
0
 void Start()
 {
     healthScript = GetComponent<HealthScript> ();
     slider.maxValue = healthScript.hp;
 }
    // Use this for initialization
    void Start()
    {
        rb2d = gameObject.GetComponent<Rigidbody2D>();
        hs = gameObject.GetComponent<HealthScript>();

        // order waypoint list then sort, cast into waypoint list, and assign
        WayPointList = GameObject.FindObjectsOfType<WayPointScript>().ToList<WayPointScript>();
        WayPointList = WayPointList.OrderBy(wp => wp.wayIndex).ToList<WayPointScript>();

        MovingEnemyList = GameObject.FindObjectsOfType<MovingEnemy>().ToList<MovingEnemy>();

        if(WayPointList.Count()>0)
        {
            currentTarget = 0;
        }
    }
示例#49
0
 void Awake()
 {
     healthScript = GetComponent<HealthScript> ();
         animator = GetComponent<Animator> ();
 }
    // Use this for initialization
    void Start()
    {
        hpScript = gameObject.GetComponent<HealthScript>();
        damagedThisTurn = false;
        startOfHeal = true;
        state = "Standby";
        speed = 15.0f;

        attackDelay = 700.0f;
        attackTimer = attackDelay;
        nextTurnChoice = "";
        dmgBox = (DamageBoxScript) GameObject.Find ("DamageBox").GetComponent<DamageBoxScript>();
        uiScript = (CursorScript) GameObject.Find ("Menu Cursor").GetComponent<CursorScript>();
        aiScript = (EnemyAIScript) GameObject.Find ("Menu Cursor").GetComponent<EnemyAIScript>();
        maxHealth = GameObject.Find ("Menu Cursor").GetComponent<StatsScript>().GetMaxHP (gameObject.name);
        health = maxHealth;
        maxMana = GameObject.Find ("Menu Cursor").GetComponent<StatsScript>().GetMaxMP (gameObject.name);
        mana = maxMana;

        naturalRotation = transform.rotation;
    }
示例#51
0
 void Awake()
 {
     oldDistance = PlayerPrefs.GetInt ("Player_Distance");
     score = 0;
     distance = 0;
     divisible = 0;
     time = new Timer ();
     time.Elapsed += new ElapsedEventHandler (OnTimedEvent); // Calls the OnTimedEvent method based on the time interval.
     time.Interval = 1000; // Change interval between score ticks. Currently set at 5 seconds.
     time.Start (); // Starts the timer.
     health = GameObject.FindGameObjectWithTag("Player").GetComponent<HealthScript> ();
 }
示例#52
0
    private void Decrease(GameObject target) // Decrease enemy health
    {
        HealthScript healthBar = target.GetComponent <HealthScript>();

        healthBar.DecreaseHealth(7);
    }
示例#53
0
 // 1 - Disable everything
 void Start()
 {
     rats = new GameObject[] {rat1,rat2,rat3,rat4,rat5};
     initialFiringRate = weapons[0].shootingRate;
     initalPosition = transform.position;
     health = this.GetComponent<HealthScript>();
     hp = health.hp;
 }
 // Start is called before the first frame update
 void Awake()
 {
     healthScript = GetComponent <HealthScript>();
 }
示例#55
0
    void Start()
    {
        rb2d = GetComponent<Rigidbody2D> ();
        weapon = GetComponent<Weapon> ();
        healthScript = GetComponent<HealthScript> ();
        score = GetComponent<Score> ();
        animator = GetComponent<Animator> ();

        dead = false;
        maxHp = healthScript.getHp();
        rechargeTime = shieldsRechargeTime;

        //Check whether to display combo multiplier or not
        if (score.isCooldown () && score.getCombo() > 1) {
            comboText.text = "Combo x" + score.getCombo ();
        } else {
            comboText.text = "";
        }
        //Display Score
        scoreText.text = "Score: " + score.getScore();

        //Display Shields
        shieldsText.text = "Shields: " + healthScript.getHp();;
    }
示例#56
0
 void Start()
 {
     PlayerHP        = Player.GetComponent <HealthScript>();
     originalHPScale = HealthBar.transform.localScale;
 }
示例#57
0
 // Use this for initialization
 void Start()
 {
     health = this.GetComponent<HealthScript>();
     originalPosition = this.transform.position;
     player = GameObject.Find("Player");
     //hp = health.hp;
 }
 void Awake()
 {
     animator = GetComponent <Animator>();
     health   = GetComponent <HealthScript>();
     weapons  = GetComponentsInChildren <WeaponScript>();
 }
示例#59
0
    void Awake()
    {
        myNavMeshAgent = GetComponent<NavMeshAgent>();

        if(null == myOwner)
        {
            myOwner = GetComponent<OwnerScript>();
        }

        if(null == myHealth)
        {
            myHealth = GetComponent<HealthScript>();
        }

        if(null == myCommands)
        {
            myCommands = GetComponent<CommandScript>();
        }

        if(null == myAttackMessenger)
        {
            myAttackMessenger = gameObject.AddComponent<Messenger_Script>() as Messenger_Script;
        }
    }
示例#60
0
 // Start is called before the first frame update
 void Start()
 {
     m_playerLocation = new Vector3(0.0f, 0.0f, -5.0f);
     rigidbody        = gameObject.GetComponent <Rigidbody2D>();
     healthScript     = gameObject.GetComponent <HealthScript>();
 }