How do you convert UnityEngine.GameObject to UnityEngine.Transform?
error CS0029: Cannot implicitly convert type UnityEngine.GameObject to UnityEngine.Transform
I just got this code, and I don't know how to fix this, how do you set the location of the target to the location of the ball?
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class SphereCont : NetworkBehaviour {
public Transform target;
public float speed;
private Rigidbody rb;
void Awake()
{ target = GameObject.FindGameObjectWithTag("Player");
}
void Start ()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate ()
{
if (!isLocalPlayer)
{
// exit from update if this is not the local player
return;
}
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
}
}
target = GameObject.FindGameObjectWithTag("Player").transform;
Each GameObject has a Transform attached to it, you should really consider reading a bit:
http://docs.unity3d.com/ScriptReference/Transform.html
edit: to clarify, you will not be converting anything into a Transform or GameObject.
Your answer
Follow this Question
Related Questions
Object cordinates changing when game start 1 Answer
Null Reference Exception for target in a script on a newly instantiated object 0 Answers
How do I find a player for AI to target when spawning a player in? 0 Answers
How can i assign a GameObject to another but only have some of its components? 1 Answer
Is this possible?? (details below) [with pictures] 0 Answers