I NEED RPC HELP PLEASEEEEE

Options
N1warhead
N1warhead ✭✭
Okay, I am getting extremely frustrated and something tells me it's something so simple I am missing, I have been up sense 6 PM yesterday working on jut this ONE script.

I had bullets instantiating over network awhile back, well, now I want to RPC call them over the Network like I have seen so many times in the past people saying... Well here's the thing, I'm not wanting y'all to code my gun, I've got all that coded, I just want to get it to actually RPC over the network.... I had RPCs working, but nothing on the clients end, now nothing works, it won't even show my bullet on my side.

Here is my Code, IGNORE A LOT OF IT, IT'S NOT IN USE YET, I"LL CHANGE FONTS TO ANOTHER COLOR SO YOU CAN DISTINGUISH WHAT IS WHAT.

IF IT DON'T SHOW THE COLOR I AM SORRY, THE PREVIEW DON'T SHOW COLOR SO I'M NOT SURE IF ITS WORKING UNTIL POSTED.

using UnityEngine;
using System.Collections;

public class Shoot : Photon.MonoBehaviour {
	public GameObject Bullet;
	public Transform Barrel;
	public float Speed = 20.0f; // speed of bullet
	public float force = 200; // How how force is applied to push rigidbodies
	public float fireRate = 0.1f;
	private float nextFire = 0.0f;
	public float ReloadTime = 2;
	public AnimationClip ReloadAnim;
	public AnimationClip IdleAnim;
	public AnimationClip ShootAnim;
	public AnimationClip MoveAnim;
	public AudioClip ShootSFX;
	public float Force = 1000;
	public bool Shootin = false;
	//bool  IsRunning = false; // Tells script if running (moving) is true or not.
	
	public void Start (){
		//THE STARTING ANIMATION, USUALLY AN IDLE ANIMATION.
		//animation.Play("Red_M16_Idle"); 
	}

	public void Update (){

					[color=#FF0000]	if (Input.GetButton ("Fire1") && Time.time > nextFire) { // Press left Mouse Button to fire (FOR NOW SEMI AUTO)
			                   //photonView.RPC ("Shooting", PhotonTargets.All, null);
			                     GetComponent<PhotonView> ().RPC ("Shooting", PhotonTargets.All);
			                   //Shooting ();
			                     ShootAudio ();
						}[/color]

[color=#4000FF]I COMMENTED OUT "Shooting()" as everything I seen online never used it. I ALSO FOR NOW ADDED THE GETCOMPONENT PART TO BOTH THIS PART AND THE PART ON BOTTOM SO YOU CAN SEE HOW I HAVE EVERYTHING SET UP.[/color]
		
						if (Input.GetButtonUp ("Fire1") || Input.GetKey ("w")) {
								//animation.CrossFade("Red_M16_Run");
						}
		
						if (Input.GetKeyDown (KeyCode.W)) { // When W Is pressed, player Run Animation.
								//animation.CrossFade("Red_M16_Run");
								//animation["Red_M16_Run"].layer =0;
								//IsRunning = true;
						}
		
						if (Input.GetKeyUp (KeyCode.W)) { // If W Is Released Play IDLE Animation again.
								//animation.CrossFade("Red_M16_Idle");
						}
						if (Input.GetKeyDown ("r")) { // Runs the RELOAD FUNCTION
								//Reload();
						}
		
						if (Input.GetButtonUp ("Fire1")) {
								//animation.CrossFade("Red_M16_Idle");
						}
				
		}
	[color=#FF0000][RPC] 
	void Shooting(){
				
						nextFire = Time.time + fireRate;
						//audio.PlayOneShot(ShootSFX);
						//animation["Red_M16_Shoot"].layer =2;
						//animation.Stop("Red_M16_Run");
						//animation.Play("Red_M16_Shoot"); //PLAYS SHOOTING ANIMATION

						//GameObject BulletForce;
						GameObject BulletForce = Instantiate (Bullet, Barrel.position, Barrel.rotation)as GameObject;
						BulletForce.transform.Translate (Barrel.forward * 700); // CHANGE THIS NUMBER TO CHANGE SPEED OF BULLET.
						//GetComponent<PhotonView> ().RPC ("Shooting", PhotonTargets.All);

						Debug.Log ("BULLET SHOT");
				
						// BELOW IS NETWORK SHOOTING
				
				}
	public void ShootAudio(){
		audio.PlayOneShot(ShootSFX);
	}
}
[/color]

Comments

  • N1warhead
    Options
    Forgot to post the error I am getting here it is.
    NullReferenceException: Object reference not set to an instance of an object
    Shoot.Update () (at Assets/Scripts/GunsC#/FX-120/Shoot.cs:30)
    
  • Tobias
    Options
    It would help to know where exactly Shoot.cs line 30 is and what can be null there.
    You basically just have to double click on the log entry and get to that code-line and see what's going wrong.
  • N1warhead
    Options
    Thanks for the quick response.

    It's to deal with PhotonView.

    THE first one under Update in Get ("Fire1")

    GetComponent<PhotonView> ().RPC ("Shooting", PhotonTargets.All);


    My Projectile is in my Resources folder, I've read I didn't need a PhotonView, even though I put one on it and off it, still didn't make a difference, so I am lost.

    I want to do like you've mentioned to everyone to make it like instantiate locally from my position kind of thing.
    Am I going about this the wrong way?
  • N1warhead
    Options
    I still can't figure this out people, I've been up literally again sense 8:30 PM Eastern time last night and stilllll trying to figure out how to RPC call my slow moving projectile, nothing is working except PHOTON INSTANTIATE, AND IT SLOWS DOWN WAAAYYYYYYYY TO MUCH.

    There is literally NO documentation of RPC Calling Localized Projectiles, and nothing else whatsoever makes sense towards Localized RPC Calling to make it (Appear) I am shooting, you know, things that fly through the air and BLOW up.

    I would just you the Instantiate for this, it runs smoothly until other player dies, then we have to take turns killing each other because once I kill him i couldn't kill him until he killed me, something about the rocket not deleting after I killed him until he killed me then it was fine again....
  • Tobias
    Options
    Please rephrase and explain your current issue. "I can't make it work" is just not the info needed to help.
    The RPCs are maybe not explained in much detail but so many developers just get it and there is actually not a lot to say about them in the first place.

    Take a step back and check out the Marco Polo Tutorial which is also doing RPCs:
    http://doc.exitgames.com/en/pun/current ... marco-polo

    From there, get to know things by experimenting a bit with variations.