error CS1525: Unexpected symbol `(', expecting `,', `;', or `='
I'm getting this error error CS1525: Unexpected symbol (', expecting
,', ;', or
=' and error CS1525: Unexpected symbol `}'
here's the script
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class enemyTurretRotations : MonoBehaviour {
public float rotateSpeed = 0.6f;
public GameObject T90parent;
public enemyAttacks enemyAttacksScript;
public GameObject m_target = null;
public float speed = 0.6f;
Vector3 m_lastKnownPosition = Vector3.zero;
Quaternion m_lookAtRotation;
// Use this for initialization
void Start()
{
T90parent = gameObject.transform.root.gameObject;
enemyAttacksScript = T90parent.GetComponentInChildren<enemyAttacks>();
}
// Update is called once per frame
void Update()
{
if (m_target)
{
if (m_lastKnownPosition != m_target.transform.position)
{
m_lastKnownPosition = m_target.transform.position;
m_lookAtRotation = Quaternion.LookRotation(m_lastKnownPosition - tranform.position);
}
}
if (transform.rotation != m_lookAtRotation)
{
transform.rotation = Quaternion.RotateTowards(transform.rotation, m_lookAtRotation, speed * Time.deltaTime);
}
if (enemyAttacksScript.attack)
{
bool SetTarget(GameObject target)
{
if (!target)
{
return false;
}
m_target = target;
return true;
}
}
}
}
what have I done wrong?
Answer by nathanlink169 · May 28, 2017 at 11:53 AM
It looks like you're trying to create a function inside of another function. I assume that inside of your statement if(enemyAttacksScript.attack) - you're trying to call the function SetTarget. The issue is that you need to create SetTarget outside of the Update function. Take a look at this code:
public float rotateSpeed = 0.6f;
public GameObject T90parent;
public enemyAttacks enemyAttacksScript;
public GameObject m_target = null;
public float speed = 0.6f;
Vector3 m_lastKnownPosition = Vector3.zero;
Quaternion m_lookAtRotation;
// Use this for initialization
void Start()
{
T90parent = gameObject.transform.root.gameObject;
enemyAttacksScript = T90parent.GetComponentInChildren<enemyAttacks>();
}
// Update is called once per frame
void Update()
{
if (m_target)
{
if (m_lastKnownPosition != m_target.transform.position)
{
m_lastKnownPosition = m_target.transform.position;
m_lookAtRotation = Quaternion.LookRotation(m_lastKnownPosition - tranform.position);
}
}
if (transform.rotation != m_lookAtRotation)
{
transform.rotation = Quaternion.RotateTowards(transform.rotation, m_lookAtRotation, speed * Time.deltaTime);
}
if (enemyAttacksScript.attack)
{
SetTarget(YOUR_NEW_TARGET_HERE);
}
}
bool SetTarget(GameObject target)
{
if (!target)
{
return false;
}
m_target = target;
return true;
}
Your answer
Follow this Question
Related Questions
Menu object not responding 0 Answers
[Question] Unity C# Set a Player Class and refence issue 0 Answers
How to assign GameObject to Script? 1 Answer
Help with [SerializeField] in a script! 1 Answer
Flashlight flickering script? 0 Answers