I'm doing a multiplayer top-down shooter. The problem is that the bullets are only spawned when the player spawning them is moving, they wont otherwise.
Hope you can lend me a hand with that.
Here're the codes.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using System;
public class powerUps : Photon.Pun.MonoBehaviourPun
{
public bool bow;
public bool speed;
public bool autoheal;
public bool trees;
public bool attackSpeed;
public float timerBow;
public float attackSpeedTim;
public GameObject flecha;
public GameObject projectileSpawner;
public float proyectilSpeed;
public float autohealTimer;
public float autohealDelay;
public float autohealAmount;
Player player;
GameObject PlayerBody;
// Start is called before the first frame update
void Start()
{
bow = false;
speed = false;
autoheal = false;
trees = false;
attackSpeed = false;
proyectilSpeed = 1f;
attackSpeedTim = 1.5f;
autohealDelay = 5;
autohealAmount = 2;
player = gameObject.GetComponent();
PlayerBody = player.playerBody;
}
// Update is called once per frame
void Update()
{
//BOW
if (player.PlayerOn)
{
if (bow)
{
if (timerBow < attackSpeedTim)
{
timerBow += Time.deltaTime;
}
else
{
if (Input.GetMouseButton(0))
{
if (timerBow >= attackSpeedTim)
{
AtacarBow();
}
}
}
}
if (autoheal)
{
if (autohealTimer <= autohealDelay)
{
autohealTimer += Time.deltaTime;
}
else
{
if (player.health <= 100)
{
player.addHealth(autohealAmount);
autohealTimer = 0;
}
}
}
if (Input.GetKeyDown(KeyCode.H))
{
player.addHealth(-90);
}
}
}
void AtacarBow()
{
Quaternion rotation = PlayerBody.transform.rotation;
this.GetComponent<PhotonView>().RPC("spawnShot", RpcTarget.AllBuffered, flecha.name, projectileSpawner.transform.position, rotation);
timerBow = 0;
}
public float getProyectilSpeed()
{
return proyectilSpeed;
}
public void setProyectilSpeed()
{
}
[PunRPC]
void spawnShot(String name, Vector3 position, Quaternion rotation)
{
GameObject clonflecha = Photon.Pun.PhotonNetwork.Instantiate(flecha.name, projectileSpawner.transform.position, rotation, 0);
clonflecha.GetComponent().creador = gameObject;
clonflecha.GetComponent().velocidad = clonflecha.GetComponent().velocidad + proyectilSpeed;
Debug.Log("Disparando");
PlayerBody.transform.position = new Vector3(70, 18, 70);
}
}