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

Network.instantiate problem

Discussion in 'Scripting' started by markrashera, Aug 16, 2014.

  1. markrashera

    markrashera

    Joined:
    Aug 15, 2014
    Posts:
    10
    Hello there, i'm trying to make a multiplayer fps game, and i'm now trying to instantiate a particle when the ray hits something. but i get this problem when i'm trying to do Network.instantiate:

    here is the script:
    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var Effect : Transform;
    4. var TheDammage : int = 50;
    5. var line : LineRenderer;
    6. var blood : Transform;
    7. function Update () {
    8.    
    9.    
    10.    
    11.     if (Input.GetButton("Fire1") && !Input.GetKey(KeyCode.W))
    12.     {
    13.     networkView.RPC("shoot", RPCMode.All);
    14.     }
    15.    
    16.    
    17. }
    18.  
    19. @RPC
    20. function shoot() {
    21. var hit : RaycastHit;
    22.     var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
    23.         if (Physics.Raycast (ray, hit, 100))
    24.         {
    25.         if(hit.transform.tag == "Player"){
    26. //This is the problem.
    27.             var particleClone = Network.Instantiate(blood, hit.point, Quaternion.LookRotation(hit.normal), 0);
    28.             Destroy(particleClone.gameObject, 2);
    29.             //hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
    30.             hit.transform.networkView.RPC("ApplyDammage", RPCMode.All, TheDammage);
    31.         }
    32.         else{
    33.         var particleClone2 = Network.Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
    34.         Destroy(particleClone2.gameObject, 2);
    35.         }
    36.        
    37.         }
    38. }
     
  2. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    Read the error. It says exactly what the problem is.
     
  3. Beennn

    Beennn

    Joined:
    Sep 11, 2010
    Posts:
    373
    markrashera likes this.
  4. CraftySentinel

    CraftySentinel

    Joined:
    Jul 20, 2013
    Posts:
    4
    Code (JavaScript):
    1. var blood : Transform;
    That would be your problem, as the error says. You're passing a Transform where a GameObject is expected.
     
  5. Beennn

    Beennn

    Joined:
    Sep 11, 2010
    Posts:
    373
    That is not correct.
     
  6. CraftySentinel

    CraftySentinel

    Joined:
    Jul 20, 2013
    Posts:
    4
    Ah I do stand corrected, used to line numbers on the errors. My apologies. Shows how much I use JS these days.
     
  7. markrashera

    markrashera

    Joined:
    Aug 15, 2014
    Posts:
    10