Question by
tastelessbanana · Jan 13, 2017 at 08:13 AM ·
c#photongameobjectsinstantiation
Problem instantiating projectiles
I am getting the error, Error CS0030: Cannot convert type 'UnityEngine.GameObject' to 'Fireball'
The Aoe line works fine but so I could technically use that for the fireballs but I don't know how to propel the fireballs forward. I would like to learn why I am getting the error if anyone knows the solution.
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
public class Staff : MonoBehaviour, IWeapon, IProjectileWeapon, IAoe
{
[PunRPC]
private Animator animator;
public List<BaseStat> Stats { get; set; }
public Transform AoeSpawn { get; set; }
Aoe fireAoe;
public Transform ProjectileSpawn { get; set; }
Fireball fireball;
void Start()
{
fireball = Resources.Load<Fireball> ("Weapons/Projectiles/fireball");
fireAoe = Resources.Load<Aoe> ("Weapons/Projectiles/fireAoe");
animator = GetComponent<Animator> ();
}
public void PerformAttack()
{
animator.SetTrigger ("Base_Attack");
//Debug.Log (this.name + "Sword Attack!");
}
public void PerformSpecialAttack()
{
animator.SetTrigger ("Special_Attack");
//Debug.Log (this.name + "Special Sword Attack!");
}
public void CastProjectile()
{
//PhotonNetwork.Instantiate ("fireball", ProjectileSpawn.position, ProjectileSpawn.rotation,0);
Fireball fireballInstance = (Fireball)PhotonNetwork.Instantiate ("fireball", ProjectileSpawn.position, ProjectileSpawn.rotation,0);
fireballInstance.Direction = ProjectileSpawn.forward;
}
public void CastAoe()
{
PhotonNetwork.Instantiate ("fireAoe", AoeSpawn.position, Quaternion.Euler(270,0,0),0);
}
}
public void CastProjectile()
{
//PhotonNetwork.Instantiate ("fireball", ProjectileSpawn.position, ProjectileSpawn.rotation,0);
Fireball fireballInstance = (Fireball)PhotonNetwork.Instantiate ("fireball", ProjectileSpawn.position, ProjectileSpawn.rotation,0);
fireballInstance.Direction = ProjectileSpawn.forward;
}
Comment
Best Answer
Answer by hexagonius · Jan 13, 2017 at 09:15 AM
Are you talking about this line?
Fireball fireballInstance = (Fireball)PhotonNetwork.Instantiate ("fireball", ProjectileSpawn.position, ProjectileSpawn.rotation,0);
If so I would say that Instantiate returns a GameObject. Maybe Photon has a generic instatiate version like Unity has, but in your case it should be:
Fireball fireballInstance = PhotonNetwork.Instantiate ("fireball", ProjectileSpawn.position, ProjectileSpawn.rotation,0).GetComponent<Fireball>();