help with script

public abstract class FollowTarget : MonoBehaviour {

    [SerializeField] public Transform target;
    [SerializeField] private bool autoTargetPlayer = true;

    // Use this for initialization
    virtual protected void Start () {
        if (autoTargetPlayer) {
            FindTargetPlayer();
        }
    }
   
    // Update is called once per frame
    void FixedUpdate () {
        if(autoTargetPlayer && (target == null || !target.gameObject.activeSelf) {
            FindTargetPlayer();
        }
        if(target != null && (target == null || !target.GameObject.activateSelf)) {
            Follow(Time.deltaTime);
        }
    }

        protected abstract void Follow(float deltaTime);

    public void FindTargetPlayer() {
        if (target == null) {
            GameObject targetObj = GameObject.FindGameObjectsWithTag("Player");

            if(targetObj) {
                SetTarget(targetObj.transform);
            }
        }
    }

    public virtual void SetTarget(Transform newTransform) {
        target = newTransform;
    }

    public Transform Target{get {return this.target;}}

}

i am getting a Parser Error at the fixedUpdate section where i have commented out.

if(target != null && (target == null || !target.GameObject.activateSelf)) {
Follow(Time.deltaTime);
}

the error is: Unexpected symbol ‘if’ in class, struct, or interface member declaration. how do i fix this.
and i thank you all prehand.

Line 15 you’re missing a closing parenthesis ‘)’ change to:

if(autoTargetPlayer &&([target](http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=target)==null||![target](http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=target).gameObject.activeSelf)**)**{

lol oh man. sorry for wasting your time. i was extremely high making this.

1 Like

#facepalm

1 Like

Ha, no issue at all… This happens, especially when high.

sorry i have another issue:

using UnityEngine;
using UnityEditor;

public class FreeCameraLook : Pivot
{

    [SerializeField] private float moveSpeed = 5f;
    [SerializeField] private float turnSpeed = 1.5f;
    [SerializeField] private float turnsmoothing = .1f;
    [SerializeField] private float tiltMax = 75f;
    [SerializeField] private float tiltMin = 45f;
    [SerializeField] private bool lockCursor = false;

    private float lookAngle;
    private float tiltAngle;

    private const float lookDistance = 100f;

    private float smoothX = 0;
    private float smoothY = 0;
    private float smoothXvelocity = 0;
    private float smoothYvelocity = 0;


    protected override void Awake() {
        base.Awake ();

        Screen.lockCursor = lockCursor;

        cam = GetComponentInChildren<Camera> ().transform;

        pivot = cam.parent;

    }
   
    // Update is called once per frame
    protected override void Update()
    {
        base.Update();

        HandleRotationMovement ();

        if(lockCursor && Input.GetMouseButtonUp(0)) {
            Screen.lockCursor = lockCursor;

        }
    }

    void OnDisable() {
        Screen.lockCursor = false;
    }

    protected override void Follow(float deltaTime) {
        Transform.position = Vector3.Lerp (Transform.position, target.position, deltaTime * moveSpeed);
    }

    void HandleRotationMovement() {
        float x = Input.GetAxis ("Mouse x");
        float y = Input.GetAxis ("Mouse Y");

        if (turnsmoothing > 0) {
            smoothX = Mathf.SmoothDamp (smoothX, x, ref smoothXvelocity, turnsmoothing);
            smoothY = Mathf.SmoothDamp (smoothY, y, ref smoothYvelocity, turnsmoothing);
        } else {
            smoothX = x;
            smoothY = y;
        }
        lookAngle += smoothX * turnSpeed;

        Transform.rotation = Quaternion.Euler (0f, lookAngle, 0);

        tiltAngle -= smoothY * turnSpeed;
        tiltAngle = Mathf.Clamp (tiltAngle, - tiltMin, tiltMax);

        pivot.localRotation = Quaternion.Euler (tiltAngle, 0, 0);
    }
}

The problem is with the "protected override void update.
i keep being told there is no suitable method to override

Does Pivot have an Update method? Does Pivot.cs inherit from Monobehaviour?

no pivot inherits from followtarget.cs

You have to derive from Monobehaviour to use the Update() method. Somewhere in the inheritance hierarchy you must inherit from Monobehaviour.

yes the followtarget.cs is monobehaviour, i am looking into it at the moment but havent found any solutions yet

and yes pivot does have a update function in there which is not override

Is it virtual?

using UnityEngine;
using System.Collections;

public class Pivot : FollowTarget
{

    protected Transform cam;
    protected Transform pivot;
    protected Vector3 lastTargetPosition;

    protected virtual void Awake() {
        cam = GetComponentInChildren<Camera>().transform;
        pivot = cam.parent;
    }

    // Use this for initialization
    protected override void Start ()
    {   
        base.Start();
   
    }
   
    // Update is called once per frame
    void Update()
    {
        if (!Application.isPlaying) {

            if (target != null) {
                Follow (999);
                lastTargetPosition = AvatarTarget.position;
            }
            if(Mathf.Abs(Camera.localPosition.x) > .5f || Mathf.Abs(cam.localPosition.y) > .5f) {
                cam.localPosition = Vector3.Scale (cam.localPosition, Vector3.forward);
            }

            cam.localPosition = Vector3.Scale (cam.localPosition, Vector3.forward);
        }
    }


    protected override void Follow(float deltaTime){

    }

}

this is the pivote coding.

no it is not

Could be that your pivot.cs update isn’t virtual so you can’t override it. I’m pretty sure only virtual methods can be over ridden

i just made it a virtual and i get the error, virtual or abstract members cannot be private

Right, they can’t. You’ll also have to make it public.

lol now i get the error:
cannot change access modifiers when overring public inherited member.

Maybe this will enlighten you a bit. This shows how to override a start method from a monobehaviour. Inheritance hides Start() - Questions & Answers - Unity Discussions

Your void Update will have to be a public void update in the FollowTarget.cs script. You can’t change the access back and forth from public to private.