- Home /
how do i get the viewid of the object that my prefab collided with? PhotonNetwork
im using photon network, and im bashing my head up against the wall trying to figure out how to do this. i want it so that when the object collides with another, it reads the viewid of the object it hit and i can deduct health points. reason why i need the view id, is because it belongs to another player. im extremely confused. if you can give me an example of a better way to get this done, please dont hesitate to show me :).
using UnityEngine;
using System.Collections;
public class fireballexplosion : Photon.MonoBehaviour {
float lifespan = 3.0f;
// Use this for initialization
void Start () {
//note: change for other maps ----
GameObject _map1 = GameObject.Find ("Map1");
GameObject _warrior = GameObject.Find ("6102024(Clone)");
GameObject _Mage = GameObject.Find ("MagePlayer(Clone)");
Physics.IgnoreCollision (_map1.collider, collider);
//Physics.IgnoreCollision (_warrior.collider, collider);
//Physics.IgnoreCollision (_Mage.collider, collider);
}
// Update is called once per frame
void Update () {
lifespan -= Time.deltaTime;
if(lifespan <- 0) {
Explode();
}
}
[RPC] void OnCollisionEnter (Collision collision) {
//Destroy (GameObject);
if(collision.gameObject){
//this is all failed attempts to try to do this..
print("This collider collided with: " + pView);
foreach (ContactPoint contact in collision.contacts) {
print(contact.thisCollider.name + " hit " + contact.otherCollider);
Debug.DrawRay(contact.point, contact.normal, Color.white);
}
lifespan = 0.25f;
//Destroy (gameObject);
}
}
void Explode () {
Destroy (gameObject);
}
}
Comment
Answer by membles · Mar 24, 2017 at 10:09 AM
int viewid = hit.collider.GetComponent<PhotonView>().viewID;
Your answer
Follow this Question
Related Questions
why do I get this error? 1 Answer
Photonview with 4 separate cameras 0 Answers
ViewID + Sending Messages 1 Answer
Player names all displayed as local player photon 2 Answers
Extract the network id from raycast 1 Answer