- Home /
Question by
jesser1981 · Mar 06, 2014 at 09:58 PM ·
errortutorial
Official Unity Space Shooter Tutorial
I am following the space shooter tutorial and I am getting this error error
CS0266: Cannot implicitly convert type UnityEngine.Object' to
UnityEngine.GameObject'. An explicit conversion exists (are you missing a cast?)
using UnityEngine;
using System.Collections;
[System.Serializable]
public class Boundary
{
public float xMin, xMax, zMin, zMax;
}
public class PlayerController : MonoBehaviour
{
public float speed;
public Boundary boundary;
public float tilt;
public GameObject bolt;
public Transform shotSpawn;
public float fireRate;
private float nextFire;
void Update()
{
//allows player to fire weapon and determines a firerate for the next shot fired.
if (Input.GetButton ("Fire1") && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
GameObject clone = Instantiate (bolt, shotSpawn.position, shotSpawn.rotation); // as GameObject;
}
}
void FixedUpdate ()
{
//Move player left and right and up and down the screen
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rigidbody.velocity = movement * speed;
//Keeps player from leaving game area by clamping player with bounds.
rigidbody.position = new Vector3
(
Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax),
0.0f,
Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax)
);
//Make player ship tilt when going left or right
rigidbody.rotation = Quaternion.Euler (0.0f, rigidbody.velocity.x * -tilt);
}
}
Any help with this would be greatly appreciated
Comment
Best Answer
Answer by perchik · Mar 06, 2014 at 10:01 PM
On line 27, you should uncomment as GameObject
:
GameObject clone = Instantiate (bolt, shotSpawn.position, shotSpawn.rotation) as GameObject;