Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Whats wrong with this?

Discussion in 'Scripting' started by MODEEEEE, Jun 20, 2014.

  1. MODEEEEE

    MODEEEEE

    Joined:
    Feb 15, 2014
    Posts:
    52
    Ok i tried to rewrite from js to c# but c# dont work for me and dont give me any errors? whast the problem?
    Animation dont play and the dammage are not being apply.Maybe something wrong with raycats in c#?

    js (good one)
    http://pastebin.com/z4wqfR8q

    c# (not working) <<<<
    http://pastebin.com/AN07ddxv
     
  2. MODEEEEE

    MODEEEEE

    Joined:
    Feb 15, 2014
    Posts:
    52
    Ps its something with AttackDammage()
     
  3. Zaladur

    Zaladur

    Joined:
    Oct 20, 2012
    Posts:
    392
    In C# AttackDammage needs be called via StartCoroutine if you are going to be making use of yields. Also, a simple way of testing this kind of thing for yourself would be to throw a few Debug.Log statements in there - see which ones are called and which ones are not reached.
     
  4. MODEEEEE

    MODEEEEE

    Joined:
    Feb 15, 2014
    Posts:
    52
    Its looks like that the AttackDammage is not beign called at all somehow... i tried to make debug.logs and it didnt even appeard in first line of funcion. Btw how to make that starcoroutine?
     
  5. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
  6. MODEEEEE

    MODEEEEE

    Joined:
    Feb 15, 2014
    Posts:
    52
  7. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    well tbh it's not that great of a piece of code...
    anyways if you get headaches from enumerators, just make yourself a counter to use.
    something like:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Counter
    5. {
    6.     public static float cnt;
    7.    
    8.     public static float Count(float amount)
    9.     {
    10.         if (cnt == 0.0f)
    11.             cnt = amount;
    12.         cnt -= Time.deltaTime;
    13.         if (cnt <= 0f)
    14.             cnt = 0f;
    15.         Debug.Log ("count: " + cnt);
    16.         return cnt;
    17.     }
    18. }
    which you can simply use in other scripts like this:
    Code (CSharp):
    1.  
    2.         if(Counter.Count(3.0f) == 0)
    3.         {
    4.             //do something
    5.         }
     
  8. MODEEEEE

    MODEEEEE

    Joined:
    Feb 15, 2014
    Posts:
    52
    can i do without if statement? like normal yield waitforseconds?
     
  9. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    no the counter replaces the yield.
    anyway what is the script supposed to do. as far as i see instantiate some things depending on what kind of material is hit right?
     
  10. MODEEEEE

    MODEEEEE

    Joined:
    Feb 15, 2014
    Posts:
    52
    Well its my melee system heres video

    I thought it will be nice to have it translated to c# because of the future problems(networking,multiplayer)
    What it does it deals dammage and spawns different particles,sounds,hitmarks,ddepended on tags :)