- Home /
How to acess script from Command Method
this is a command from my player script. On server (Host) all works fine but on client bombClone.GetComponent<BombPrefab_Script>().Init(chosenType);
is not called. i dont know why, ther is no exeption or something like that. how can i acess that script (function) ?
[Command]
private void CmdThrowBomb(float speed, float duration, Vector3 pos, Vector3 camForwart, BombType chosenType) {
// create a Instanze of the right Bomb prefab
GameObject bombClone = (GameObject)Instantiate(bombPrefab, new Vector3(pos.x + (camForwart.normalized.x / 3), pos.y + throwingOfset.y + (camForwart.normalized.y / 3), pos.z + (camForwart.normalized.z / 3)), Quaternion.identity);
bombClone.GetComponent<BombPrefab_Script>().Init(chosenType);
//get the direction the player is facing at
Vector3 playerDirection = camForwart;
//get rigBody of the Bomb and add force and Torque
Rigidbody bombRigBody = bombClone.GetComponent<Rigidbody>();
float impuls = CalcImpuls(duration);
bombRigBody.AddForce(playerDirection.normalized * impuls, ForceMode.Impulse);
bombRigBody.AddTorque(Random.value, Random.value, Random.value, ForceMode.Impulse);
NetworkServer.Spawn(bombClone);
}
Answer by alijaj · May 01, 2016 at 07:23 AM
you can use this method if im not wrong inside ur script call the script u want to use like this public Scriptname dothis;
and after you can call the function or whatever doing like this
dothis.function(); ex bool dothis.bool=true;
Hm dont think this would work because its importend that the script is attached to the instanz of the prefab. Otherwice the function call make no sence...
Your answer
![](https://koobas.hobune.stream/wayback/20220612075935im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
UNET : SyncVar value not updating, hooks firing 1 Answer
Network [Command] funktion dont run. 1 Answer
UnityScript not recognizing NetworkServer "Unknown Identifier" 0 Answers
Rpc client issue 0 Answers