Unity Community


Results 1 to 3 of 3

Thread: Shark Attack!


  1. Location
    UK
    Posts
    22

    Shark Attack!

    Hi all,
    I'm a bit stuck debugging a script. It's actually hurting my brain.

    I've got a shark moving in a circle and I've used a bit of script from the robot (badguy) script in the Lurpz tutorial and using a capsule collider to trigger it. It worked the 1st time by bumping my character backwards and removing health points, but had a script error. Now after restarting Unity the game won't run because of the error. See below.
    assets/scripts/SharkAttack.js (43,59):BCE0044: expecting :, found ';'

    I can't figure it out as I've tried putting in a : which obviously doesn't work.
    Below is my script. Any help debugging it would be most appreciated. I'm a bit of a coding noob being an artist by trade.

    var damage = 1;

    var target : Transform;

    // Cache a reference to the controller
    private var characterController : CharacterController;
    characterController = GetComponent(CharacterController);

    // Cache a link to LevelStatus state machine script:
    var levelStateMachine : LevelStatus;

    function Start ()
    {
    levelStateMachine = GameObject.Find("/Level").GetComponent(LevelStatus);

    if (!levelStateMachine)
    {
    Debug.Log("Shark: ERROR! NO LEVEL STATUS SCRIPT FOUND.");
    }

    if (!target)
    target = GameObject.FindWithTag("Player").transform;
    }

    function OnTriggerEnter (col : Collider)
    {
    var controller : ThirdPersonController = col.GetComponent(ThirdPersonController);
    if (controller != null)
    print ("enter1");

    // Keep looking if we are hitting our target
    // If we are, knock them out of the way dealing damage
    //var pos = transform.TransformPoint(punchPosition);
    //if(Time.time > 0.3 && (pos - target.position).magnitude < punchRadius)
    {
    // deal damage
    SendMessage("ApplyDamage", damage);
    // knock the player back and to the side
    var slamDirection = transform.InverseTransformDirection(target.positio n - transform.position);
    slamDirection.y = 0;
    slamDirection.z = 1;
    if (slamDirection.x >= 0)
    slamDirection.x = 1;
    else
    slamDirection.x = -1;
    target.SendMessage("Slam", transform.TransformDirection(slamDirection));
    lastPunchTime = Time.time;
    }
    }

    Here's a bit of an old link to the game I'm working on if it helps.

    http://www.vj23.com/pages/test/test.html

    Thanks again for any help.


  2. Location
    UK
    Posts
    22
    WooHoo! I've fixed it!

    I reckon this script will be really useful for landing on spikes, hot lava and all things that can damage the player. Or maybe comment out the damage bit, mess round with the slam direction and you could turn it into bouncepads or something.
    Here's the code below:

    var damage = 1;

    var target : Transform;

    var levelStateMachine : LevelStatus;

    function Start ()
    {
    levelStateMachine = GameObject.Find("/Level").GetComponent(LevelStatus);

    if (!levelStateMachine)
    {
    Debug.Log("Shark: ERROR! NO LEVEL STATUS SCRIPT FOUND.");
    }

    if (!target)
    target = GameObject.FindWithTag("Player").transform;
    }

    function OnTriggerEnter (col : Collider)
    {
    var controller : ThirdPersonController = col.GetComponent(ThirdPersonController);
    if (controller != null) ;
    print ("enter1");

    controller.SendMessage("ApplyDamage",damage);
    // knock the player back and to the side
    var slamDirection = transform.InverseTransformDirection(target.positio n - transform.position);
    slamDirection.y = 0;
    slamDirection.z = 1;
    if (slamDirection.x >= 0)
    slamDirection.x = 1;
    else
    slamDirection.x = -1;
    target.SendMessage("Slam", transform.TransformDirection(slamDirection));
    }


  3. Location
    Medellin Colombia
    Posts
    635
    Hello,

    I'm just curious :P what was the error, couldn't see it yesterday when you posted :P
    orly yarly nowai my page -> www.pencilsquaregames.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •