I am trying to spawn a bullet/projectile by using PhotonNetwork.Instantiate(). I have attached this code to the Main Camera:
using UnityEngine;
using System.Collections;
public class Ability1 : MonoBehaviour {
public GameObject projectile;
public float projectilespeed = 20;
void Update(){
if (Input.GetButtonDown ("Fire1")) {
Rigidbody clone =(Rigidbody)PhotonNetwork.Instantiate(projectile, transform.position, transform.rotation, 0);
clone.velocity = transform.TransformDirection(Vector3.forward * projectilespeed);
Destroy(clone.gameObject, 3);
}
}
}
I have referenced the "Bullet" prefab by dragging it into the projectile box. My project is structured like this: Assets>Player>Character 1>Resources>Bullet. It is also worth noting that I have another prefab in the same folder as "Bullet" called "Character 1". I get 3 errors when I run this code:
1. NullReferenceException: Object reference not set to an instance of an object
2. The best overloaded method match for `PhotonNetwork.Instantiate(string, UnityEngine.Vector3, UnityEngine.Quaternion, int)' has some invalid arguments
3. Argument `#1' cannot convert `UnityEngine.GameObject' expression to type `string'
I have experimented and tinkered with the code and cant find a solution. Does anyone know what the problem is and how to fix it? Thank you in advanced.
↧