public override IEnumerator OnReceive(Server.Main.Session session, Gamnet.Packet packet) { MsgCliSvr_HitSphere_Ntf ntf = packet.Deserialize <MsgCliSvr_HitSphere_Ntf>(); Sphere sphere = null; if (false == session.spheres.TryGetValue(ntf.id, out sphere)) { yield break; } Vector3 hitDirection = ntf.hitDirection; sphere.rigidBody.velocity += hitDirection * 30.0f; yield break; }
private void Update() { inputObjectCount.text = Server.Main.Instance.objectCount.ToString(); Server.Main.Instance.objectCount = (int)sliderObjectCount.value; inputSyncInterval.text = Server.Main.Instance.syncInterval.ToString(); Server.Main.Instance.syncInterval = sliderSyncInterval.value; syncPosition = toggleSyncPosition.isOn; syncRotation = toggleSyncRotation.isOn; syncVelocity = toggleSyncVelocity.isOn; Server.Main.Instance.sync = toggleSync.isOn; Server.Main.Instance.clientOnly = toggleClientOnly.isOn; if (true == Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Debug.DrawRay(ray.origin, ray.direction * 100.0f, Color.red); RaycastHit[] hits = Physics.RaycastAll(ray, Mathf.Infinity); foreach (RaycastHit hit in hits) { if ("ClientSphere" == hit.transform.gameObject.tag) { Rigidbody rb = hit.transform.GetComponent <Rigidbody>(); rb.velocity += ray.direction.normalized * 30.0f; Sphere sphere = hit.transform.GetComponent <Sphere>(); MsgCliSvr_HitSphere_Ntf ntf = new MsgCliSvr_HitSphere_Ntf(); ntf.id = sphere.id; ntf.hitDirection = ray.direction.normalized; Send(ntf); } } } }