Hi, I am trying to make a simple multiplayer bullet that moves through space, the graphics are working, anyway, the player isn’t getting destroyed when he gets hit:
using System.Collections;
public class LaserScript : MonoBehaviour {
public float velocity;
public float radius;
public float distance;
public GameObject particles;
public MeshRenderer[] meshes;
public Light laserLight;
void Start () {
Destroy(gameObject, 10f);
rigidbody.velocity = transform.forward * velocity;
if (!networkView.isMine) {
enabled = false;
}
}
void Update () {
SphereCastForward();
}
[RPC]
void SphereCastForward () {
RaycastHit hit;
if (Physics.SphereCast(transform.position, radius, transform.forward, out hit, distance)) {
foreach (MeshRenderer mesh in meshes) {
mesh.enabled = false;
}
laserLight.enabled = false;
Instantiate(particles, transform.position, transform.rotation);
Destroy(gameObject);
if (hit.transform.tag == "Head") {
hit.transform.SendMessageUpwards("ApplyDamage", SendMessageOptions.DontRequireReceiver);
}
}
}
}
So, what could be wrong? This is the mensage that is sent,a long with the part that shoots the bullet:
void Update () {
waitTilNextFire -= Time.deltaTime;
if (Input.GetMouseButton(0) && waitTilNextFire <= 0f) {
Network.Instantiate (laser, laserSpawner.position, laserSpawner.rotation, 0);
waitTilNextFire = fireSpeed;
}
}
void ApplyDamage () {
Network.Destroy(transform.root.gameObject);
}
And if you need the network manager: using UnityEngine;using System.Collections;public class NetworkManager : M - Pastebin.com
And here’s a script that I got from quil18creates tutorial where he uses photon and tried putting it into unity default networking:
using UnityEngine;
using System.Collections;
public class NetworkMovement : MonoBehaviour {
Vector3 realPos = Vector3.zero;
Quaternion realRot = Quaternion.identity;
void Update () {
if (!networkView.isMine) {
transform.position = Vector3.Lerp(transform.position, realPos, 0.1f);
transform.rotation = Quaternion.Lerp(transform.rotation, realRot, 0.1f);
}
}
void OnSerializeNetworkView (BitStream stream) {
if (stream.isWriting) {
realPos = transform.position;
realRot = transform.rotation;
stream.Serialize(ref realPos);
stream.Serialize(ref realRot);
}
else {
stream.Serialize(ref realPos);
stream.Serialize(ref realRot);
}
}
}