- Home /
Question by
Mellevh · Aug 12, 2019 at 01:17 PM ·
damagespawning problemsinternetself
is it possible in uNet to shoot a network.spawned bullet but not have it damage yourself?
I am making a 2d platformer shooter online. but whenever I spawn a bullet from a client and that client teleports into the bullet the bullet damages the client. This makes me so sad and i have been trying this for to long. so that is the reason why I am asking a question. If you might ask what my script is. Thanks in advance for trying to find a solution.
[SerializeField]
GameObject[] availables;
[SerializeField]
GameObject[] extraavailables;
private int availableshots;
public int overallshots;
private int reloading;
public GameObject fireableobject;
public Transform firepoint;
public float firewaittime;
public float reloadtime;
private float waittime;
public Image waitbalk;
public Canvas waitbalkcanvas;
private void Start()
{
for (int m = 0; m < extraavailables.Length; m++)
{
extraavailables[m].SetActive(false);
}
for (int i = 0; i < availables.Length; i++)
{
availables[i].SetActive(true);
}
availableshots = overallshots;
waittime = 0;
}
// Update is called once per frame
void Update()
{
if (isLocalPlayer)
{
shooting_handler();
showavailables();
}
}
void shooting_handler()
{
if (Input.GetKeyDown(KeyCode.Mouse0) && waittime <= 0)
{
Cmdfire();
//shoot();
availableshots-= 1;
if (availableshots >= 1)
{
reloading = 0;
waittime = firewaittime;
}
if (availableshots <= 0)
{
reloading = 1;
waittime = reloadtime;
}
}
if (waittime >= 0)
{
waitbalkcanvas.enabled = true;
waittime -= Time.deltaTime;
}
else waitbalkcanvas.enabled = false;
}
void showavailables()
{
if(reloading == 1)
{
if(waittime <= 0)
{
availableshots = overallshots;
}
waitbalk.fillAmount = waittime / reloadtime;
}
if(reloading == 0)
{
waitbalk.fillAmount = waittime / firewaittime;
}
if (availableshots == overallshots)
{
for (int i = 0; i < availables.Length; i++)
{
availables[i].SetActive(true);
}
}else availables[availableshots].SetActive(false);
}
[Command]
void Cmdfire()
{
GameObject arrow = (GameObject)Instantiate(fireableobject, firepoint.position, firepoint.rotation);
NetworkServer.Spawn (arrow);
}
void shoot()
{
GameObject arrow = (GameObject)Instantiate(fireableobject, firepoint.position, firepoint.rotation);
// Instantiate(arrow);
}
Comment
Your answer
Follow this Question
Related Questions
Getting particle to not damage the emitter parent 1 Answer
Screen flashes red when taking damage 3 Answers
How do I simulate a tsunami wave? 6 Answers
Object Not Recieving Damage 3 Answers
Expecting ) found = 1 Answer