heath script

i have some problem
i need heath script and i tried to get some but they did not work
and sadly i don’t know how to right my own script but i am learning so i hop some one cud help me out in this

the game i am working on is a firstperson shooter

i will show u the game of the player if there cud be some thing added there

var walkSpeed = 6.0;
var runSpeed = 11.0;
var crouchSpeed = 3.0;

// If true, diagonal speed (when strafing + moving forward or back) can't exceed normal move speed; otherwise it's about 1.4 times faster
var limitDiagonalSpeed = true;

// If checked, the run key toggles between running and walking. Otherwise player runs if the key is held down and walks otherwise
// There must be a button set up in the Input Manager called "Run"

var enableRun = true;
var enableCrouch = true;

var jumpSpeed = 8.0;
var gravity = 20.0;

var enableFallingDamage = true;
// Units that player can fall before a falling damage function is run. To disable, type "infinity" in the inspector
var fallingDamageThreshold = 10.0;
var fallingDamageMultiplier = 2;

// If the player ends up on a slope which is at least the Slope Limit as set on the character controller, then he will slide down
var slideWhenOverSlopeLimit = false;

// If checked and the player is on an object tagged "Slide", he will slide down it regardless of the slope limit
var slideOnTaggedObjects = false;

var slideSpeed = 12.0;

// If checked, then the player can change direction while in the air
var airControl = false;

// Small amounts of this results in bumping when walking down slopes, but large amounts results in falling too fast
var antiBumpFactor = .75;

// Player must be grounded for at least this many physics frames before being able to jump again; set to 0 to allow bunny hopping
var antiBunnyHopFactor = 1;

private var moveDirection = Vector3.zero;
private var grounded = false;
private var controller : CharacterController;
private var myTransform : Transform;
private var speed : float;
private var hit : RaycastHit;
private var fallStartLevel : float;
private var falling = false;
private var slideLimit : float;
private var rayDistance : float;
private var contactPoint : Vector3;
private var playerControl = false;
private var jumpTimer : int;

private var charHeight : float; //Initial height

function Start () {
    controller = GetComponent(CharacterController);
    myTransform = transform;
    speed = walkSpeed;
    rayDistance = controller.height * .5 + controller.radius;
    slideLimit = controller.slopeLimit - .1;
    jumpTimer = antiBunnyHopFactor;
    oldPos = transform.position;
}

function FixedUpdate() {
    var inputX = Input.GetAxis("Horizontal");
    var inputY = Input.GetAxis("Vertical");
    // If both horizontal and vertical are used simultaneously, limit speed (if allowed), so the total doesn't exceed normal move speed
    var inputModifyFactor = (inputX != 0.0  inputY != 0.0  limitDiagonalSpeed)? .7071 : 1.0;

    if (grounded) {
        var sliding = false;
        // See if surface immediately below should be slid down. We use this normally rather than a ControllerColliderHit point,
        // because that interferes with step climbing amongst other annoyances
        if (Physics.Raycast(myTransform.position, -Vector3.up, hit, rayDistance)) {
            if (Vector3.Angle(hit.normal, Vector3.up) > slideLimit)
                sliding = true;
        }
        // However, just raycasting straight down from the center can fail when on steep slopes
        // So if the above raycast didn't catch anything, raycast down from the stored ControllerColliderHit point instead
        else {
            Physics.Raycast(contactPoint + Vector3.up, -Vector3.up, hit);
            if (Vector3.Angle(hit.normal, Vector3.up) > slideLimit)
                sliding = true;
        }

        // If we were falling, and we fell a vertical distance greater than the threshold, run a falling damage routine
        if (falling) {
            falling = false;
            if (myTransform.position.y < fallStartLevel - fallingDamageThreshold  enableFallingDamage == true)
                ApplyFallingDamage (fallStartLevel - myTransform.position.y);
        }

        // If running is enabled, change to run speed when left shift is pressed:
        if (Input.GetKey(KeyCode.LeftShift)  enableRun == true)
        {
            speed = runSpeed;
        }
        // If crouching is enabled, change to crouch speed when "c" is pressed:
        else if (Input.GetKey("c")  enableCrouch == true)
        {
            speed = crouchSpeed;
        }
        // If nothing is pressed, use walkSpeed:
        else
        {
            speed = walkSpeed;
        }

        // If sliding (and it's allowed), or if we're on an object tagged "Slide", get a vector pointing down the slope we're on
        if ( (sliding  slideWhenOverSlopeLimit) || (slideOnTaggedObjects  hit.collider.tag == "Slide") ) {
            var hitNormal = hit.normal;
            moveDirection = Vector3(hitNormal.x, -hitNormal.y, hitNormal.z);
            Vector3.OrthoNormalize (hitNormal, moveDirection);
            moveDirection *= slideSpeed;
            playerControl = false;
        }
        // Otherwise recalculate moveDirection directly from axes, adding a bit of -y to avoid bumping down inclines
        else {
            moveDirection = Vector3(inputX * inputModifyFactor, -antiBumpFactor, inputY * inputModifyFactor);
            moveDirection = myTransform.TransformDirection(moveDirection) * speed;
            playerControl = true;
        }

        // Jump! But only if the jump button has been released and player has been grounded for a given number of frames
        if (!Input.GetButton("Jump"))
            jumpTimer++;
        else if (jumpTimer >= antiBunnyHopFactor) {
            moveDirection.y = jumpSpeed;
            jumpTimer = 0;
        }
    }
    else {
        // If we stepped over a cliff or something, set the height at which we started falling
        if (!falling) {
            falling = true;
            fallStartLevel = myTransform.position.y;
        }

        // If air control is allowed, check movement but don't touch the y component
        if (airControl  playerControl) {
            moveDirection.x = inputX * speed * inputModifyFactor;
            moveDirection.z = inputY * speed * inputModifyFactor;
            moveDirection = myTransform.TransformDirection(moveDirection);
        }
    }

    // Apply gravity
    moveDirection.y -= gravity * Time.deltaTime;

    // Move the controller, and set grounded true or false depending on whether we're standing on something
    grounded = (controller.Move(moveDirection * Time.deltaTime)  CollisionFlags.Below) != 0;
}

function Update ()
{
//    var h = charHeight;
//   
//    if (Input.GetKey("c")  enableCrouch == true)
//    {
//        h = charHeight*0.5;
//    }
//   
//    var lastHeight = controller.height; //Stand up/crouch smoothly
//    controller.height = Mathf.Lerp(controller.height, h, 5*Time.deltaTime);
//    myTransform.position.y += (controller.height-lastHeight)/2; //Fix vertical position
}

// Store point that we're in contact with for use in FixedUpdate if needed
function OnControllerColliderHit (hit : ControllerColliderHit) {
    contactPoint = hit.point;
}

// If falling damage occured, this is the place to do something about it. You can make the player
// have hitpoints and remove some of them based on the distance fallen, add sound effects, etc.
function ApplyFallingDamage (fallDistance : float) {
    gameObject.SendMessage("ApplyDammage", fallDistance*fallingDamageMultiplier);
    Debug.Log ("Ouch! Fell " + fallDistance + " units!");   
}

@script RequireComponent(CharacterController)

hi, you’ve been asked before, a few times, and with the new forums the formatting is even worse without them.

use

[CODE ]
[/CODE ]
tags
(without spaces)
when you paste in code

thanks!

Have you tried this asset that I’ve made? Health Script
It’s completely free and has useful messages that it sends to the Health component’s owner AND the object that caused damage.

yes the new unity update is not nice
in ssome way

where do i add ?

sir
if i uploed it will it also show me a heath bar
that importer in some way

You sent me a private message but I see no option to reply on there. What do you need help with?

1 Like

ya i did
if its ok with u

i am working on a FPS game for zombies
so i am 60% at the ending almost
but i have some problems with the start Sean i need 3 scripts for the start and Quitting i made them but there is the continue scripts that i need that can make the player continue where he lift off this is only for the start Sean

can some one pls help coz i dont know how to right scripts for now but i am learning

Add your code tags to the post just before and just after the code.

This has not changed in the new Forum.

You can look at your original post and check, as I added the code tags for you.

ahmedalheday: Have you had a chance to go through all of the material on the “Learn” section?

Here is a link to the Tutorials, and note the second tab for projects:

Following these will help you get a better understanding of not only Unity, but game Development in general.

If you want to look at one simple approach to starting a game, come by my live session tomorrow:
http://unity3d.com/learn/live-training

We will be adding a splash screen and start button to the game.

a continue bitten where the last time the players stared

i have made already a started and a Quit
but i need the continue

i am sorry sir i have a problem with my assnt store it does not want to open
so i cant get that heath scrpit

sir i have downloeded it
but its not working out i dont know really what script to use or add

If your new to scripting, you should probably learn that before you go forward in a project (unless you plan on using something like play maker).

I tried to give a basic idea of how to set it up here http://forum.unity3d.com/threads/health-script-with-kill-assists-free.184461/#post-1649466

Making games with Unity is not hard…

… but it is also not trivial.

We all need to learn some basics before forging ahead into a serious game project.

Your most helpful resources are the Learn Section and the Documentation.

If you post the code you are working on using CODE TAGS we can try to help you understand your scripting more, but people usually don’t want to write your game for you.

To avoid frustration, look at the basic scripting lessons in the learn section and check out the scripting primer sessions in the live training archives.

yes your right sir

and i am and i am not working on a big project its just a prototip

and i am not asking to ppl make my game just to help me in some thing

mostly what i am not good at like scripting

but i am learning

Don’t underestimate the complexity of game-development.
Start with something like Pong…you’d be surprised how much work it is.

Also, if you’re not good at scripting programming, do yourself a favor and go learn programming first. What newbies often don’t know is that learning how to program is less about learning a programming language, and more about learning how to think in a specific manner.

I feel if you watch the beginner scripting videos and do a project like “roll-a-ball”, you will have a much better understanding of how to program and on how Unity works.