Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Sentrygun Damage

Discussion in 'Scripting' started by Hansuke, Aug 28, 2007.

  1. Hansuke

    Hansuke

    Joined:
    Apr 17, 2007
    Posts:
    100
    Code (csharp):
    1.  
    2. var damage = 5.0;
    3. private var hit : RaycastHit;
    4.  
    5. if(Physics.Raycast(transform.position, transform.forward, hit, maxLength))
    6.       {
    7.          lineRenderer.SetPosition(0, transform.position);
    8.          lineRenderer.SetPosition(1, hit.point);
    9.          particleEffect.transform.position = hit.point;
    10.          particleEffect.transform.rotation = Quaternion.LookRotation(hit.normal);
    11.          particleEffect.emit =true;
    12.          charDamage = hit.collider.GetComponent(CharacterDamage);
    13.      if(charDamage) charDamage.ApplyDamage(damage*Time.deltaTime);
    i have been trying to apply damage script to the sentrygun so it deals damage, this part is where i include the script where ApplyDamage and CharacterDamage is called from another script. This doesn't seem working. Anyone can help?

    I attached the scripts as well just incase anyone need to check the scripts :)

    Ernest
     

    Attached Files: