If Statement not working properly - Comparing game objects
public void GotShot(GameObject col,GameObject shotBullet)
{
if (shotBullet.GetComponent<bulletController>().parent != this.gameObject)
{
cameraObject.GetComponent<cameraScaleController2>().m_Targets.Remove(gameObject.transform);
NetworkServer.Destroy(shotBullet);
Destroy(gameObject);
}
}
For some reason, you are still able to shoot yourself. If programming is linear, then this should not be a problem. My shoot method:
void CmdFire()
{
GameObject projectile = (GameObject)Instantiate(bullet, transform.position, transform.rotation);
projectile.GetComponent<bulletController>().parent = gameObject;
NetworkServer.Spawn(projectile);
}
The game object is instantiated, the parent variable in the projectile is set to be this Game Object, the projectile is spawned. Then, when the projectile collides with an object (and in this case, the object has the name character), the GotShot method is called, where the game object that has collided with the bullet and the bullet are passed. If the bullets parent is not the same as the player (parent) it will destroy it.
The biggest joke, is this only happens on clients. The host does not have this issue.
-bump
Your answer
Follow this Question
Related Questions
How to detect collisions in the LateUpdate ? 0 Answers
Unity 5: AddForce Increases power when already being pushed towards a collider. How to make stop? 1 Answer
Detect overlapping objects 2D game 0 Answers
problem with tilemap collider and composite collider 1 Answer
Animator and collision issues 0 Answers