|
楼主 |
发表于 2013-4-5 16:33
|
显示全部楼层
不知道怎么的,中午代码还正常运行,现在竟然那个什么“没有上下文的错”,Assets/scripts/FishToLeftController.cs(40,38): error CS0103: The name `originPosition' does not exist in the current context 下面是源代码:
using UnityEngine;
using System.Collections;
public class FishToLeftController : MonoBehaviour {
public Transform playerTransform;//小鱼的位置
private int times=0;//记录击打RedFish的次数
private Vector3 originPosition;//获得RedFish的初始值位置
private bool isFromRedFish=true;//判断来自RedFish的方向
// Use this for initialization
void Start () {
Vector3 originPosition=transform.position;
}
// Update is called once per frame
void Update () {
float angle=Mathf.Atan((playerTransform.position.y-transform.position.y)/(playerTransform.position.x-transform.position.x));
Vector3 myVector31=new Vector3(-0.8f*Time.deltaTime,-0.8f*Mathf.Abs(Mathf.Tan(angle))*Time.deltaTime,0.0f);//RedFish在第一象限
Vector3 myVector34= new Vector3(-0.8f*Time.deltaTime,0.8f*Mathf.Abs(Mathf.Tan(angle))*Time.deltaTime,0.0f);//RedFish在第四象限
//Debug.Log("angle "+angle+"myVector3 "+myVector31+"ATan "+Mathf.Atan(45f)+"Tan "+Mathf.Tan(45f)+"Mathf.Deg2Rad "+Mathf.Deg2Rad*180f+"Mathf.Atan2 "+Mathf.Atan2(1,1)+"Mathf.Rad2Deg "+Mathf.Rad2Deg*3.1415926f);
myVector31.Normalize();
if(transform.position.y>playerTransform.position.y)
{
transform.Translate(0.01f*myVector31);
//Debug.Log("if myVector32 "+myVector31+"playerTransform.position"+playerTransform.position);
}
myVector34.Normalize();
if(transform.position.y<playerTransform.position.y)
{
transform.Translate(0.01f*myVector34);
}
if(transform.position.x<=-3.0f)
{
transform.position=originPosition;
Debug.Log("chaogu-3.5");
}
}
void OnTriggerEnter(Collider other)
{
times++;
if(times>=2)
{
Debug.Log("times "+times);
transform.position=originPosition;//这里没有销毁RedFish 只是把它的位置初始化
times=0;
}
if(other.transform.tag=="projectile")
{
Destroy(other.gameObject);
}
}
}
|
|