- Home /
The question is answered, right answer was accepted
UNET NetworkBehaviour
import UnityEngine.Networking;
import UnityEngine.UI;
public var hedef : Transform;
private var canAttack : boolean;
var hiz : float = 250;
var Efekt : Rigidbody;
var ses : AudioClip;
var cooldown : float;
var cooldowntime : float = 0;
var rayhit : RaycastHit;
public class TaretYapayZeka extends NetworkBehaviour {
function FixedUpdate () {
if(Physics.Raycast(transform.position, transform.TransformDirection(Vector3(0,0,1000)), rayhit, 1000)
&&
rayhit.collider.gameObject.tag == "Player"
&&
cooldowntime<=0
&&
canAttack == true
)
{
CmdSaldiri();
}
}
//Debug.DrawRay(transform.position, transform.TransformDirection(Vector3(0,0,1000)), Color.red);
@Command function CmdSaldiri (){
RpcSaldiri();
}
@ClientRpc function RpcSaldiri (){
cooldowntime = cooldown;
GetComponent.<AudioSource>().PlayOneShot(ses, 0.7);
clone = Instantiate(Efekt, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection (Vector3.forward * hiz);
}
}
when i try to shoot i get this error message: NullReferenceException: Object reference not set to an instance of an object UnityEngine.Networking.NetworkBehaviour.get_isServer () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkBehaviour.cs:19) TaretYapayZeka.CallCmdSaldiri () TaretYapayZeka.FixedUpdate () (at Assets/Scriptler/TaretYapayZeka.js:74)
Answer by Chom1czek · Feb 11, 2016 at 02:17 PM
I'm not sure but "var Efekt : Rigidbody" might be the case, try to change it to GameObject instead. Anyway code is a mess at least for me, I don't know why are you keeping variables outside the class?
What is "clone"? Where is declaration for it? Plus you should Instantiate and Spawn it in CmdSaldiri and it should work :) Hope it helped, if you got more questions please PM or just format this code better please. Good luck
Follow this Question
Related Questions
Java-Multiple inheritance in Networking 0 Answers
Sending an RPC 1 Answer
game objects and meshes not appearing 1 Answer
Online Player Position 1 Answer
Big Delay in Networking 0 Answers