// Activates impact animations
	void OnHit (RayAndHit rayAndHit) {
		Vector3 dir = -rayAndHit.ray.direction;
		
		// Push character slightly
		cc.Move(cc.velocity * Time.deltaTime - dir * impactForce);
		
		// Find horizontal direction in character space, with a slight randomness
		dir = transform.InverseTransformDirection(dir);
		dir += Random.insideUnitSphere * 0.2f;
		dir.y = 0;
		dir = dir.normalized;
		
		if (impactFront != null) {
			float axisz = dir.z;
			float axisx = dir.x;
			
			// Start animations
			// For each of four directions, choose a random animation from the array
			// and play it with the weight multiplier for that direction times a random value
			float rand = Random.Range(0.6f, 1.0f);
			if (axisz > 0)
				StartAnimation(impactFront[Random.Range(0, impactFront.Length)], axisz * rand);
			if (axisz < 0)
				StartAnimation(impactBack[Random.Range(0, impactBack.Length)], -axisz * rand);
			if (axisx < 0)
				StartAnimation(impactLeft[Random.Range(0, impactLeft.Length)], -axisx * rand);
			if (axisx > 0)
				StartAnimation(impactRight[Random.Range(0, impactRight.Length)], axisx * rand);
		}
	}
Exemple #2
0
    void OnHit(RayAndHit rayAndHit)
    {
        if (!isDead)
        {
            // Set damage value
            damaged = true;
            damagedValue = Random.Range(1, 5);

            // Reduce the current health by the damage amount
            currentHealth -= damagedValue;

            // Set the health bar's value to the current health
            healthSlider.value = currentHealth;

            //guitext
            guiHealth();
        }
        

        // If the orb has lost all it's health it should die
        if (currentHealth <= 0)
        {
            Death();
        }
    }
Exemple #3
0
    void OnHit(RayAndHit rayAndHit)
    {
        // Add a big force impact from the bullet hit
        rigidbody.AddForce(rayAndHit.ray.direction * 200, ForceMode.Impulse);

        // Sometimes, also AddForceAtPosition - this adds some rotation as well.
        // We don't want to allow this too often, otherwise the orb, when being hit constantly,
        // will aim so bad that it's too easy to win.
        if (Random.value < 0.2f)
            rigidbody.AddForceAtPosition(rayAndHit.ray.direction * 15, rayAndHit.hit.point, ForceMode.Impulse);
    }
Exemple #4
0
    void OnHit(RayAndHit rayAndHit)
    {
        // Add a big force impact from the bullet hit
        rigidbody.AddForce(rayAndHit.ray.direction * 200, ForceMode.Impulse);

        // Sometimes, also AddForceAtPosition - this adds some rotation as well.
        // We don't want to allow this too often, otherwise the orb, when being hit constantly,
        // will aim so bad that it's too easy to win.
        if (Random.value < 0.2f)
        {
            rigidbody.AddForceAtPosition(rayAndHit.ray.direction * 15, rayAndHit.hit.point, ForceMode.Impulse);
        }
    }
 void OnHit(RayAndHit rayAndHit)
 {
     if (hitParticles) {
         GameObject particles = Instantiate(
             hitParticles,
             rayAndHit.hit.point,
             Quaternion.LookRotation(-rayAndHit.ray.direction)
         ) as GameObject;
         particles.transform.parent = transform;
     }
     if (hitSound) {
         AudioSource.PlayClipAtPoint(hitSound, rayAndHit.hit.point, 0.6f);
     }
 }
    void OnHit(RayAndHit rayAndHit)
    {
        health -= hitDamage;
        health = Mathf.Clamp(health, 0, maxHealth);

        if (hitParticles) {
            GameObject particles = Instantiate(
                hitParticles,
                rayAndHit.hit.point,
                Quaternion.LookRotation(-rayAndHit.ray.direction)
            ) as GameObject;
            particles.transform.parent = transform;
        }
    }
Exemple #7
0
    void OnHit(RayAndHit rayAndHit)
    {
        // Random damage
        isDamaged = true;
        int damagedValue = Random.Range(1, 5);

        // Reduce the current health by the damage amount
        currentHealth -= damagedValue;

        // Set the health bar's value to the current health
        healthSlider.value = currentHealth;

        // Player dies if lost all health
        if (currentHealth <= 0)
        {
            isDead = true;
        }
    }
    void OnHit(RayAndHit rayAndHit)
    {
        health -= hitDamage;
        health  = Mathf.Clamp(health, 0, maxHealth);

        if (hitParticles)
        {
            GameObject particles = Instantiate(
                hitParticles,
                rayAndHit.hit.point,
                Quaternion.LookRotation(-rayAndHit.ray.direction)
                ) as GameObject;
            particles.transform.parent = transform;
        }
        if (hitSound)
        {
            AudioSource.PlayClipAtPoint(hitSound, rayAndHit.hit.point, 0.6f);
        }
    }
Exemple #9
0
    // Activates impact animations
    void OnHit(RayAndHit rayAndHit)
    {
        Vector3 dir = -rayAndHit.ray.direction;

        // Push character slightly
        cc.Move(cc.velocity * Time.deltaTime - dir * impactForce);

        // Find horizontal direction in character space, with a slight randomness
        dir   = transform.InverseTransformDirection(dir);
        dir  += Random.insideUnitSphere * 0.2f;
        dir.y = 0;
        dir   = dir.normalized;

        if (impactFront != null)
        {
            float axisz = dir.z;
            float axisx = dir.x;

            // Start animations
            // For each of four directions, choose a random animation from the array
            // and play it with the weight multiplier for that direction times a random value
            float rand = Random.Range(0.6f, 1.0f);
            if (axisz > 0)
            {
                StartAnimation(impactFront[Random.Range(0, impactFront.Length)], axisz * rand);
            }
            if (axisz < 0)
            {
                StartAnimation(impactBack[Random.Range(0, impactBack.Length)], -axisz * rand);
            }
            if (axisx < 0)
            {
                StartAnimation(impactLeft[Random.Range(0, impactLeft.Length)], -axisx * rand);
            }
            if (axisx > 0)
            {
                StartAnimation(impactRight[Random.Range(0, impactRight.Length)], axisx * rand);
            }
        }
    }
Exemple #10
0
    void OnHit(RayAndHit rayAndHit)
    {
        // Random amount of damage
        damaged = true;
        damagedValue = Random.Range(1, 5);

        // Reduce the current health by the damage amount
        currentHealth -= damagedValue;

        // Set the health bar's value to the current health
        healthSlider.value = currentHealth;

        // Show guitext
        guiHealth();

        // If the soldier has lost all it's health
        if (currentHealth <= 0 && !isDead)
        {
            // Game over.
            Death();
        }
    }
Exemple #11
0
 void OnAim(RayAndHit rayAndHit)
 {
     aimed = true;
 }
Exemple #12
0
 void OnHit(RayAndHit rayAndHit)
 {
     inHit = true;  
 }
Exemple #13
0
 void OnHit(RayAndHit rayAndHit)
 {
     // Empty
 }
Exemple #14
0
 void OnHit(RayAndHit rayAndHit)
 {
     Debug.Log(gameObject.tag);
 }
Exemple #15
0
	void OnHit (RayAndHit rayAndHit) {
        if (!GetComponent<OrbHealth>().isDead)
        {
            // Add a force impact from the bullet hit
            //GetComponent<Rigidbody>().AddForce(rayAndHit.ray.direction * 200, ForceMode.Impulse);            
        }
    }
    void OnHit(RayAndHit rayAndHit)
    {
        // Add a big force impact from the bullet hit
        rigidbody.AddForce(rayAndHit.ray.direction * 200, ForceMode.Impulse);

        // Sometimes, also AddForceAtPosition - this adds some rotation as well.
        // We don't want to allow this too often, otherwise the orb, when being hit constantly,
        // will aim so bad that it's too easy to win.
        if (Random.value < 0.2f)
            rigidbody.AddForceAtPosition(rayAndHit.ray.direction * 15, rayAndHit.hit.point, ForceMode.Impulse);

        if (hitParticles) {
            GameObject particles = Instantiate(
                hitParticles,
                rayAndHit.hit.point,
                Quaternion.LookRotation(-rayAndHit.ray.direction)
                ) as GameObject;
            particles.transform.parent = transform;
        }
        if (hitSound) {
            AudioSource.PlayClipAtPoint(hitSound, rayAndHit.hit.point, 0.6f);
        }
    }