I have a little problem with a lift script. Whenever I click play game, it come sup with the error “Assets/Lift_script.cs(6,25): error CS1525: Unexpected symbol :', expecting )‘, ,', ;’, [', or =”. Here is the Csharp script:
using UnityEngine;
using System.Collections;
public class Lift_script : MonoBehaviour {
void Update() {
var main:Player;
var playerTransform = Camera.main.transform;
transform.Translate(Vector3.forward * Time.deltaTime);
transform.Translate(Vector3.up * Time.deltaTime, Space.World);
}
}
Thanks for that, it cleared it up a bit, but a new error appears; It doesn’t seem to like the Player main;
Assets/Lift_test.cs(6,17): error CS0246: The type or namespace name `Player’ could not be found. Are you missing a using directive or an assembly reference?
The avatar is tagged as player, so I don’t see how this can be…
Thanks loads, JamesLeeNZ and ar0nax for your help. I got the lift going up when I click U, so that’s great. One small problem though; my avatar doesn’t go up with the lift[:P] I’ve spent loads of time trying to figure this out, and I’ve come to the conclusion that I’d need to parent my avatar to the lift when he’s on it, and de-parent him when he’s off. With my limited knowledge of Csharp scripting (and when I say limited, I mean it[:P]), things where bound to go wrong. As soon as I run the game, the camera and lift start moving upwards, while my character stays on the ground. This happens even when I don’t press u. Here’s the code…
using UnityEngine;
using System.Collections;
public class Lift_test : MonoBehaviour {
void Update() {
Transform player;
Transform playerTransform = Camera.main.transform;
if (Input.GetKey (“u”))
playerTransform.parent = transform;
transform.Translate (Vector3.forward * Time.deltaTime);
if (Input.GetKeyUp(“u”))
transform.parent = null;
}
}
can anyone tell me what I’m doing wrong this time?[:P]
Start using the [ code ] [ / code] tags (no spaces). Makes reading your code easier
The reason its failing is because you are not using braces with your if statement
public class Lift_test : MonoBehaviour {
void Update() {
Transform player;
Transform playerTransform = Camera.main.transform;
if (Input.GetKey ("u"))
{
playerTransform.parent = transform;
transform.Translate (Vector3.forward * Time.deltaTime);
}
if (Input.GetKeyUp("u"))
transform.parent = null;
}
}
I would recommend doing a tutorial as well. I always recommend the lerpz tutorial. Will give you a pretty good foundation. You can find it in the asset store
Thanks loads, tomorrow I’m going to get this sorted. And yes, I did try a tutorial, and ended up with Lerpz waling around in zero gravity and jumping twice his height in a discoloured world[:P] strange…[:P] Anyway, I might try it again now I have the newer version.
Thanks again for everything
Yup, things just keep going wrong with me[:P] Anyway, the problem now is that my character stays at the bottom of the lift and it passes through him, though the camera moves alright. The camera isn’t faultless though, as once it’s attached to the lift, it stays that way and doesn’t detach. I tried playing around with the code and using some info from the Stealth tutorial. Here what I came up with;
using UnityEngine;
using System.Collections;
public class Lift_test : MonoBehaviour{
private GameObject scout_robot
void Update() {
Transform scout_robot;
if (Input.GetKey ("u"))
{
scout_robot.transform.parent = transform;
transform.Translate (Vector3.forward * Time.deltaTime);
}
if (Input.GetKeyUp("u"))
transform.parent = null;
}
}