U3D FistWeek Summary

1、Project Tank

***Bullet Flying Script

/*
void Start ()
    {
        transform.Rotate(Vector3.forward, 90);
        transform.forward = GameObject.Find("Target").transform.position - transform.position;

    }

    float timer = 0;
    // Update is called once per frame
    void Update ()
    {
        timer+= Time.deltaTime;
        //让子弹发生变换
        transform.position += transform.forward * 10 * Time.deltaTime;

        //transform.position += (GameObject.Find("Target").transform.position - transform.position) * 0.05f;

        if ((transform.position - GameObject.Find("Target").transform.position).magnitude < 0.1)
        {
            Destroy(gameObject);
        }
    }

*/


***Bullet Creater Script

/*

public GameObject bullet;

    // Use this for initialization
    void Start ()
    {

    }
    // Update is called once per frame
    float timer;
    void Update ()
    {
        timer += Time.deltaTime;
        if (timer >= 1)
        {
            timer = 0;
            Instantiate(bullet, transform.position, Quaternion.identity);
        }
    }

*/


***Make Gun Lookat The Target

/*
    void Start ()
    {
        transform.Rotate(Vector3.back);
    }
    
    
    void Update ()
    {
        Quaternion qua = Quaternion.LookRotation(GameObject.Find("Cube").transform.position - transform.position);
        transform.rotation = qua;
    }

*/


***WASD Control Move of Tank

/*

void TankMove()
    {
        float hA=Input.GetAxis("Horizontal");
        float vA = Input.GetAxis("Vertical");

        if (vA >= 0)
        {
            transform.Rotate(Vector3.left * hA * 30 * Time.deltaTime);
        }
        else
        {
            transform.Rotate(Vector3.right * hA * 30 * Time.deltaTime);
        }
        transform.Translate(Vector3.forward * vA * 0.5f);
    }

*/


***Using Lerp

//通过VECTOR线性差值移动物体
        //transform.position = Vector3.Lerp(transform.position, GameObject.Find("Sphere").transform.position, 0.5f * Time.deltaTime);
        //if (Vector3.Distance(transform.position, GameObject.Find("Sphere").transform.position) < 0.01f)
        //{
        //    transform.position = GameObject.Find("Sphere").transform.position;
        //}


***Move Cube with Mouse Drag

/*

    void OnMouseEnter()
    {
        Debug.Log("in!");
    }

    Vector3 offset;

    void OnMouseDown()
    {
        //开始拖拽
        Debug.Log("down!");


        Vector3 mousev = Input.mousePosition;
        //将鼠标坐标转换为世界坐标
        Vector3 screenSpace = Camera.main.WorldToScreenPoint(transform.position);
        Vector3 mouseWorld = Camera.main.ScreenToWorldPoint(new Vector3(mousev.x, mousev.y,screenSpace.z));
        offset = transform.position - mouseWorld;
    }


    void OnMouseDrag()
    {
        //鼠标拖拽时调用
        Debug.Log("drag!");

        //mx = Input.GetAxis("Mouse X");
        //my = Input.GetAxis("Mouse Y");
        //transform.position += Vector3.right * mx;
        //transform.position += Vector3.up * my;

        Vector3 mousev = Input.mousePosition;
        //将鼠标坐标转换为世界坐标
        Vector3 screenSpace = Camera.main.WorldToScreenPoint(transform.position);
        Vector3 mouseWorld = Camera.main.ScreenToWorldPoint(new Vector3(mousev.x, mousev.y, screenSpace.z));

        transform.position = mouseWorld + offset;

    }

*/


***Mouse DoubleClicks

/*

 float timer;
    bool intodouble1 = false;
    bool intodouble2 = false;
    float time1;

    void Start ()
    {
    
    }

    void Update ()
    {
        timer += Time.deltaTime;
        if (Input.GetMouseButtonDown(0))
        {
            intodouble1 = true;
            if (intodouble1 && (intodouble2 == false))
            {
                time1 = timer;
                intodouble2 = true;
            }
            else
            {
                if (intodouble1 && intodouble2)
                {
                    if (timer - time1 < 0.6)
                    {
                        Debug.Log("DoubleClick");
                    }
                    intodouble1 = false;
                    intodouble2 = false;
                }
            }
        }
        if (timer - time1 > 0.6)
        {
            intodouble1 = false;
            intodouble2 = false;
        }

*/



***Camera Move

/// <summary>
    /// 摄像机移动方法(防止颠倒改良版)
    /// </summary>
    void CameraMove()
    {
        vA = Input.GetAxis("Vertical");
        hA = Input.GetAxis("Horizontal");
        mX = Input.GetAxis("Mouse X");
        mY = Input.GetAxis("Mouse Y");

        transform.position += transform.forward * vA * 0.5f;
        transform.position += transform.right * hA * 0.5f;
        transform.Rotate(Vector3.up, mX);
        transform.Rotate(Vector3.left, mY * 0.5f);

        Vector3 oldrotation = transform.rotation.eulerAngles;
        oldrotation.z = 0;
        transform.rotation = Quaternion.Euler(oldrotation);
        transform.position=new Vector3(transform.position.x, 1.5f, transform.position.z);
    }



The scene of Delegate in U3D04 is the strandrard mothd to use event and delegate.


Edit by Suxny

If Reproduced,,please indicate the source.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值