Hi i have this code but when i am online it spawm 2 bullets, 1 with de force and another without.
public Transform Ancla;
public float fRadius = 3.0f;
public GameObject Misil;
public float Speed = 1000;
PhotonView pv;
public static float dist;
void Start(){
pv = GetComponent<PhotonView>();
if(pv.isMine == false){
Destroy(this.gameObject);
}
}
void Update(){
if(pv.isMine == true){
//Seguimos el mouse
Vector3 v3Pos = Camera.main.WorldToScreenPoint (Ancla.position);
v3Pos = Input.mousePosition - v3Pos;
float angle = Mathf.Atan2 (v3Pos.y, v3Pos.x) * Mathf.Rad2Deg;
v3Pos = Quaternion.AngleAxis (angle, Vector3.forward) * (Vector3.right * fRadius);
transform.position = Ancla.position + v3Pos;
//Mientras mas lejos esta el mouse mas fuerza le agrega
Vector3 dist3 = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
float rDot = Vector3.Dot(transform.right, dist3);
float uDot = Vector3.Dot(transform.up, dist3);
dist = (float) Mathf.Sqrt((uDot * uDot) + (rDot * rDot));
//Rotamos a la direccion del mouse
Vector3 dir = Camera.main.WorldToScreenPoint (transform.position);
dir = Input.mousePosition - dir;
angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle + 90, Vector3.forward);
if(Input.GetKeyDown(KeyCode.Q)){
pv.RPC("Shoot",PhotonTargets.All,new object[]{transform.position,transform.rotation,- (Vector2)transform.TransformDirection(Vector3.up) * Speed * dist});
}
}
}
[RPC]
void Shoot(Vector3 pos,Quaternion rot,Vector2 FuerzaDireccion)
{
GameObject RocketClone = PhotonNetwork.Instantiate("Sphereprefab",pos,rot,0)as GameObject;
RocketClone.GetComponent<Rigidbody2D>().AddForce(FuerzaDireccion);
}
}