unity3d 相机跟随代码怎么写
2016-06-22
展开全部
需要先声明一个public的GameObject对象:publicGameObjectprefab1;然后在你想要创建物体的地方写Instantiate方法:Instantiate(prefab1,位置,角度)//这个方法的返回类型是一个gameobject对象,如果需要也可以用一个gameobject对象来引用创建的物体,比如你写的GameObjectgo=Instantiate(prefab),就是用go来引用创建的物体。之后把这段脚本保存为.cs文件绑定给一个对象,比如绑定到摄像机上,然后选中摄像机,会在Inspector面板看到你绑定的脚本组件,在那里能找到一个prefab1字段,因为这个字段是public的,然后把你创建的y1预设拖动到prefab1上,也就是把y1预设引用给prefab1这个gameobject对象,然后运行就能看到效果了。
展开全部
正上方跟随:
using UnityEngine;
using System.Collections;
public void Following:MonoBehaviour
{
public float Ox;//偏差值
public float smooth=1;//缓动系数,默认为1,如有需要请在引擎中调试
public Transform ObjectPosition;//物体的位置
public Transform TargetPosition;//相机的移动目标位置
void Awake()
{
follow = GameObject.FindWithTag ("Object").transform;
}
void Update()
{
TargetPosition=ObjectPosition.position+Vector3.up*Ox;//Ox具体是什么值在引擎里面调试
transform.position=vector3(transform.position,TargetPosition,Time.deltaTime*smooth);
transform.LookAt(ObjectPosition);
}
}
前上方跟随:
using UnityEngine;
using System.Collections;
public void Following:MonoBehaviour
{
public float Ox;//偏差值
public float smooth=1;//缓动系数,默认为1,如有需要请在引擎中调试
public Transform ObjectPosition;//物体的位置
public Transform TargetPosition;//相机的移动目标位置
void Awake()
{
follow = GameObject.FindWithTag ("Object").transform;
}
void Update()
{
TargetPosition=(ObjectPosition.position+Vector3.up*Ox)+(ObjectPosition.position+vector3.forward*Ox);//Ox具体是什么值在引擎里面调试
transform.position=vector3(transform.position,TargetPosition,Time.deltaTime*smooth);
transform.LookAt(ObjectPosition);
}
}
后上方跟随:
using UnityEngine;
using System.Collections;
public void Following:MonoBehaviour
{
public float Ox;//偏差值
public float smooth=1;//缓动系数,默认为1,如有需要请在引擎中调试
public Transform ObjectPosition;//物体的位置
public Transform TargetPosition;//相机的移动目标位置
void Awake()
{
follow = GameObject.FindWithTag ("Object").transform;
}
void Update()
{
TargetPosition=(ObjectPosition.position+Vector3.up*Ox)+(ObjectPosition.position-vector3.forward*Ox);//Ox具体是什么值在引擎里面调试
transform.position=vector3(transform.position,TargetPosition,Time.deltaTime*smooth);
transform.LookAt(ObjectPosition);
}
}
正前方跟随:
using UnityEngine;
using System.Collections;
public void Following:MonoBehaviour
{
public float Ox;//偏差值
public float smooth=1;//缓动系数,默认为1,如有需要请在引擎中调试
public Transform ObjectPosition;//物体的位置
public Transform TargetPosition;//相机的移动目标位置
void Awake()
{
follow = GameObject.FindWithTag ("Object").transform;
}
void Update()
{
TargetPosition=ObjectPosition.position+vector3.forward*Ox;//Ox具体是什么值在引擎里面调试
transform.position=vector3(transform.position,TargetPosition,Time.deltaTime*smooth);
transform.LookAt(ObjectPosition);
}
}
正后方跟随
using UnityEngine;
using System.Collections;
public void Following:MonoBehaviour
{
public float Ox;//偏差值
public float smooth=1;//缓动系数,默认为1,如有需要请在引擎中调试
public Transform ObjectPosition;//物体的位置
public Transform TargetPosition;//相机的移动目标位置
void Awake()
{
follow = GameObject.FindWithTag ("Object").transform;
}
void Update()
{
TargetPosition=ObjectPosition.position-vector3.forward*Ox;//Ox具体是什么值在引擎里面调试
transform.position=vector3(transform.position,TargetPosition,Time.deltaTime*smooth);
transform.LookAt(ObjectPosition);
}
}
正右方跟随:
using UnityEngine;
using System.Collections;
public void Following:MonoBehaviour
{
public float Ox;//偏差值
public float smooth=1;//缓动系数,默认为1,如有需要请在引擎中调试
public Transform ObjectPosition;//物体的位置
public Transform TargetPosition;//相机的移动目标位置
Vecrtor3 R=new Vecrtor3 (1,0,0);//摄像机在物体右面的偏移位置
void Awake()
{
follow = GameObject.FindWithTag ("Object").transform;
}
void Update()
{
TargetPosition=ObjectPosition.position+R*Ox;//Ox具体是什么值在引擎里面调试
transform.position=vector3(transform.position,TargetPosition,Time.deltaTime*smooth);
transform.LookAt(ObjectPosition);
}
}
正左方跟随:
using UnityEngine;
using System.Collections;
public void Following:MonoBehaviour
{
public float Ox;//偏差值
public float smooth=1;//缓动系数,默认为1,如有需要请在引擎中调试
public Transform ObjectPosition;//物体的位置
public Transform TargetPosition;//相机的移动目标位置
Vecrtor3 L=new Vecrtor3 (-1,0,0);//摄像机在物体左面的偏移位置
void Awake()
{
follow = GameObject.FindWithTag ("Object").transform;
}
void Update()
{
TargetPosition=ObjectPosition.position+L*Ox;//Ox具体是什么值在引擎里面调试
transform.position=vector3(transform.position,TargetPosition,Time.deltaTime*smooth);
transform.LookAt(ObjectPosition);
}
}
using UnityEngine;
using System.Collections;
public void Following:MonoBehaviour
{
public float Ox;//偏差值
public float smooth=1;//缓动系数,默认为1,如有需要请在引擎中调试
public Transform ObjectPosition;//物体的位置
public Transform TargetPosition;//相机的移动目标位置
void Awake()
{
follow = GameObject.FindWithTag ("Object").transform;
}
void Update()
{
TargetPosition=ObjectPosition.position+Vector3.up*Ox;//Ox具体是什么值在引擎里面调试
transform.position=vector3(transform.position,TargetPosition,Time.deltaTime*smooth);
transform.LookAt(ObjectPosition);
}
}
前上方跟随:
using UnityEngine;
using System.Collections;
public void Following:MonoBehaviour
{
public float Ox;//偏差值
public float smooth=1;//缓动系数,默认为1,如有需要请在引擎中调试
public Transform ObjectPosition;//物体的位置
public Transform TargetPosition;//相机的移动目标位置
void Awake()
{
follow = GameObject.FindWithTag ("Object").transform;
}
void Update()
{
TargetPosition=(ObjectPosition.position+Vector3.up*Ox)+(ObjectPosition.position+vector3.forward*Ox);//Ox具体是什么值在引擎里面调试
transform.position=vector3(transform.position,TargetPosition,Time.deltaTime*smooth);
transform.LookAt(ObjectPosition);
}
}
后上方跟随:
using UnityEngine;
using System.Collections;
public void Following:MonoBehaviour
{
public float Ox;//偏差值
public float smooth=1;//缓动系数,默认为1,如有需要请在引擎中调试
public Transform ObjectPosition;//物体的位置
public Transform TargetPosition;//相机的移动目标位置
void Awake()
{
follow = GameObject.FindWithTag ("Object").transform;
}
void Update()
{
TargetPosition=(ObjectPosition.position+Vector3.up*Ox)+(ObjectPosition.position-vector3.forward*Ox);//Ox具体是什么值在引擎里面调试
transform.position=vector3(transform.position,TargetPosition,Time.deltaTime*smooth);
transform.LookAt(ObjectPosition);
}
}
正前方跟随:
using UnityEngine;
using System.Collections;
public void Following:MonoBehaviour
{
public float Ox;//偏差值
public float smooth=1;//缓动系数,默认为1,如有需要请在引擎中调试
public Transform ObjectPosition;//物体的位置
public Transform TargetPosition;//相机的移动目标位置
void Awake()
{
follow = GameObject.FindWithTag ("Object").transform;
}
void Update()
{
TargetPosition=ObjectPosition.position+vector3.forward*Ox;//Ox具体是什么值在引擎里面调试
transform.position=vector3(transform.position,TargetPosition,Time.deltaTime*smooth);
transform.LookAt(ObjectPosition);
}
}
正后方跟随
using UnityEngine;
using System.Collections;
public void Following:MonoBehaviour
{
public float Ox;//偏差值
public float smooth=1;//缓动系数,默认为1,如有需要请在引擎中调试
public Transform ObjectPosition;//物体的位置
public Transform TargetPosition;//相机的移动目标位置
void Awake()
{
follow = GameObject.FindWithTag ("Object").transform;
}
void Update()
{
TargetPosition=ObjectPosition.position-vector3.forward*Ox;//Ox具体是什么值在引擎里面调试
transform.position=vector3(transform.position,TargetPosition,Time.deltaTime*smooth);
transform.LookAt(ObjectPosition);
}
}
正右方跟随:
using UnityEngine;
using System.Collections;
public void Following:MonoBehaviour
{
public float Ox;//偏差值
public float smooth=1;//缓动系数,默认为1,如有需要请在引擎中调试
public Transform ObjectPosition;//物体的位置
public Transform TargetPosition;//相机的移动目标位置
Vecrtor3 R=new Vecrtor3 (1,0,0);//摄像机在物体右面的偏移位置
void Awake()
{
follow = GameObject.FindWithTag ("Object").transform;
}
void Update()
{
TargetPosition=ObjectPosition.position+R*Ox;//Ox具体是什么值在引擎里面调试
transform.position=vector3(transform.position,TargetPosition,Time.deltaTime*smooth);
transform.LookAt(ObjectPosition);
}
}
正左方跟随:
using UnityEngine;
using System.Collections;
public void Following:MonoBehaviour
{
public float Ox;//偏差值
public float smooth=1;//缓动系数,默认为1,如有需要请在引擎中调试
public Transform ObjectPosition;//物体的位置
public Transform TargetPosition;//相机的移动目标位置
Vecrtor3 L=new Vecrtor3 (-1,0,0);//摄像机在物体左面的偏移位置
void Awake()
{
follow = GameObject.FindWithTag ("Object").transform;
}
void Update()
{
TargetPosition=ObjectPosition.position+L*Ox;//Ox具体是什么值在引擎里面调试
transform.position=vector3(transform.position,TargetPosition,Time.deltaTime*smooth);
transform.LookAt(ObjectPosition);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询